Skip to content

Commit ba3b217

Browse files
committed
Add docstrings to the xarray method.
1 parent 343a2bb commit ba3b217

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

pandas_flavor/xarray.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""XArray support for pandas_flavor."""
12
from xarray import register_dataarray_accessor, register_dataset_accessor
23
from functools import wraps
34

@@ -6,29 +7,67 @@ def make_accessor_wrapper(method):
67
"""
78
Makes an XArray-compatible accessor to wrap a method to be added to an
89
xr.DataArray, xr.Dataset, or both.
9-
:param method: A method which takes an XArray object and needed parameters.
10-
:return: The result of calling ``method``.
10+
11+
Args:
12+
method: A method which takes an XArray object and needed parameters.
13+
14+
Returns:
15+
The result of calling ``method``.
1116
"""
1217

1318
class XRAccessor:
19+
"""XArray accessor for a method."""
20+
1421
def __init__(self, xr_obj):
22+
"""Initialize the accessor.
23+
24+
Args:
25+
xr_obj: The XArray object to which the accessor is attached.
26+
"""
1527
self._xr_obj = xr_obj
1628

1729
@wraps(method)
1830
def __call__(self, *args, **kwargs):
31+
"""Call the method.
32+
33+
Args:
34+
*args: Positional arguments to pass to the method.
35+
**kwargs: Keyword arguments to pass to the method.
36+
37+
Returns:
38+
The result of calling ``method``.
39+
"""
40+
1941
return method(self._xr_obj, *args, **kwargs)
2042

2143
return XRAccessor
2244

2345

2446
def register_xarray_dataarray_method(method: callable):
47+
"""Register a method on an XArray DataArray object.
48+
49+
Args:
50+
method: A method which takes an XArray object and needed parameters.
51+
52+
Returns:
53+
The method.
54+
"""
2555
accessor_wrapper = make_accessor_wrapper(method)
2656
register_dataarray_accessor(method.__name__)(accessor_wrapper)
2757

2858
return method
2959

3060

3161
def register_xarray_dataset_method(method: callable):
62+
"""Register a method on an XArray Dataset object.
63+
64+
Args:
65+
method: A method which takes an XArray object and needed parameters.
66+
67+
Returns:
68+
The method.
69+
"""
70+
3271
accessor_wrapper = make_accessor_wrapper(method)
3372
register_dataset_accessor(method.__name__)(accessor_wrapper)
3473

0 commit comments

Comments
 (0)