Uh oh!
There was an error while loading. Please reload this page.
built-in accessor documentation - #3988
Conversation
dcherian
left a comment
There was a problem hiding this comment.
Excited to see this work at last.
Uh oh!
There was an error while loading. Please reload this page.
keewis
commented
Apr 22, 2020
there are a few of my questions / comments we can resolve by using something like classUncachedAccessor:
def__init__(self, accessor):
self._accessor=accessordef__get__(self, obj, cls):
ifobjisNone:
returnself._accessorreturnself._accessor(obj)The only disadvantage is that now I think we could try to trick
|
| """ | ||
| __slots__ = ("_da",) | ||
| # __slots__ = ("_da",) |
to match the behavior of _CachedAccessor, it also accepts the accessor class (not the object). We lose the ability for custom docstrings, though.
shoyer
commented
Apr 23, 2020
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 :) |
shoyer
commented
Apr 23, 2020
This is a really clever yet simple fix. I like it! A few ideas for testing:
|
shoyer
commented
Apr 23, 2020
👍 for a simple solution here like pandas rather than using inspect. I think it's probably actually slightly more accurate to show the class. |
keewis
commented
Apr 23, 2020
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 ( |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
keewis
commented
Jun 12, 2020
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
propertyto attach our built-in accessors (plot,dtandstr) to theDataArrayandDatasetclasses. However, becausepropertyreturns itself when trying to access it as a class attribute, this does not work when generating the documentation (sphinxinspects 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 getsphinxto work with_PlotMethods.__slots__, though.A few questions / comments on this:
I noticed we have
DataArray.plot.__call__andxarray.plot.plotbut 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. Forplotandstr, we could just list methods / attributes in subsections ofDataArray/Dataset(or keep thePlotting/str/ ... sections and add class subsections?), butdtis more complicated since it dispatches fordatetimeandtimedeltaisort -rc . && black . && mypy . && flake8whats-new.rstfor all changes andapi.rstfor new APIEdit: err, it seems I used the branch I pushed to the main repository for a documentation preview for this...