Skip to content

Commit ae3fea0

Browse files
authored
Update docstring for apply_ufunc, set_options (#5904)
1 parent 3c60814 commit ae3fea0

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

doc/conf.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,18 @@
147147
"matplotlib colormap name": ":doc:`matplotlib colormap name <matplotlib:gallery/color/colormap_reference>`",
148148
"matplotlib axes object": ":py:class:`matplotlib axes object <matplotlib.axes.Axes>`",
149149
"colormap": ":py:class:`colormap <matplotlib.colors.Colormap>`",
150-
# objects without namespace
150+
# objects without namespace: xarray
151151
"DataArray": "~xarray.DataArray",
152152
"Dataset": "~xarray.Dataset",
153153
"Variable": "~xarray.Variable",
154+
"DatasetGroupBy": "~xarray.core.groupby.DatasetGroupBy",
155+
"DataArrayGroupBy": "~xarray.core.groupby.DataArrayGroupBy",
156+
# objects without namespace: numpy
154157
"ndarray": "~numpy.ndarray",
155158
"MaskedArray": "~numpy.ma.MaskedArray",
156159
"dtype": "~numpy.dtype",
157160
"ComplexWarning": "~numpy.ComplexWarning",
161+
# objects without namespace: pandas
158162
"Index": "~pandas.Index",
159163
"MultiIndex": "~pandas.MultiIndex",
160164
"CategoricalIndex": "~pandas.CategoricalIndex",

xarray/core/computation.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ def apply_ufunc(
840840
the style of NumPy universal functions [1]_ (if this is not the case,
841841
set ``vectorize=True``). If this function returns multiple outputs, you
842842
must set ``output_core_dims`` as well.
843-
*args : Dataset, DataArray, GroupBy, Variable, numpy.ndarray, dask.array.Array or scalar
843+
*args : Dataset, DataArray, DataArrayGroupBy, DatasetGroupBy, Variable, numpy.ndarray, dask.array.Array or scalar
844844
Mix of labeled and/or unlabeled arrays to which to apply the function.
845845
input_core_dims : sequence of sequence, optional
846846
List of the same length as ``args`` giving the list of core dimensions
@@ -911,24 +911,24 @@ def apply_ufunc(
911911
- 'allowed': pass dask arrays directly on to ``func``. Prefer this option if
912912
``func`` natively supports dask arrays.
913913
- 'parallelized': automatically parallelize ``func`` if any of the
914-
inputs are a dask array by using `dask.array.apply_gufunc`. Multiple output
914+
inputs are a dask array by using :py:func:`dask.array.apply_gufunc`. Multiple output
915915
arguments are supported. Only use this option if ``func`` does not natively
916916
support dask arrays (e.g. converts them to numpy arrays).
917917
dask_gufunc_kwargs : dict, optional
918-
Optional keyword arguments passed to ``dask.array.apply_gufunc`` if
918+
Optional keyword arguments passed to :py:func:`dask.array.apply_gufunc` if
919919
dask='parallelized'. Possible keywords are ``output_sizes``, ``allow_rechunk``
920920
and ``meta``.
921921
output_dtypes : list of dtype, optional
922922
Optional list of output dtypes. Only used if ``dask='parallelized'`` or
923-
vectorize=True.
923+
``vectorize=True``.
924924
output_sizes : dict, optional
925925
Optional mapping from dimension names to sizes for outputs. Only used
926926
if dask='parallelized' and new dimensions (not found on inputs) appear
927927
on outputs. ``output_sizes`` should be given in the ``dask_gufunc_kwargs``
928928
parameter. It will be removed as direct parameter in a future version.
929929
meta : optional
930930
Size-0 object representing the type of array wrapped by dask array. Passed on to
931-
``dask.array.apply_gufunc``. ``meta`` should be given in the
931+
:py:func:`dask.array.apply_gufunc`. ``meta`` should be given in the
932932
``dask_gufunc_kwargs`` parameter . It will be removed as direct parameter
933933
a future version.
934934
@@ -943,7 +943,7 @@ def apply_ufunc(
943943
arrays. If ``func`` needs to manipulate a whole xarray object subset to each block
944944
it is possible to use :py:func:`xarray.map_blocks`.
945945
946-
Note that due to the overhead ``map_blocks`` is considerably slower than ``apply_ufunc``.
946+
Note that due to the overhead :py:func:`xarray.map_blocks` is considerably slower than ``apply_ufunc``.
947947
948948
Examples
949949
--------
@@ -954,7 +954,7 @@ def apply_ufunc(
954954
... return xr.apply_ufunc(func, a, b)
955955
...
956956
957-
You can now apply ``magnitude()`` to ``xr.DataArray`` and ``xr.Dataset``
957+
You can now apply ``magnitude()`` to :py:class:`DataArray` and :py:class:`Dataset`
958958
objects, with automatically preserved dimensions and coordinates, e.g.,
959959
960960
>>> array = xr.DataArray([1, 2, 3], coords=[("x", [0.1, 0.2, 0.3])])
@@ -989,7 +989,7 @@ def apply_ufunc(
989989
... )
990990
...
991991
992-
Inner product over a specific dimension (like ``xr.dot``):
992+
Inner product over a specific dimension (like :py:func:`dot`):
993993
994994
>>> def _inner(x, y):
995995
... result = np.matmul(x[..., np.newaxis, :], y[..., :, np.newaxis])
@@ -999,7 +999,7 @@ def apply_ufunc(
999999
... return apply_ufunc(_inner, a, b, input_core_dims=[[dim], [dim]])
10001000
...
10011001
1002-
Stack objects along a new dimension (like ``xr.concat``):
1002+
Stack objects along a new dimension (like :py:func:`concat`):
10031003
10041004
>>> def stack(objects, dim, new_coord):
10051005
... # note: this version does not stack coordinates
@@ -1034,10 +1034,9 @@ def apply_ufunc(
10341034
...
10351035
10361036
Most of NumPy's builtin functions already broadcast their inputs
1037-
appropriately for use in `apply`. You may find helper functions such as
1038-
numpy.broadcast_arrays helpful in writing your function. `apply_ufunc` also
1039-
works well with numba's vectorize and guvectorize. Further explanation with
1040-
examples are provided in the xarray documentation [3]_.
1037+
appropriately for use in ``apply_ufunc``. You may find helper functions such as
1038+
:py:func:`numpy.broadcast_arrays` helpful in writing your function. ``apply_ufunc`` also
1039+
works well with :py:func:`numba.vectorize` and :py:func:`numba.guvectorize`.
10411040
10421041
See Also
10431042
--------
@@ -1046,12 +1045,13 @@ def apply_ufunc(
10461045
numba.guvectorize
10471046
dask.array.apply_gufunc
10481047
xarray.map_blocks
1048+
:ref:`dask.automatic-parallelization`
1049+
User guide describing :py:func:`apply_ufunc` and :py:func:`map_blocks`.
10491050
10501051
References
10511052
----------
10521053
.. [1] http://docs.scipy.org/doc/numpy/reference/ufuncs.html
10531054
.. [2] http://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
1054-
.. [3] http://xarray.pydata.org/en/stable/computation.html#wrapping-custom-computation
10551055
"""
10561056
from .dataarray import DataArray
10571057
from .groupby import GroupBy

xarray/core/options.py

+32-29
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class T_Options(TypedDict):
5151
"enable_cftimeindex": True,
5252
"file_cache_maxsize": 128,
5353
"keep_attrs": "default",
54-
"warn_for_unclosed_files": False,
5554
"use_bottleneck": True,
55+
"warn_for_unclosed_files": False,
5656
}
5757

5858
_JOIN_OPTIONS = frozenset(["inner", "outer", "left", "right", "exact"])
@@ -75,8 +75,8 @@ def _positive_integer(value):
7575
"enable_cftimeindex": lambda value: isinstance(value, bool),
7676
"file_cache_maxsize": _positive_integer,
7777
"keep_attrs": lambda choice: choice in [True, False, "default"],
78-
"warn_for_unclosed_files": lambda value: isinstance(value, bool),
7978
"use_bottleneck": lambda value: isinstance(value, bool),
79+
"warn_for_unclosed_files": lambda value: isinstance(value, bool),
8080
}
8181

8282

@@ -123,38 +123,16 @@ class set_options:
123123
124124
Parameters
125125
----------
126-
display_width : int, default: 80
127-
Maximum display width for ``repr`` on xarray objects.
128-
display_max_rows : int, default: 12
129-
Maximum display rows.
130-
arithmetic_join : {"inner", "outer", "left", "right", "exact"}
126+
arithmetic_join : {"inner", "outer", "left", "right", "exact"}, default: "inner"
131127
DataArray/Dataset alignment in binary operations.
132-
file_cache_maxsize : int, default: 128
133-
Maximum number of open files to hold in xarray's
134-
global least-recently-usage cached. This should be smaller than
135-
your system's per-process file descriptor limit, e.g.,
136-
``ulimit -n`` on Linux.
137-
warn_for_unclosed_files : bool, default: False
138-
Whether or not to issue a warning when unclosed files are
139-
deallocated. This is mostly useful for debugging.
140-
cmap_sequential : str or matplotlib.colors.Colormap, default: "viridis"
141-
Colormap to use for nondivergent data plots. If string, must be
142-
matplotlib built-in colormap. Can also be a Colormap object
143-
(e.g. mpl.cm.magma)
144128
cmap_divergent : str or matplotlib.colors.Colormap, default: "RdBu_r"
145129
Colormap to use for divergent data plots. If string, must be
146130
matplotlib built-in colormap. Can also be a Colormap object
147131
(e.g. mpl.cm.magma)
148-
keep_attrs : {"default", True, False}
149-
Whether to keep attributes on xarray Datasets/dataarrays after
150-
operations. Can be
151-
152-
* ``True`` : to always keep attrs
153-
* ``False`` : to always discard attrs
154-
* ``default`` : to use original logic that attrs should only
155-
be kept in unambiguous circumstances
156-
display_style : {"text", "html"}
157-
Display style to use in jupyter for xarray objects.
132+
cmap_sequential : str or matplotlib.colors.Colormap, default: "viridis"
133+
Colormap to use for nondivergent data plots. If string, must be
134+
matplotlib built-in colormap. Can also be a Colormap object
135+
(e.g. mpl.cm.magma)
158136
display_expand_attrs : {"default", True, False}:
159137
Whether to expand the attributes section for display of
160138
``DataArray`` or ``Dataset`` objects. Can be
@@ -183,6 +161,31 @@ class set_options:
183161
* ``True`` : to always expand data variables
184162
* ``False`` : to always collapse data variables
185163
* ``default`` : to expand unless over a pre-defined limit
164+
display_max_rows : int, default: 12
165+
Maximum display rows.
166+
display_style : {"text", "html"}, default: "html"
167+
Display style to use in jupyter for xarray objects.
168+
display_width : int, default: 80
169+
Maximum display width for ``repr`` on xarray objects.
170+
file_cache_maxsize : int, default: 128
171+
Maximum number of open files to hold in xarray's
172+
global least-recently-usage cached. This should be smaller than
173+
your system's per-process file descriptor limit, e.g.,
174+
``ulimit -n`` on Linux.
175+
keep_attrs : {"default", True, False}
176+
Whether to keep attributes on xarray Datasets/dataarrays after
177+
operations. Can be
178+
179+
* ``True`` : to always keep attrs
180+
* ``False`` : to always discard attrs
181+
* ``default`` : to use original logic that attrs should only
182+
be kept in unambiguous circumstances
183+
use_bottleneck : bool, default: True
184+
Whether to use ``bottleneck`` to accelerate 1D reductions and
185+
1D rolling reduction operations.
186+
warn_for_unclosed_files : bool, default: False
187+
Whether or not to issue a warning when unclosed files are
188+
deallocated. This is mostly useful for debugging.
186189
187190
Examples
188191
--------

0 commit comments

Comments
 (0)