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

built-in accessor documentation #3988

Merged
merged 25 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d808d4
ad a property-like descriptor that works both on objects and classes
keewis Apr 21, 2020
8b60a2a
generate documentation for the plotting accessor methods
keewis Apr 21, 2020
fc0fe04
Merge branch 'master' into accessor-documentation
keewis Apr 21, 2020
4f3780f
add a docstring to the custom property-like descriptor
keewis Apr 21, 2020
001c8d0
use the accessor syntax in the main plotting section
keewis Apr 22, 2020
ee183b0
explain why we need a custom property class
keewis Apr 22, 2020
c96663f
rename the custom property to UncachedAccessor
keewis Apr 22, 2020
261c69f
declare that __call__ wraps plot
keewis Apr 22, 2020
6ba1b52
add accessor tests
keewis Apr 23, 2020
e904e65
Merge branch 'master' into accessor-documentation
keewis May 3, 2020
eb54df8
add the autosummary templates from pandas
keewis May 7, 2020
b2b5432
update the plotting section to use the accessor templates
keewis May 7, 2020
f6a3eaa
Merge branch 'master' into accessor-documentation
keewis May 7, 2020
c933365
remove the separate callable section
keewis May 7, 2020
a456bd1
fix the import order
keewis May 8, 2020
08cb916
add the DataArray.str accessor as a new subsection
keewis May 14, 2020
00fa2e6
Merge branch 'master' into accessor-documentation
keewis Jun 1, 2020
eaf95c4
add the datetime accessor to the main api page
keewis Jun 1, 2020
494c4f1
move the plotting functions into the DataArray / Dataset sections
keewis Jun 1, 2020
1e45275
remove the documentation of the accessor class itself
keewis Jun 2, 2020
371bd0f
manually copy the docstring since functools.wraps does more than that
keewis Jun 2, 2020
5cd9f12
also copy the annotations and mark __call__ as wrapping plot
keewis Jun 2, 2020
7df8068
re-enable __slots__
keewis Jun 2, 2020
6fb736b
update whats-new.rst
keewis Jun 8, 2020
4940b53
Merge branch 'master' into accessor-documentation
dcherian Jun 12, 2020
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
20 changes: 10 additions & 10 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -667,17 +667,17 @@ Plotting
:toctree: generated/

Dataset.plot
plot.scatter
DataArray.plot
Dataset.plot.scatter
plot.plot
plot.contourf
plot.contour
plot.hist
plot.imshow
plot.line
plot.pcolormesh
plot.step
plot.FacetGrid
DataArray.plot
DataArray.plot.contourf
DataArray.plot.contour
DataArray.plot.hist
DataArray.plot.imshow
DataArray.plot.line
DataArray.plot.pcolormesh
DataArray.plot.step


Faceting
--------
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ def func(self, other):
def _copy_attrs_from(self, other: Union["DataArray", Dataset, Variable]) -> None:
self.attrs = other.attrs

@property
@utils.property_
def plot(self) -> _PlotMethods:
"""
Access plotting functions for DataArray's
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5551,7 +5551,7 @@ def real(self):
def imag(self):
return self._unary_op(lambda x: x.imag, keep_attrs=True)(self)

@property
@utils.property_
def plot(self):
"""
Access plotting functions for Datasets.
Expand Down
10 changes: 10 additions & 0 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,16 @@ def drop_dims_from_indexers(
)


class property_:
""" Acts like a property, but on both classes and class instances """

def __init__(self, func):
keewis marked this conversation as resolved.
Show resolved Hide resolved
self._func = func

def __get__(self, obj, cls):
return self._func(obj)


# Singleton type, as per https://github.com/python/typing/pull/240
class Default(Enum):
token = 0
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class _PlotMethods:
For example, DataArray.plot.imshow
"""

__slots__ = ("_da",)
# __slots__ = ("_da",)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def __init__(self, darray):
self._da = darray
Expand Down