-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
MNT: Apply assorted ruff/Pylint Refactor rules (PLR) #28755
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
base: main
Are you sure you want to change the base?
Conversation
Class method defined without decorator
Cannot have defined parameters for properties
Useless `return` statement at end of function
Consider merging multiple comparisons. Use a `set` if the elements are hashable.
Use `elif` instead of `else` then `if`, to reduce indentation
Use a set literal when testing for membership
b85d6e2
to
567df2e
Compare
@@ -1426,7 +1426,7 @@ def normalize_axis_tuple(axis, ndim, argname=None, allow_duplicate=False): | |||
normalize_axis_index : normalizing a single scalar axis | |||
""" | |||
# Optimization to speed-up the most common cases. | |||
if type(axis) not in (tuple, list): | |||
if type(axis) not in {tuple, list}: |
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.
same story as above
if type(axis) not in {tuple, list}: | |
if not isinstance(axis, tuple | list): |
@@ -148,7 +148,7 @@ def _setfieldnames(self, names, titles): | |||
attribute """ | |||
|
|||
if names: | |||
if type(names) in [list, tuple]: | |||
if type(names) in {list, tuple}: |
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.
same story as above
if type(names) in {list, tuple}: | |
if isinstance(names, list | tuple): |
raise AttributeError("Cannot set '%s' attribute" % attr) | ||
fielddict = nt.void.__getattribute__(self, 'dtype').fields | ||
res = fielddict.get(attr, None) | ||
if res: | ||
return self.setfield(val, *res[:2]) | ||
elif getattr(self, attr, None): |
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.
some other ruff rule will complain about this later anyway, so might as well do
elif getattr(self, attr, None): | |
if getattr(self, attr, None): |
@@ -586,7 +586,7 @@ def expand_dims(a, axis): | |||
else: | |||
a = asanyarray(a) | |||
|
|||
if type(axis) not in (tuple, list): | |||
if type(axis) not in {tuple, list}: |
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.
if type(axis) not in {tuple, list}: | |
if not isinstance(axis, tuple | list): |
@@ -3929,7 +3929,7 @@ def test_quantile_identification_equation(self, weights, method, alpha): | |||
w = rng.integers(low=0, high=10, size=n) if weights else None | |||
x = np.quantile(y, alpha, method=method, weights=w) | |||
|
|||
if method in ("higher",): | |||
if method in {"higher",}: |
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.
if method in {"higher",}: | |
if method == "higher": |
@@ -62,7 +62,7 @@ def get_complex_dtype(dtype): | |||
|
|||
def get_rtol(dtype): | |||
# Choose a safe rtol | |||
if dtype in (single, csingle): | |||
if dtype in {single, csingle}: |
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 won't work; it relies on the special behavior of dtype.__eq__
member_name != "typing" and # 2024-12: type names don't match | ||
"numpy._core" not in member.__name__ and # outside _core | ||
member not in visited_modules # not visited yet | ||
inspect.ismodule(member) and "numpy" in member.__name__ and not member_name.startswith("_") and member_name not in {"tests", "typing"} and "numpy._core" not in member.__name__ and member not in visited_modules # not visited yet |
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.
no linebreaks?
lbnd = 0 if dt in {bool, np.bool} else np.iinfo(dt).min | ||
ubnd = 2 if dt in {bool, np.bool} else np.iinfo(dt).max + 1 |
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 isn't quite the same:
>>> np.True_.dtype in (np.bool,)
True
>>> np.True_.dtype in {np.bool}
False
oh sorry I didn't notice the draft status, so my review was a bit premature. |
Co-authored-by: Joren Hammudoglu <[email protected]>
Co-authored-by: Joren Hammudoglu <[email protected]>
needs a rebase |
No description provided.