|
| 1 | +.. currentmodule:: xarray |
| 2 | + |
| 3 | +Working with numpy-like arrays |
| 4 | +============================== |
| 5 | + |
| 6 | +.. warning:: |
| 7 | + |
| 8 | + This feature should be considered experimental. Please report any bug you may find on |
| 9 | + xarray’s github repository. |
| 10 | + |
| 11 | +Numpy-like arrays (:term:`duck array`) extend the :py:class:`numpy.ndarray` with |
| 12 | +additional features, like propagating physical units or a different layout in memory. |
| 13 | + |
| 14 | +:py:class:`DataArray` and :py:class:`Dataset` objects can wrap these duck arrays, as |
| 15 | +long as they satisfy certain conditions (see :ref:`internals.duck_arrays`). |
| 16 | + |
| 17 | +.. note:: |
| 18 | + |
| 19 | + For ``dask`` support see :ref:`dask`. |
| 20 | + |
| 21 | + |
| 22 | +Missing features |
| 23 | +---------------- |
| 24 | +Most of the API does support :term:`duck array` objects, but there are a few areas where |
| 25 | +the code will still cast to ``numpy`` arrays: |
| 26 | + |
| 27 | +- dimension coordinates, and thus all indexing operations: |
| 28 | + |
| 29 | + * :py:meth:`Dataset.sel` and :py:meth:`DataArray.sel` |
| 30 | + * :py:meth:`Dataset.loc` and :py:meth:`DataArray.loc` |
| 31 | + * :py:meth:`Dataset.drop_sel` and :py:meth:`DataArray.drop_sel` |
| 32 | + * :py:meth:`Dataset.reindex`, :py:meth:`Dataset.reindex_like`, |
| 33 | + :py:meth:`DataArray.reindex` and :py:meth:`DataArray.reindex_like`: duck arrays in |
| 34 | + data variables and non-dimension coordinates won't be casted |
| 35 | + |
| 36 | +- functions and methods that depend on external libraries or features of ``numpy`` not |
| 37 | + covered by ``__array_function__`` / ``__array_ufunc__``: |
| 38 | + |
| 39 | + * :py:meth:`Dataset.ffill` and :py:meth:`DataArray.ffill` (uses ``bottleneck``) |
| 40 | + * :py:meth:`Dataset.bfill` and :py:meth:`DataArray.bfill` (uses ``bottleneck``) |
| 41 | + * :py:meth:`Dataset.interp`, :py:meth:`Dataset.interp_like`, |
| 42 | + :py:meth:`DataArray.interp` and :py:meth:`DataArray.interp_like` (uses ``scipy``): |
| 43 | + duck arrays in data variables and non-dimension coordinates will be casted in |
| 44 | + addition to not supporting duck arrays in dimension coordinates |
| 45 | + * :py:meth:`Dataset.rolling_exp` and :py:meth:`DataArray.rolling_exp` (uses |
| 46 | + ``numbagg``) |
| 47 | + * :py:meth:`Dataset.rolling` and :py:meth:`DataArray.rolling` (uses internal functions |
| 48 | + of ``numpy``) |
| 49 | + * :py:meth:`Dataset.interpolate_na` and :py:meth:`DataArray.interpolate_na` (uses |
| 50 | + :py:class:`numpy.vectorize`) |
| 51 | + * :py:func:`apply_ufunc` with ``vectorize=True`` (uses :py:class:`numpy.vectorize`) |
| 52 | + |
| 53 | +- incompatibilities between different :term:`duck array` libraries: |
| 54 | + |
| 55 | + * :py:meth:`Dataset.chunk` and :py:meth:`DataArray.chunk`: this fails if the data was |
| 56 | + not already chunked and the :term:`duck array` (e.g. a ``pint`` quantity) should |
| 57 | + wrap the new ``dask`` array; changing the chunk sizes works. |
| 58 | + |
| 59 | + |
| 60 | +Extensions using duck arrays |
| 61 | +---------------------------- |
| 62 | +Here's a list of libraries extending ``xarray`` to make working with wrapped duck arrays |
| 63 | +easier: |
| 64 | + |
| 65 | +- `pint-xarray <https://github.com/xarray-contrib/pint-xarray>`_ |
0 commit comments