Description
What happened?
Hi!
I'm having trouble with some grouped reorganisation data. My expectation is that there should be only one piece of data in this position, so both the first
and last
functions should work? But it turned out to be an error.
What did you expect to happen?
No response
Minimal Complete Verifiable Example
The cases (from Xarray document Xarray Groupby #First and last) are as follows:
import xarray as xr
import numpy as np
ds = xr.Dataset(
{"foo": (("x", "y"), np.random.rand(4, 3))},
coords={"x": [10, 20, 30, 40], "letters": ("x", list("abba"))},
)
ds
ds.groupby("letters").first(...)
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
It seems to be pandas related?
`error: TypeError: float() argument must be a string or a real number, not 'ReprObject'`
Anything else we need to know?
No response
Environment
xarray: 2025.3.1
pandas: 2.2.3
numpy: 1.26.4
scipy: 1.15.2
netCDF4: 1.7.2
pydap: None
h5netcdf: 1.6.1
h5py: 3.13.0
zarr: None
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: 1.4.2
dask: 2025.4.0
distributed: 2025.4.0
matplotlib: 3.10.1
cartopy: 0.24.0
seaborn: 0.13.2
numbagg: None
fsspec: 2025.3.2
cupy: None
pint: 0.24.4
sparse: None
flox: 9.11
numpy_groupies: 0.11.2
setuptools: 79.0.0
pip: 25.0.1
conda: None
pytest: None
mypy: None
IPython: 9.1.0
sphinx: None
/opt/miniconda3/envs/learn/lib/python3.11/site-packages/_distutils_hack/init.py:30: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml
warnings.warn(