Skip to content

Apply ruff rules (RUF) #574

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

Merged
merged 4 commits into from
Oct 4, 2024
Merged

Apply ruff rules (RUF) #574

merged 4 commits into from
Oct 4, 2024

Conversation

DimitriPapadopoulos
Copy link
Contributor

No description provided.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Needs rebase or rerun. I disagree with reduce(iadd, ..., []) instead of sum(..., [])

@@ -190,7 +192,7 @@ def test_ec():
assert_almost_equal(f(box1), 1)
# While we're here, test we can use different dtypes, and that values
# other than 0 or 1 raise an error.
for dtt in sum([np.sctypes[t] for t in ('int', 'uint', 'float')], []):
for dtt in functools.reduce(operator.iadd, [np.sctypes[t] for t in ('int', 'uint', 'float')], []):
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely not more readable. I'd be okay to switching to chain.from_iterable from itertools, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, quadratic-list-summation (RUF017) is not about readability:

The use of sum() to flatten lists of lists is quadratic in the number of lists, as sum() creates a new list for each element in the summation.

Instead, consider using another method of flattening lists to avoid quadratic complexity. The following methods are all linear in the number of lists:

  • functools.reduce(operator.iadd, lists, [])
  • list(itertools.chain.from_iterable(lists))
  • [item for sublist in lists for item in sublist]

But then that's hardly an issue for these small lists.

RUF010  Use explicit conversion flag
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the RUF branch 2 times, most recently from 6159138 to 05f160f Compare October 4, 2024 17:57
RUF017 Avoid quadratic list summation
I001 Import block is un-sorted or un-formatted
Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Small cleanups.

Co-authored-by: Chris Markiewicz <effigies@gmail.com>
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.61%. Comparing base (e03aae0) to head (8e10c2c).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #574   +/-   ##
=======================================
  Coverage   84.61%   84.61%           
=======================================
  Files         293      293           
  Lines       27479    27481    +2     
  Branches     3362     3363    +1     
=======================================
+ Hits        23252    23254    +2     
  Misses       3273     3273           
  Partials      954      954           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@effigies effigies merged commit 15a906e into nipy:main Oct 4, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants