Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pycodestyle] Allow dtype comparisons in type-comparison #9676

Merged
merged 1 commit into from Jan 29, 2024

Conversation

charliermarsh
Copy link
Member

Summary

Per #9570:

dtype are a bit of a strange beast, but definitely best thought of as instances, not classes, and they are meant to be comparable not just to their own class, but also to the corresponding scalar types (e.g., x.dtype == np.float32) and strings (e.g., x.dtype == ['i1,i4']; basically, __eq__ always tries to do dtype(other).

This PR thus allows comparisons to dtype in preview.

Closes #9570.

Test Plan

cargo test

@charliermarsh charliermarsh added the bug Something isn't working label Jan 29, 2024
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -180 violations, +0 -0 fixes in 5 projects; 38 projects unchanged)

RasaHQ/rasa (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

- tests/utils/tensorflow/test_rasa_layers.py:832:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

alteryx/featuretools (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

- featuretools/entityset/entityset.py:402:17: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

bokeh/bokeh (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview --select ALL

- examples/server/app/crossfilter/main.py:32:35: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

ibis-project/ibis (+0 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

- ibis/backends/bigquery/tests/system/test_client.py:222:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- ibis/backends/bigquery/tests/system/test_client.py:223:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

pandas-dev/pandas (+0 -175 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

- pandas/core/_numba/extensions.py:52:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/algorithms.py:533:13: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/algorithms.py:790:36: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/algorithms.py:940:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/algorithms.py:940:38: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/array_algos/putmask.py:138:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/array_algos/putmask.py:44:13: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/datetimelike.py:661:40: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/datetimelike.py:774:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/datetimelike.py:780:20: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/datetimes.py:2426:10: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/interval.py:257:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/masked.py:968:30: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/numeric.py:164:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/string_arrow.py:656:32: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/timedeltas.py:1040:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/arrays/timedeltas.py:647:20: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/computation/expressions.py:200:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/construction.py:551:39: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/construction.py:605:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/construction.py:652:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/astype.py:103:10: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/astype.py:131:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/cast.py:1036:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/cast.py:1065:21: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/cast.py:1091:21: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/cast.py:1179:45: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/cast.py:1700:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/dtypes.py:450:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/dtypes/missing.py:643:10: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/frame.py:11535:33: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/frame.py:2482:24: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/frame.py:8129:20: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/groupby/generic.py:1670:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/groupby/groupby.py:1977:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexers/utils.py:321:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:5558:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7013:56: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7031:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7051:17: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7054:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7054:37: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:7124:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/base.py:873:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/indexes/datetimelike.py:156:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/internals/concat.py:371:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/internals/managers.py:509:16: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
- pandas/core/nanops.py:1682:14: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
... 127 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
E721 180 0 180 0 0

@zanieb
Copy link
Member

zanieb commented Jan 29, 2024

Ecosystem looks good

@charliermarsh charliermarsh merged commit a6f7100 into main Jan 29, 2024
17 checks passed
@charliermarsh charliermarsh deleted the charlie/np branch January 29, 2024 17:39
zanieb pushed a commit that referenced this pull request Jan 29, 2024
## Summary

Per #9570:

> `dtype` are a bit of a strange beast, but definitely best thought of
as instances, not classes, and they are meant to be comparable not just
to their own class, but also to the corresponding scalar types (e.g.,
`x.dtype == np.float32`) and strings (e.g., `x.dtype == ['i1,i4']`;
basically, `__eq__` always tries to do `dtype(other)`.

This PR thus allows comparisons to `dtype` in preview.

Closes #9570.

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Behaviour of E721 with numpy.dtype
2 participants