Add categorized repr to the .xrs accessor (#3476)#3477
Merged
Conversation
Printing `da.xrs` or `ds.xrs` now lists the available operations grouped by category instead of showing the default object id. A helper parses the `# ---- Category ----` banners already present in the accessor source, so the listing stays in sync with the methods. `__repr__` renders grouped text; `_repr_html_` renders a table for notebooks. Falls back to a flat public-method list when source introspection is unavailable.
brendancol
commented
Jun 24, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Add categorized repr to the .xrs accessor (#3476)
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
- The text and HTML fallbacks label the no-category case differently. The
text path prints "(categories unavailable; flat method list)"; the HTML path
uses an "Available tools" row header (accessor.py:638 vs accessor.py:655).
Harmless, but matching the wording would make the two paths read the same.
Nits (optional improvements)
- accessor.py:619:
_accessor_categoriesis lru_cached and keyed on the class.
Only two classes ever reach it, so the cache is a two-entry memo. Fine as-is;
noting thatmaxsize=Noneis unbounded by design, not an oversight.
What looks good
- The parser reads the
# ---- Category ----banners already in the source, so
the listing can't drift from the real method set. The coverage test
(test_categories_cover_every_public_method) asserts an exact match against
vars(cls), which also catches a future nested non-underscore def leaking into
the listing. - HTML output escapes method and category names, with a dedicated test that
injects a<script>name to prove it. - The source-unavailable fallback is tested with a type()-built class whose
source inspect can't retrieve. - Pure-Python change with no array code, so no backend / dask / cupy / NaN
concerns apply.
Checklist
- Algorithm matches reference/paper: N/A (no algorithm)
- All implemented backends produce consistent results: N/A (no array code)
- NaN handling is correct: N/A
- Edge cases are covered by tests: yes (fallback, HTML escaping, DataArray vs Dataset)
- Dask chunk boundaries handled correctly: N/A
- No premature materialization or unnecessary copies: N/A
- Benchmark exists or is not needed: not needed (repr is interactive, not a hot path)
- README feature matrix updated: N/A (no new function)
- Docstrings present and accurate: yes (helpers documented; quickstart updated)
The text and HTML reprs used different labels when source banners can't be parsed. Both now route through a shared `_categories_or_fallback` helper that emits a single "Available tools" group, so the two paths read the same.
brendancol
commented
Jun 24, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
Follow-up review (after e6d1be2)
The one Suggestion from the first pass is resolved. The text and HTML reprs
now both route through _categories_or_fallback (accessor.py:644), so the
no-banner case shows the same "Available tools" group in either path. The
fallback test was updated to assert the shared label.
No new findings. The Nit about lru_cache(maxsize=None) was a note, not a
defect, and stands as-is (two classes, intentional). Pure-Python repr change;
no backend, dask, cupy, or NaN concerns apply. Nothing blocking.
This was referenced Jun 24, 2026
brendancol
added a commit
that referenced
this pull request
Jun 24, 2026
* Forward per-tool repr to the accessed tool (#3478) Evaluating a single accessor tool such as da.xrs.slope returned a bound method, whose repr embeds repr(self) and therefore the whole accessor catalog added in #3477. Wrap public methods in a callable _AccessorTool proxy on attribute access so the repr shows that tool's own signature and docstring instead. Calls forward unchanged and the delegated docstring is mirrored for help()/inspect. * Add per-tool repr tests for the .xrs accessor (#3478) * Document the per-tool repr in quickstart (#3478)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3476
Printing the
.xrsaccessor used to show the default object repr, whichtells you nothing about what you can call. Now it lists the available
operations grouped by category, so you can see the toolset from a plain
REPL or notebook without tab completion or an LSP.
__repr__renders a grouped, wrapped text listing;_repr_html_renders a compact table in Jupyter.
# ---- Category ----banners alreadyin the accessor source, so it can't drift from the actual method set. A
test asserts every public method lands in exactly one category.
isn't available (e.g. a frozen build).
Example:
Backend coverage: not applicable. This is a pure-Python repr on the
accessor classes; it touches no array code, so numpy / cupy / dask paths
are unaffected.
Test plan:
pytest xrspatial/tests/test_accessor.py(79 passed)repr content, DataArray vs Dataset distinct listings, HTML escaping,
source-unavailable fallback