Skip to content

Commit

Permalink
Clarify pydata#8728 in docs
Browse files Browse the repository at this point in the history
- Add reference to numpy docs on view / copies in the corresponding section of the xarray docs, to help clarify pydata#8728 .
- Add note that `da.values()` returns a view in the header for `da.values()`.
  • Loading branch information
ks905383 committed Feb 13, 2024
1 parent 4806412 commit 8a7016e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions doc/user-guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ Whether array indexing returns a view or a copy of the underlying
data depends on the nature of the labels.

For positional (integer)
indexing, xarray follows the same rules as NumPy:
indexing, xarray follows the same `rules`_ as NumPy:

* Positional indexing with only integers and slices returns a view.
* Positional indexing with arrays or lists returns a copy.
Expand All @@ -764,8 +764,10 @@ Whether data is a copy or a view is more predictable in xarray than in pandas, s
unlike pandas, xarray does not produce `SettingWithCopy warnings`_. However, you
should still avoid assignment with chained indexing.

.. _SettingWithCopy warnings: https://pandas.pydata.org/pandas-docs/stable/indexing.html#returning-a-view-versus-a-copy
Note that other operations (such as :py:meth:`~xarray.DataArray.values`) may also return views rather than copies.

.. _SettingWithCopy warnings: https://pandas.pydata.org/pandas-docs/stable/indexing.html#returning-a-view-versus-a-copy
.. _rules: https://numpy.org/doc/stable/user/basics.copies.html

.. _multi-level indexing:

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def data(self, value: Any) -> None:
@property
def values(self) -> np.ndarray:
"""
The array's data as a numpy.ndarray.
A view onto the DataArray's underlying data as a numpy.ndarray.
If the array's data is not a numpy.ndarray this will attempt to convert
it naively using np.array(), which will raise an error if the array
Expand Down

0 comments on commit 8a7016e

Please sign in to comment.