Skip to content

Commit 48fbee0

Browse files
authored
parameter documentation for DataArray.sel (#4150)
* copy the parameter documentation of Dataset.sel to DataArray.sel * reflow the return value documentation * update whats-new.rst
1 parent 59a2397 commit 48fbee0

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ Documentation
172172
By `Matthias Riße <https://github.com/risebell>`_.
173173
- Apply ``black`` to all the code in the documentation (:pull:`4012`)
174174
By `Justus Magin <https://github.com/keewis>`_.
175-
- Narrative documentation now describes :py:meth:`map_blocks`. :ref:`dask.automatic-parallelization`.
175+
- Narrative documentation now describes :py:meth:`map_blocks`: :ref:`dask.automatic-parallelization`.
176176
By `Deepak Cherian <https://github.com/dcherian>`_.
177+
- Add documentation for the parameters and return values of :py:meth:`DataArray.sel`.
178+
By `Justus Magin <https://github.com/keewis>`_.
177179

178180
Internal Changes
179181
~~~~~~~~~~~~~~~~

xarray/core/dataarray.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,19 @@ def sel(
10761076
"""Return a new DataArray whose data is given by selecting index
10771077
labels along the specified dimension(s).
10781078
1079+
In contrast to `DataArray.isel`, indexers for this method should use
1080+
labels instead of integers.
1081+
1082+
Under the hood, this method is powered by using pandas's powerful Index
1083+
objects. This makes label based indexing essentially just as fast as
1084+
using integer indexing.
1085+
1086+
It also means this method uses pandas's (well documented) logic for
1087+
indexing. This means you can use string shortcuts for datetime indexes
1088+
(e.g., '2000-01' to select all values in January 2000). It also means
1089+
that slices are treated as inclusive of both the start and stop values,
1090+
unlike normal Python indexing.
1091+
10791092
.. warning::
10801093
10811094
Do not try to assign values when using any of the indexing methods
@@ -1088,6 +1101,45 @@ def sel(
10881101
Assigning values with the chained indexing using ``.sel`` or
10891102
``.isel`` fails silently.
10901103
1104+
Parameters
1105+
----------
1106+
indexers : dict, optional
1107+
A dict with keys matching dimensions and values given
1108+
by scalars, slices or arrays of tick labels. For dimensions with
1109+
multi-index, the indexer may also be a dict-like object with keys
1110+
matching index level names.
1111+
If DataArrays are passed as indexers, xarray-style indexing will be
1112+
carried out. See :ref:`indexing` for the details.
1113+
One of indexers or indexers_kwargs must be provided.
1114+
method : {None, 'nearest', 'pad'/'ffill', 'backfill'/'bfill'}, optional
1115+
Method to use for inexact matches:
1116+
1117+
* None (default): only exact matches
1118+
* pad / ffill: propagate last valid index value forward
1119+
* backfill / bfill: propagate next valid index value backward
1120+
* nearest: use nearest valid index value
1121+
tolerance : optional
1122+
Maximum distance between original and new labels for inexact
1123+
matches. The values of the index at the matching locations must
1124+
satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
1125+
drop : bool, optional
1126+
If ``drop=True``, drop coordinates variables in `indexers` instead
1127+
of making them scalar.
1128+
**indexers_kwargs : {dim: indexer, ...}, optional
1129+
The keyword arguments form of ``indexers``.
1130+
One of indexers or indexers_kwargs must be provided.
1131+
1132+
Returns
1133+
-------
1134+
obj : DataArray
1135+
A new DataArray with the same contents as this DataArray, except the
1136+
data and each dimension is indexed by the appropriate indexers.
1137+
If indexer DataArrays have coordinates that do not conflict with
1138+
this object, then these coordinates will be attached.
1139+
In general, each array's data will be a view of the array's data
1140+
in this DataArray, unless vectorized indexing was triggered by using
1141+
an array indexer, in which case the data will be a copy.
1142+
10911143
See Also
10921144
--------
10931145
Dataset.sel

0 commit comments

Comments
 (0)