Skip to content

Comments

MAINT: Start applying ruff/Pycodestyle rules#26857

Merged
charris merged 12 commits intonumpy:mainfrom
DimitriPapadopoulos:24994
Aug 28, 2024
Merged

MAINT: Start applying ruff/Pycodestyle rules#26857
charris merged 12 commits intonumpy:mainfrom
DimitriPapadopoulos:24994

Conversation

@DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Jul 4, 2024

Start working on #24994.

I have left out most of distutils, *.pyi files, and some special cases that seem to require extra attention.

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the 24994 branch 4 times, most recently from 55c9ba4 to 82f20e1 Compare July 4, 2024 21:21
@DimitriPapadopoulos DimitriPapadopoulos changed the title Start applying ruff/Pycodestyle rules MAINT: start applying ruff/Pycodestyle rules Jul 4, 2024
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the 24994 branch 4 times, most recently from 7cecfd0 to da91eaf Compare July 4, 2024 21:51
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the 24994 branch 7 times, most recently from 91381ad to b669241 Compare July 6, 2024 12:23
@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review July 6, 2024 12:24
@DimitriPapadopoulos DimitriPapadopoulos changed the title MAINT: start applying ruff/Pycodestyle rules MAINT: start applying ruff/pycodestyle rules Jul 6, 2024
Copy link
Member

@rkern rkern left a comment

Choose a reason for hiding this comment

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

I haven't individually confirmed all of the import removals, but I did note the ones that had a comment explaining why they were there and should not be removed.

I think the other changes look good to my eyeballs.

assert(np.isnan(div)), "div: %s" % div
div = np.floor_divide(fnan, fzer)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
assert(np.isnan(div)), "div: %s" % div
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not remove the parentheses from the asserts?

Suggested change
assert(np.isnan(div)), "div: %s" % div
assert np.isnan(div), "div: %s" % div

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Aug 27, 2024

Choose a reason for hiding this comment

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

These commits contain automated fixes when possible. I try not to manually modify these fixes, unless really needed. There's a ruff/pyupgrade rule for extraneous parentheses (UP034), which I could apply in a different PR.

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

We usually do not like these kinds of code reformats, but this one is actually quite nice. I thing we shouldn't be touching the deprecated numpy.distutils, could you revert those?

@@ -1,3 +1,4 @@
import os
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, how did this work before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps resolve_includes() is usually not called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We usually do not like these kinds of code reformats, but this one is actually quite nice.

This is not really a "reformat", rather in support of migrating linting from Pycodestyle to ruff (#24994).

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Aug 27, 2024

Choose a reason for hiding this comment

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

I thing we shouldn't be touching the deprecated numpy.distutils, could you revert those?

Done.

Actually, numpy.distutils had already been touched. Should I revert prior linting changes?
https://github.com/numpy/numpy/commits/main/numpy/distutils

assert_isin_equal(empty_array, empty_array)

@pytest.mark.parametrize("kind", [None, "sort", "table"])
def test_isin(self, kind):
Copy link
Member

Choose a reason for hiding this comment

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

Rather than remove this, please rename the tests and keep them separate.

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Aug 27, 2024

Choose a reason for hiding this comment

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

We have two test functions with the same name and identical parameters:

@pytest.mark.parametrize("kind", [None, "sort", "table"])
def test_isin(self, kind):

@pytest.mark.parametrize("kind", [None, "sort", "table"])
def test_isin(self, kind):

I think it makes sense to merge, doesn't it?

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Aug 27, 2024

Choose a reason for hiding this comment

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

I renamed the second test_isin to test_isin_additional.

nsteps = None

source = scrub_source(source, nsteps, verbose=True)
source = scrubSource(source, nsteps, verbose=True)
Copy link
Member

Choose a reason for hiding this comment

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

Huh. How did this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this Python 2.7 script hasn't been used for a long time - probably not after f589305 in 2018.

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the 24994 branch 4 times, most recently from d9419f1 to 2d05f15 Compare August 27, 2024 14:24
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the 24994 branch 2 times, most recently from 21eaf4e to f30b9e8 Compare August 27, 2024 14:30
@DimitriPapadopoulos DimitriPapadopoulos changed the title MAINT: start applying ruff/pycodestyle rules MAINT: Start applying ruff/Pycodestyle rules Aug 27, 2024
@charris
Copy link
Member

charris commented Aug 27, 2024

Needs rebase.

DimitriPapadopoulos and others added 12 commits August 27, 2024 23:29
F401 imported but unused

I have left out *.pyi files. Still lots of occurrences to examine.

Co-authored-by: Robert Kern <[email protected]>
F541 f-string without any placeholders
F811 Redefinition of unused `...`

I have left out *.pyi files and some special cases.
F821 Undefined name

I have left out *.pyi files and some special cases.
E401 Multiple imports on one line
E701 Multiple statements on one line (colon)
E711 Comparison to `None` should be `cond is None`
E712 Avoid inequality comparisons to `True`; use `if not cond:` for false checks
E713 Test for membership should be `not in`
E714 Test for object identity should be `is not`
E722 Do not use bare `except`
@charris charris merged commit 221ea71 into numpy:main Aug 28, 2024
@charris
Copy link
Member

charris commented Aug 28, 2024

Thanks @DimitriPapadopoulos .

@DimitriPapadopoulos DimitriPapadopoulos deleted the 24994 branch August 29, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants