-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
sel by slice not working for multi-index containing float-values #6838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report @nunupeke. That's definitely a regression. I'm not that surprised actually as the logic behind |
I'm working on this issue right now and I see this too. I don't think that providing slice objects to multi-index level coordinates in da
# <xarray.DataArray (x: 4)>
# array([0.30120807, 0.43951659, 0.19163508, 0.57251755])
# Coordinates:
# * x (x) object MultiIndex
# * y (x) float64 0.0 0.3333 0.6667 1.0
# * z (x) int64 4 5 6 7
da.sel(z=[4, 5])
# ValueError: Vectorized selection is not available along coordinate 'z' (multi-index level) The fact that it used to work with slices looks like a side effect. For example, providing a slice for only one of the level coordinates drops that coordinate in the resulting dataset (v2022.3.0): da.sel(y=slice(None, 0.5))
# <xarray.DataArray (z: 2)>
# array([0.4004091 , 0.11179854])
# Coordinates:
# * z (z) int64 4 5
#
# The 'y' coord is missing! It should be still there. I think that we could support slices in a clean way (maybe any sequence of values too?) by reusing # note the difference between
da.sel(y=0.0, z=slice(None))
# <xarray.DataArray (x: 1)>
# array([0.08696024])
# Coordinates:
# * x (x) object MultiIndex
# * y (x) float64 0.0
# * z (x) int64 4
# and
da.sel(y=0.0)
# <xarray.DataArray (z: 1)>
# array([0.08696024])
# Coordinates:
# * z (z) int64 4
# y float64 0.0
# the 1st one calls pandas.MultiIndex.get_locs, while
# the 2nd one calls pandas.MultiIndex.get_loc_level |
What happened?
fails with
What did you expect to happen?
In v2022.3, this yields the correct sliced selection. Also, in v2022.6 this works for Multiindices without float-Values
(only that the resulting coordinates look a bit weird, containing
slice
s). Also, the sliced selection for a regular float-based index works in v2202.6Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
Maybe related to #6836
Environment
INSTALLED VERSIONS
commit: None
python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 06:57:19) [MSC v.1929 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8
LOCALE: ('de_DE', 'cp1252')
libhdf5: None
libnetcdf: None
xarray: 2022.6.0
pandas: 1.4.3
numpy: 1.23.1
scipy: 1.8.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
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: 0.11.2
numbagg: None
fsspec: None
cupy: None
pint: 0.19.2
sparse: None
flox: None
numpy_groupies: None
setuptools: 63.2.0
pip: 22.2
conda: None
pytest: 7.1.2
IPython: 8.4.0
sphinx: 4.5.0
The text was updated successfully, but these errors were encountered: