Working with numpy-like arrays#
Warning
This feature should be considered experimental. Please report any bug you may find on xarray’s github repository.
NumPy-like arrays (duck array) extend the numpy.ndarray
with
additional features, like propagating physical units or a different layout in memory.
DataArray
and Dataset
objects can wrap these duck arrays, as
long as they satisfy certain conditions (see Integrating with duck arrays).
Note
For dask
support see Parallel computing with Dask.
Missing features#
Most of the API does support duck array objects, but there are a few areas where
the code will still cast to numpy
arrays:
dimension coordinates, and thus all indexing operations:
Dataset.reindex()
,Dataset.reindex_like()
,DataArray.reindex()
andDataArray.reindex_like()
: duck arrays in data variables and non-dimension coordinates won’t be casted
functions and methods that depend on external libraries or features of
numpy
not covered by__array_function__
/__array_ufunc__
:Dataset.ffill()
andDataArray.ffill()
(usesbottleneck
)Dataset.bfill()
andDataArray.bfill()
(usesbottleneck
)Dataset.interp()
,Dataset.interp_like()
,DataArray.interp()
andDataArray.interp_like()
(usesscipy
): duck arrays in data variables and non-dimension coordinates will be casted in addition to not supporting duck arrays in dimension coordinatesDataset.rolling()
andDataArray.rolling()
(requiresnumpy>=1.20
)Dataset.rolling_exp()
andDataArray.rolling_exp()
(usesnumbagg
)Dataset.interpolate_na()
andDataArray.interpolate_na()
(usesnumpy.vectorize
)apply_ufunc()
withvectorize=True
(usesnumpy.vectorize
)
incompatibilities between different duck array libraries:
Dataset.chunk()
andDataArray.chunk()
: this fails if the data was not already chunked and the duck array (e.g. apint
quantity) should wrap the newdask
array; changing the chunk sizes works.
Extensions using duck arrays#
Here’s a list of libraries extending xarray
to make working with wrapped duck arrays
easier: