Skip to content
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

minor doc updates to clarify extensions using accessors #7751

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/internals/extending-xarray.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

Extending xarray
================
Extending xarray using accessors
================================

.. ipython:: python
:suppress:

import xarray as xr


Xarray is designed as a general purpose library, and hence tries to avoid
Xarray is designed as a general purpose library and hence tries to avoid
including overly domain specific functionality. But inevitably, the need for more
domain specific logic arises.

One standard solution to this problem is to subclass Dataset and/or DataArray to
One potential solution to this problem is to subclass Dataset and/or DataArray to
add domain specific functionality. However, inheritance is not very robust. It's
easy to inadvertently use internal APIs when subclassing, which means that your
code may break when xarray upgrades. Furthermore, many builtin methods will
Expand All @@ -29,7 +29,9 @@ from pandas) may suffice.
To resolve this issue for more complex cases, xarray has the
:py:func:`~xarray.register_dataset_accessor` and
:py:func:`~xarray.register_dataarray_accessor` decorators for adding custom
"accessors" on xarray objects. Here's how you might use these decorators to
"accessors" on xarray objects, thereby "extending" the functionality of your xarray object.

Here's how you might use these decorators to
write a custom "geo" accessor implementing a geography specific extension to
xarray:

Expand Down