Skip to content

Ruff 0.17 lint fixes - #1908

Merged
cmdupuis3 merged 18 commits into
mainfrom
ruff-0.17-lint-fixes
Nov 23, 2026
Merged

cmdupuis3 merged 18 commits into
mainfrom
ruff-0.17-lint-fixes

Conversation

@cmdupuis3

@cmdupuis3 cmdupuis3 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1858

Overview

This PR includes fixes that solve issues that will be flagged by Ruff 0.17.5. Commits are organized by theme, rather than by timestamp, for easy browsing and cherry-picking if needed. This PR should be stacked with #1625 somehow.

Most issues have to do with optional types, nested conditionals, or unidiomatic python contruct usage.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)

AI Disclosure

AI Usage: Claude Opus 5.5 for edits and merges

  • I have tested and take responsibility for all AI-generated content in my PR.

@cmdupuis3
cmdupuis3 added this pull request to stack #1909 November 18, 2026 19:52
@review-notebook-app

Copy link
Copy Markdown

Review Notebooks

Notebooks changed:

Review visual diffs and comment on any notebook cell. All comments sync back to this PR.


Powered by ReviewNB

@cmdupuis3 cmdupuis3 added the github_actions Pull requests that update GitHub Actions code label Nov 18, 2026
@cmdupuis3
cmdupuis3 marked this pull request as draft November 18, 2026 20:33
@cmdupuis3
cmdupuis3 force-pushed the ruff-0.17-lint-fixes branch from 3f554d1 to 0bee6c8 Compare November 18, 2026 23:09
@cmdupuis3 cmdupuis3 self-assigned this Nov 18, 2026
@cmdupuis3
cmdupuis3 marked this pull request as ready for review November 18, 2026 23:09

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PR stacks merge into main bottom-up, not top-down, so I believe this will never be mergeable without bypassing merge rules, because #1625's pre-commit check will always fail. I'd recommend having a single PR for this, instead of a stack, because #1625's change is one-line. Even though it would mean needing to continually merge the bot updates from #1625 into this PR to keep it up to date, I suspect that would be simpler than dealing with the quirks of stacked PRs.

Before giving a proper review, I will wait until you check the box that says you take responsibility for the AI-generated content here :)

@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

@Sevans711 We can just force-merge as long as this PR passes, at least that's my thinking.

@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

Also, there could be some style issues with underscores on private variables; some cases end up splitting e.g. nlat, _nlon, etc.

@Sevans711
Sevans711 force-pushed the ruff-0.17-lint-fixes branch from 0bee6c8 to fd6fdc1 Compare November 19, 2026 19:34
@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

@Sevans711 Looks like the bot pushed a commit and effectively rebased this whole branch, as intended. Kind of cool.

@cmdupuis3 cmdupuis3 changed the title Ruff 0.17.5 lint fixes Ruff 0.17.6 lint fixes Nov 19, 2026
@cmdupuis3 cmdupuis3 changed the title Ruff 0.17.6 lint fixes Ruff 0.17 lint fixes Nov 19, 2026
Comment thread uxarray/core/aggregation.py Resolved
Comment thread uxarray/core/dataarray.py Resolved
Comment thread uxarray/core/dataarray.py Resolved
Comment thread uxarray/core/dataarray.py Resolved
Comment thread uxarray/core/dataarray.py Resolved
Comment thread uxarray/grid/integrate.py Resolved
Comment thread uxarray/grid/neighbors.py Resolved
Comment thread uxarray/io/_exodus.py Resolved
Comment thread uxarray/plot/accessor.py Resolved
Comment thread uxarray/utils/warnings.py Resolved
@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

@Sevans711 Everything edited here was flagged by ruff, there shouldn't be anything extra that isn't forced by the linting update at some point.

The underscore issues should be resolved. Ruff can take either _ or private variables, so I changed it to go with private variables instead.

