Fixes #790: add .xrs xarray accessors#868
Merged
brendancol merged 3 commits intomasterfrom Feb 24, 2026
Merged
Conversation
Register DataArray and Dataset accessors so spatial operations can be called directly via tab-completion (e.g. raster.xrs.slope()). Update all user guide and example notebooks to use the accessor pattern, removing per-function imports in favor of a single `import xrspatial`.
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.
Summary
.xrsDataArray and Dataset accessors so spatial operations can be called directly via tab-completion, aligning with the xarray ecosystem pattern (rioxarray.rio, etc.)import xrspatial— no extra setup neededraster.xrs.slope()styleNew files
xrspatial/accessor.py—XrsSpatialDataArrayAccessorandXrsSpatialDatasetAccessorclasses with lazy imports in every method body to avoid loading numba/cupy/dask at registration timexrspatial/tests/test_accessor.py— 21 tests covering registration, tab-completion, DataArray single/multi-input, and Dataset single/multi-input equivalenceAPI examples
Notebooks updated
All 11 user guide and example notebooks converted to accessor style:
1_Surface,2_Proximity,3_Zonal,4_Focal,5_Classification,6_Remote_Sensing,7_Pathfinding,9_Cost_Distance,zonal_crosstab,pharmacy-deserts,classification-methodsTest plan
pytest xrspatial/tests/test_accessor.py -v— 21/21 passedpytest xrspatial/tests/ -v— 635 passed, 12 skipped, 0 failuresCloses #790