-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
What happened?
When reducing a DataArray after using groupby, and reducing over a dimension that does not exist, the given error is
ValueError: cannot reduce over dimensions ['<missing dimension>']. expected either '...' to reduce over all dimensions or one or more of (<existing dimension). Alternatively, install the `flox` package.Doing the same but without using groupby gives a much more clear error
ValueError: '<missing dimension>' not found in array dimensions (<existing dimensions>)What did you expect to happen?
I'd expect both examples to give the error
ValueError: '<missing dimension>' not found in array dimensions (<existing dimensions>)which is a much more clear indication of what caused the error
Minimal Complete Verifiable Example
import numpy as np
import xarray as xr
ds = xr.DataArray(np.reshape(range(27), (3, 3, 3)),
coords=dict(lon=range(3),
lat=range(3),
time=xr.date_range('2025-10-01 00:00', '2025-10-01 02:00', freq='h')))
ds.std(dim='lon') # OK
ds.groupby('time').std(dim='lon') # OK
ds.std(dim='longitude') # ValueError: 'longitude' not found in array dimensions ('lon', 'lat', 'time')
ds.groupby('time').std(dim='longitude') # ValueError: cannot reduce over dimensions ['longitude']. expected either '...' to reduce over all dimensions or one or more of ('lon', 'lat', 'time'). Alternatively, install the `flox` package.Steps to reproduce
No response
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.14.0 | packaged by conda-forge | (main, Oct 22 2025, 23:18:03) [MSC v.1944 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 11
machine: AMD64
processor: Intel64 Family 6 Model 189 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: ('English_Netherlands', '1252')
libhdf5: None
libnetcdf: None
xarray: 2025.10.1
pandas: 2.3.3
numpy: 2.3.4
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 25.2
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None