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.
whats-new.rstapi.rstSummary
Add typed properties for external accessor packages (hvplot, cf-xarray, pint-xarray, rioxarray, xarray-plotly), enabling full IDE support including autocompletion, parameter hints, docstrings, and go-to-definition.
Problem
External accessor packages currently have no IDE support:
.plotThis affects every accessor package: hvplot, cf-xarray, pint-xarray, rioxarray, xarray-plotly, and the entire xarray-contrib ecosystem.
Solution
Add typed properties with lazy imports on
DataArray,Dataset, andDataTree:Key behaviors
hasattr()returnsFalsefor uninstalled packages - Clean runtime introspectionHelpful error messages when accessing uninstalled accessors:
External packages don't overwrite the typed properties - xarray's
register_*_accessorskips registration for known external accessors, preserving IDE support.Full IDE support for installed packages - autocompletion, parameter hints, docstrings all work.
Supported accessors
hvplotcfpintrioplotlyFiles changed
xarray/accessors.py(new) - Accessor registry and lazy loaderxarray/core/dataarray.py- Added typed accessor propertiesxarray/core/dataset.py- Added typed accessor propertiesxarray/core/datatree.py- Added typed accessor propertiesxarray/core/extensions.py- Skip registration for known external accessorspyproject.toml- Added mypy ignores for external packagesBackward compatibility
register_*_accessorcontinue to work (registration is silently skipped for known accessors)Example usage
Related