Skip to content

Docs: indexing.rst finetuning #6685

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

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
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
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