min and max changes were already tested for bitwise repro and speed changes, none were found. I was a little suspicious too, but they're compiled by numba and it should be smart enough to recognize the semantic equivalence and optimize it.

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Much closer to being merge-ready now, and thank you for the clarifications. I just have one new inline comment, left a couple followups to previous comments, plus remaining unresolved inline comment from before (#1908 (comment))

Comment thread uxarray/core/azimuthal.py Resolved

@dylannelson dylannelson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Everything that changed and was tested locally appears to run identically to the previous versions. Maybe a few smaller things that could be addressed further down the stack if they're still present, but approving for now and can discuss later after this is merged. No blockers and no meaningful slowdowns/differences observed on my end.

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All prior comments resolved, apparently ruff formatting isn't always my personal favorite style but nothing actually needs to block the PR, so I'm approving!

One thing I am a bit curious about is why this PR reformatted so many things using very old rules, e.g. https://docs.astral.sh/ruff/rules/zip-instead-of-pairwise/ was introduced into ruff in March 2023. Any guesses about why it is only surfacing in uxarray's formatting rules now? I thought that uxarray's rules were up to date until July 2026.

@cmdupuis3
cmdupuis3 force-pushed the ruff-0.17-lint-fixes branch from 99e09ab to 43267a7 Compare November 23, 2026 18:30
Base automatically changed from pre-commit-ci-update-config to main November 23, 2026 19:00
cmdupuis3 and others added 6 commits November 23, 2026 13:00
Use PEP 585/604 builtins and unions (UP006, UP045), make implicit
Optional defaults explicit (RUF013, plus UxDataset.from_xarray's uxgrid,
which ruff does not flag), import ABCs from collections.abc (UP035),
drop quoted annotations (UP037), use the PEP 695 `type` statement for
aliases (UP040), drop redundant `int | float` (PYI041, and likewise
inside the tolerance Iterable, which ruff does not flag), mark the
mutable class default as ClassVar (RUF012), and remove the typing
imports these leave unused (F401).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrite set(<genexpr>)/set([...])/list([...])/dict() as comprehensions or
literals (C401, C403, C405, C408, C411) and use next(iter(...)) instead
of building a list to take its first element (RUF015).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Convert str.format calls to f-strings (UP032) and use !r instead of
repr() inside f-strings (RUF010).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop extraneous parentheses (UP034), round() on values that are
already integers (RUF057), and int() around round(), which already
returns an int under numpy>=2 (RUF046).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collapse nested ifs that have no else branch (SIM102), return boolean
conditions directly (SIM103), iterate dicts instead of .keys() (SIM118),
use min()/max() instead of compare-and-assign (PLR1730), drop a no-op
pass and range(0, n) starts (PIE790, PIE808), and remove a try/except
that only re-raised (TRY203).

The min()/max() rewrites in the numba kernels (bounds, face radii,
node-edge connectivity, _widest) keep the original semantics exactly:
numba lowers min(a, b) to select(b < a, b, a) and max(a, b) to
select(b > a, b, a), the same comparison as the if-statements they
replace, so NaN, signed-zero and inf inputs give bit-identical results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace tuple-unpacking targets that are never read with a bare _
(RUF059), the convention the package already uses for discarded values,
and keep the unpack itself so the shape of each return value stays
visible. The unused n_max_face_nodes in angles.py predates ruff 0.17 but
gets the same treatment, so no _name-style discards are left.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cmdupuis3 and others added 12 commits November 23, 2026 13:00
Use `from package import module` instead of import-as aliases (PLR0402),
import MagicMock from unittest.mock unconditionally (UP026; the `mock`
backport is never needed on Python 3.12), use functools.cache (UP033),
and remove F401 noqa markers that docs/* already ignores (RUF100) while
keeping their explanatory comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sort __all__ and __slots__ entries (RUF022, RUF023). docs/conf.py set
__all__ to a tuple of modules to mark imports as used (PLE0604); F401
is already ignored for docs/*, so the line is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- callable(x) instead of hasattr(x, "__call__") (B004)
- plain attribute assignment instead of setattr with a constant (B010)
- don't shadow the face_nodes argument with the loop variable (B020, PLR1704)
- pass *args before keyword arguments; Python already bound them
  positionally first, so behavior is unchanged (B026)
- np.isnan instead of x != x self-comparisons in the SCRIP dedup (PLR0124)
- don't rebind `self` to the result of the exact-join xr.align check in
  weighted_mean (PLW0642); the call is only there to raise on mismatched
  grid-dimension coordinates, so only the aligned weights is kept. The
  aligned copy of self differs only when weights carries a grid-dimension
  index that self lacks; that index is summed away, and self * weights
  aligns the same way, so the result is unchanged
- drop a useless bare expression in area_calc.ipynb (B018)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uxarray/__init__.py: importlib.metadata is always available on Python
3.12, so drop the importlib_metadata fallback and catch only
PackageNotFoundError when the package isn't installed.

The remaining `except Exception` blocks are deliberate catch-all
fallbacks (axes extent auto-set, open_dataset engine retry, the IPython
matplotlib backend switch, numba FMA toolchain probes), so they get
`# noqa: BLE001` (and S110 for the try/except/pass) instead of a guessed
narrower exception type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The notebook has no shebang and is not meant to be executed directly
(EXE002).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop a stray `#` after a raise statement (PLR2044).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
_dask_ring_sums walked successive chunk boundaries with
zip(edges[:-1], edges[1:]), which ruff flags as RUF007 now that #1847 is
in the base; pairwise(edges) yields the same (lo, hi) pairs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per review, go back to _name instead of a bare _ for tuple-unpacking
targets that are never read. RUF059 accepts either form, and the name
records what the discarded value is (e.g. _grad_u_zonal), which helps
readers and later changes. This also restores _n_max_face_nodes in
angles.py, which ruff never flagged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per review: the earlier PLW0642 fix discarded the aligned copy of self
returned by the exact-join xr.align check and kept using the original
self. Name that copy data instead, and use it everywhere the old code
used the rebound self, so weighted_mean computes exactly what it did
before without reassigning self.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Per review, the dict literal nested in the f-string (from the C408 fix
for dict(method=..., tolerance=...)) was hard to read. Build it as
options first and interpolate that; the error message is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmdupuis3
cmdupuis3 force-pushed the ruff-0.17-lint-fixes branch from 43267a7 to ca9d70d Compare November 23, 2026 19:00
@cmdupuis3
cmdupuis3 merged commit 755ce6e into main Nov 23, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-commit bot update requires substantial code updates

3 participants