Return a scalar instead of DataArray when the return value is a scalar · Issue #987 · pydata/xarray (original) (raw)
Hi,
I'm not sure how devs will feel about this, but I wanted to ask because I'm getting into this issue frequently.
Currently many methods such as .min()
, .max()
, .mean()
returns a DataArray even for the cases where the return value is a scaler. For example,
import numpy as np import xarray as xr test = xr.DataArray(data=np.ones((10, 10)))
In [6]: test.min() Out[6]: <xarray.DataArray ()> array(1.0)
which makes a lot of other things break down and I have to use test.min().values
or float(test.min())
.
I think it would be great that these methods return a scalar when the return value is a scaler. For example,
In [7]: np.ones((10, 10)).mean() Out[7]: 1.0
Thank you!