-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
There was a problem hiding this 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')], []): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, assum()
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
6159138
to
05f160f
Compare
RUF017 Avoid quadratic list summation
I001 Import block is un-sorted or un-formatted
05f160f
to
0fe9a03
Compare
There was a problem hiding this 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>
dbba8ae
to
8e10c2c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
No description provided.