-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
built-in accessor documentation #3988
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excited to see this work at last.
there are a few of my questions / comments we can resolve by using something like class UncachedAccessor:
def __init__(self, accessor):
self._accessor = accessor
def __get__(self, obj, cls):
if obj is None:
return self._accessor
return self._accessor(obj) The only disadvantage is that now I think we could try to trick
|
xarray/plot/plot.py
Outdated
@@ -438,7 +438,7 @@ class _PlotMethods: | |||
For example, DataArray.plot.imshow | |||
""" | |||
|
|||
__slots__ = ("_da",) | |||
# __slots__ = ("_da",) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @crusaderky
to match the behavior of _CachedAccessor, it also accepts the accessor class (not the object). We lose the ability for custom docstrings, though.
I think pandas might do something similar to do this? It might be worth checking, though it looks like you've figured most of it out already :) |
This is a really clever yet simple fix. I like it! A few ideas for testing:
|
👍 for a simple solution here like pandas rather than using inspect. I think it's probably actually slightly more accurate to show the class. |
where should the docstring of the accessor come from? Right now, this is the docstring of the return value which seems reasonable to me. I added tests verifying that |
I added the accessor templates from I think we should add a accessor section to each of the main objects ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @keewis. LGTM and it's a very nice improvement to our documentation.
I think this is ready for merging; the fix of the |
…o-combine * 'master' of github.com:pydata/xarray: (81 commits) use builtin python types instead of the numpy alias (pydata#4170) Revise pull request template (pydata#4039) pint support for Dataset (pydata#3975) drop eccodes in docs (pydata#4162) Update issue templates inspired/based on dask (pydata#4154) Fix failing upstream-dev build & remove docs build (pydata#4160) Improve typehints of xr.Dataset.__getitem__ (pydata#4144) provide a error summary for assert_allclose (pydata#3847) built-in accessor documentation (pydata#3988) Recommend installing cftime when time decoding fails. (pydata#4134) parameter documentation for DataArray.sel (pydata#4150) speed up map_blocks (pydata#4149) Remove outdated note from datetime accessor docstring (pydata#4148) Fix the upstream-dev pandas build failure (pydata#4138) map_blocks: Allow passing dask-backed objects in args (pydata#3818) keep attrs in reset_index (pydata#4103) Fix open_rasterio() for WarpedVRT with specified src_crs (pydata#4104) Allow non-unique and non-monotonic coordinates in get_clean_interp_index and polyfit (pydata#4099) update numpy's intersphinx url (pydata#4117) xr.infer_freq (pydata#4033) ...
We currently use
property
to attach our built-in accessors (plot
,dt
andstr
) to theDataArray
andDataset
classes. However, becauseproperty
returns itself when trying to access it as a class attribute, this does not work when generating the documentation (sphinx
inspects classes, not class instances).This adds a
property
-like descriptor that works on both classes and instance objects (the name could be more descriptive) and uses that to document theDataset.plot.*
andDataArray.plot.*
methods (see the rendered documentation). I have not been able to getsphinx
to work with_PlotMethods.__slots__
, though.A few questions / comments on this:
I noticed we have
DataArray.plot.__call__
andxarray.plot.plot
but notDataArray.plot.plot
. Is that something that is worth adding?The functions decorated with the custom property define docstrings which currently are lost. Should we patch them on their return values?
Right now, the error message when accidentally trying to call e.g.
xr.DataArray.plot.line()
is not very helpful:api.rst
. Forplot
andstr
, we could just list methods / attributes in subsections ofDataArray
/Dataset
(or keep thePlotting
/str
/ ... sections and add class subsections?), butdt
is more complicated since it dispatches fordatetime
andtimedelta
isort -rc . && black . && mypy . && flake8
whats-new.rst
for all changes andapi.rst
for new APIEdit: err, it seems I used the branch I pushed to the main repository for a documentation preview for this...