Skip to content

Commit

Permalink
Docs: indexing.rst finetuning (#6685)
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan authored Jun 10, 2022
1 parent a7799fb commit aa1d1d1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions doc/user-guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ looked-up from the coordinate values.
Dimensions of xarray objects have names, so you can also lookup the dimensions
by name, instead of remembering their positional order.

Thus in total, xarray supports four different kinds of indexing, as described
Quick overview
--------------

In total, xarray supports four different kinds of indexing, as described
below and summarized in this table:

.. |br| raw:: html
Expand Down Expand Up @@ -93,7 +96,7 @@ in the range '2000-01-01':'2000-01-02' along the first coordinate `time`
and with 'IA' value from the second coordinate `space`.

You can perform any of the label indexing operations `supported by pandas`__,
including indexing with individual, slices and arrays of labels, as well as
including indexing with individual, slices and lists/arrays of labels, as well as
indexing with boolean arrays. Like pandas, label based indexing in xarray is
*inclusive* of both the start and stop bounds.

Expand All @@ -113,32 +116,33 @@ Indexing with dimension names
With the dimension names, we do not have to rely on dimension order and can
use them explicitly to slice data. There are two ways to do this:

1. Use a dictionary as the argument for array positional or label based array
indexing:
1. Use the :py:meth:`~xarray.DataArray.sel` and :py:meth:`~xarray.DataArray.isel`
convenience methods:

.. ipython:: python
# index by integer array indices
da[dict(space=0, time=slice(None, 2))]
da.isel(space=0, time=slice(None, 2))
# index by dimension coordinate labels
da.loc[dict(time=slice("2000-01-01", "2000-01-02"))]
da.sel(time=slice("2000-01-01", "2000-01-02"))
2. Use the :py:meth:`~xarray.DataArray.sel` and :py:meth:`~xarray.DataArray.isel`
convenience methods:
2. Use a dictionary as the argument for array positional or label based array
indexing:

.. ipython:: python
# index by integer array indices
da.isel(space=0, time=slice(None, 2))
da[dict(space=0, time=slice(None, 2))]
# index by dimension coordinate labels
da.sel(time=slice("2000-01-01", "2000-01-02"))
da.loc[dict(time=slice("2000-01-01", "2000-01-02"))]
The arguments to these methods can be any objects that could index the array
along the dimension given by the keyword, e.g., labels for an individual value,
Python :py:class:`slice` objects or 1-dimensional arrays.


.. note::

We would love to be able to do indexing with labeled dimension names inside
Expand Down

0 comments on commit aa1d1d1

Please sign in to comment.