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

[pylint] Implement nan-comparison (PLW0117) #10401

Merged
merged 6 commits into from
Mar 21, 2024

Conversation

augustelalande
Copy link
Contributor

Summary

Implement pylint's nan-comparison, part of #970.

Test Plan

Text fixture was added.

Copy link
Contributor

github-actions bot commented Mar 14, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+48 -0 violations, +0 -0 fixes in 1 projects; 42 projects unchanged)

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

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ pandas/core/arrays/arrow/array.py:1409:29: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/arrays/categorical.py:1597:82: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/arrays/string_arrow.py:710:20: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/base.py:641:34: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/internals/managers.py:1000:48: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/strings/accessor.py:347:63: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/core/strings/object_array.py:102:28: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arithmetic/test_object.py:71:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arithmetic/test_object.py:75:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arrays/categorical/test_analytics.py:107:30: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arrays/categorical/test_analytics.py:117:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arrays/categorical/test_indexing.py:292:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arrays/categorical/test_indexing.py:301:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/arrays/floating/test_contains.py:12:12: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/frame/methods/test_astype.py:762:28: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/frame/methods/test_replace.py:1541:21: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/groupby/test_categorical.py:1496:20: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/categorical/test_indexing.py:345:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/categorical/test_indexing.py:353:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/categorical/test_indexing.py:366:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/categorical/test_indexing.py:376:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/categorical/test_indexing.py:386:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/multi/test_indexing.py:822:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/multi/test_indexing.py:825:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/numeric/test_indexing.py:533:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/period/test_indexing.py:784:16: PLW0117 Comparing against a NaN value; use `math.isnan` instead
+ pandas/tests/indexes/period/test_indexing.py:785:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/indexes/period/test_indexing.py:790:16: PLW0117 Comparing against a NaN value; use `math.isnan` instead
+ pandas/tests/indexes/period/test_indexing.py:791:16: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/io/excel/test_writers.py:1021:38: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/io/excel/test_writers.py:1072:50: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:150:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:151:27: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:152:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:153:27: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:154:27: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:155:23: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:157:29: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:158:30: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:159:29: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:160:30: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:161:30: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/libs/test_libalgos.py:162:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/reductions/test_reductions.py:1362:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/reductions/test_reductions.py:1375:30: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/series/indexing/test_setitem.py:1106:52: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/series/indexing/test_setitem.py:619:23: PLW0117 Comparing against a NaN value; use `np.isnan` instead
+ pandas/tests/series/test_constructors.py:1095:26: PLW0117 Comparing against a NaN value; use `np.isnan` instead

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLW0117 48 48 0 0 0

@augustelalande
Copy link
Contributor Author

augustelalande commented Mar 14, 2024

All the violations in pandas are false positives and are mostly checking for the actual np.nan object i.e. na_value is np.nan, but these seem more like exceptions to the rule, not reasons to change it. np.nan is np.nan will return True, but it's a bad idea to check for a nan value by checking x is np.nan.

Interested to hear people's thoughts.

}
}

fn is_nan_float(expr: &Expr) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also interested to hear if there is a better way to do this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tweaked it a little bit but it's generally correct. Kind of tedious to write out, but correct!

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Mar 21, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) March 21, 2024 00:20
@augustelalande augustelalande disabled auto-merge March 21, 2024 00:25
@augustelalande
Copy link
Contributor Author

Sorry had to fix the typo

@charliermarsh charliermarsh enabled auto-merge (squash) March 21, 2024 00:31
@charliermarsh charliermarsh merged commit 685de91 into astral-sh:main Mar 21, 2024
17 checks passed
@augustelalande augustelalande deleted the nan-comparison branch March 21, 2024 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants