-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Repo review bugbear #9505
Repo review bugbear #9505
Conversation
767a935
to
5116a3d
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.
Looking at about 1/3 of lines, it looks good — I did spot one potential issue with the chunk defaults; worth confirming all of those are correct
xarray/core/variable.py
Outdated
@@ -2528,7 +2532,7 @@ def _to_dense(self) -> Variable: | |||
|
|||
def chunk( # type: ignore[override] | |||
self, | |||
chunks: T_Chunks = {}, | |||
chunks: T_Chunks = 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.
IIRC these are intended to be different between {}
and None
(and the coercion below then doesn't let None
through...)
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.
...though the tests pass, so maybe it's fine (either that or our tests aren't sufficient...)
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.
Yes, there was a couple of instances where a comment was explaining something like this, so I left these ones alone.
Line 2660 in 1c6300c
chunks: T_ChunksFreq = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667) |
xarray/xarray/core/dataarray.py
Line 1363 in 1c6300c
chunks: T_ChunksFreq = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667) |
In the absence of such comment (like here) I replaced the default with None
, but I could also revert these places and add a comment if it was missing.
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.
Yes that would be great.
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.
@dcherian to confirm, you would like this:
I could also revert these places and add a comment if it was missing.
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.
^ yes.
@@ -330,11 +330,13 @@ def test_parents(self): | |||
def test_lineage(self): | |||
_, leaf_f = create_test_tree() | |||
expected = ["f", "e", "b", "a"] | |||
assert [node.name for node in leaf_f.lineage] == expected | |||
with pytest.warns(DeprecationWarning): | |||
assert [node.name for node in leaf_f.lineage] == expected |
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.
Nice!
@@ -72,7 +73,9 @@ def backends_dict_from_pkg( | |||
backend = entrypoint.load() | |||
backend_entrypoints[name] = backend | |||
except Exception as ex: | |||
warnings.warn(f"Engine {name!r} loading failed:\n{ex}", RuntimeWarning) | |||
warnings.warn( |
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.
It would be better to replace all of these with utils.emit_user_level_warning
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.
(I also think it's fine to do this in another PR, though defer to @dcherian)
We could also add a regex lint in pre-commit that we don't use warnings.warn
, we only use utils.emit_level_warning
. Here's an example of this from another repo: https://github.com/PRQL/prql/blob/main/.pre-commit-config.yaml#L64-L71
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.
I also think it's fine to do this in another PR,
yes fine by me!
xarray/testing/strategies.py
Outdated
@@ -137,7 +139,7 @@ def dimension_names( | |||
|
|||
def dimension_sizes( | |||
*, | |||
dim_names: st.SearchStrategy[Hashable] = names(), | |||
dim_names: st.SearchStrategy[Hashable] | None = 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.
this is unnecessary IIUC, the strategies are immutable.
* B006: mutable argument default * B007: unused loop control variable * B011: assert false
8bf1f75
to
6b3c4e9
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.
Thanks a lot!
* Use ignore instead of extend-ignore for ruff * Fix B028 no explicit stacklevel in warnings.warn * Fix B006, B007 and B011 (auto-fixes) * B006: mutable argument default * B007: unused loop control variable * B011: assert false * Fix the remaining B006 and B007 manually * Fix B015: pointless comparisons * Fix B017: pytest.raises(Exception) * Fix B023: function definition does not bind loop variable * Fix B005: strip with multicharacter strings * Fix B020: loop control variable overrides iterable * Fix B008: no function call in argument defaults * Fix B018: useless expression * Fix B904: raise from within except * Finally enable ruff bugbear lints * Fix readthedocs
resolved conflict stemming from pydata#9505 by accepting this branches changes (pydata#9505 was just a slight edit on the old try import .. except pattern)
Second pass on #8239 mainly addressing bugbear ruff lints.
whats-new.rst
api.rst