-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
What happened?
Hi,
My code stopped working with the new update. It raises this error when regrouping data of my dataset:
TypeError: Index(...) must be called with a collection of some kind, None was passed
It appears that that the attribute labels is used to create a pd.Index() (link to source code), but this behavior should happen if the bins are not of type pd.IntervalIndex. Sorry if it is unclear (it is my first bug report). See the minimal code provided to reproduce the issue 🙏 .
What did you expect to happen?
The data grouped by "x":
<DatasetGroupBy, grouped over 1 grouper(s), 3 groups in total:
'x_bins': 3/3 groups present with labels (0,, 1], (1,, 2], (2,, 3]>
Minimal Complete Verifiable Example
import pandas as pd
import xarray as xr
from xarray.groupers import BinGrouper
ds = xr.Dataset(
{"dummy": ("x", [1, 2, 3, 4, 5])},
coords={"x": [0.5, 1.5, 2.0, 2.5, 3]}
)
bins = pd.IntervalIndex.from_tuples([(0, 1), (1, 2), (2, 3)])
grouper = BinGrouper(bins=bins)
print(ds.groupby({"x": grouper}))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?
Maybe there is just a typo in the new code here: I think we should remove not ❓...
Environment
xarray: 2025.4.0
pandas: 2.2.3
numpy: 2.0.2
scipy: 1.14.1
netCDF4: 1.7.2
pydap: None
h5netcdf: None
h5py: None
zarr: 2.18.2
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: 2025.2.0
distributed: 2025.2.0
matplotlib: 3.10.0
cartopy: 0.24.1
seaborn: None
numbagg: None
fsspec: 2024.12.0
cupy: None
pint: 0.24.4
sparse: 0.15.4
flox: 0.10.0
numpy_groupies: 0.11.2
setuptools: 75.1.0
pip: 24.2
conda: None
pytest: 8.3.5
mypy: None
IPython: 8.30.0
sphinx: 7.4.7