Closed
Description
What is your issue?
We raise an error on grouping without supplying dims, but not for float indexes — is this intentional or an oversight?
This is without
flox
installed
da = xr.tutorial.open_dataset("air_temperature")['air']
da.drop_vars('lat').groupby('lat').sum()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[8], line 1
----> 1 da.drop_vars('lat').groupby('lat').sum()
...
ValueError: cannot reduce over dimensions ['lat']. expected either '...' to reduce over all dimensions or one or more of ('time', 'lon').
But with a float index, we don't raise:
da.groupby('lat').sum()
...returns the original array:
Out[15]:
<xarray.DataArray 'air' (time: 2920, lat: 25, lon: 53)>
array([[[296.29 , 296.79 , 297.1 , ..., 296.9 , 296.79 ,
296.6 ],
[295.9 , 296.19998, 296.79 , ..., 295.9 , 295.9 ,
295.19998],
[296.6 , 296.19998, 296.4 , ..., 295.4 , 295.1 ,
294.69998],
...
And if we try this with a non-float index, we get the error again:
da.groupby('time').sum()
ValueError: cannot reduce over dimensions ['time']. expected either '...' to reduce over all dimensions or one or more of ('lat', 'lon').