Indexing via sel
/loc
fails on multiindex float coordinate
#6802
Labels
sel
/loc
fails on multiindex float coordinate
#6802
What happened?
When I generate a stacked multiindex coordinate dataset
indexing the unstacked version of the data
ds
with both an integer as well as a float valueworks without a problem. But if I try to index the stacked version
ds2
the integer indexing works, but the float indexing
ds2.sel(y=1.2)
fails with anInvalidIndexError
.The
pandas
version works without any problem:The problems seems to lie in
xarray.core.utils.py
in themaybe_cast_to_coords_dtype
functionthat explicitly calls
np.asarray
on the coordinate label. This then later fails inpandas.core.indexes
via the_check_indexing_error
method, where it is checked that the label is a scalar, which it was beforemaybe_cast_to_coords_dtype
converted it. Why does this conversion happen there at all?What did you expect to happen?
Expecting
ds2.sel(x=3)
to return:Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)
[GCC 10.3.0]
python-bits: 64
OS: Linux
OS-release: 5.17.5-76051705-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.1
libnetcdf: 4.8.1
xarray: 2022.3.0
pandas: 1.4.3
numpy: 1.23.1
scipy: 1.8.1
netCDF4: 1.6.0
pydap: None
h5netcdf: 1.0.1
h5py: 3.7.0
Nio: None
zarr: 2.12.0
cftime: 1.6.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.2
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
setuptools: 63.2.0
pip: 22.1.2
conda: None
pytest: None
IPython: 7.33.0
sphinx: 5.0.2
/home/thorsten/.miniconda3/envs/artiq/lib/python3.8/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
The text was updated successfully, but these errors were encountered: