Skip to content
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

isel with drop=True does not drop coordinates if using scalar DataArray as indexer #6554

Closed
headtr1ck opened this issue May 1, 2022 · 2 comments · Fixed by #6579
Closed
Labels

Comments

@headtr1ck
Copy link
Collaborator

What happened?

When using DataArray/Dataset.isel with drop=True with a scalar DataArray as indexer (see example) resulting scalar coordinates do not get dropped.
When using an integer the behavior is as expected.

What did you expect to happen?

I expect that using a scalar DataArray behaves the same as an integer.

Minimal Complete Verifiable Example

import xarray as xr

da = xr.DataArray([1, 2, 3], dims="x", coord={"k": ("x", [0, 1, 2])})
# <xarray.DataArray (x: 3)>
# array([1, 2, 3])
# Coordinates:
#     k        (x) int32 0 1 2

da.isel({"x": 1}, drop=True)
# works
# <xarray.DataArray ()>
# array(2)

da.isel({"x": xr.DataArray(1)}, drop=True)
# does not drop "k" coordinate
# <xarray.DataArray ()>
# array(2)
# Coordinates:
#     k        int32 1

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: 4fbca23
python: 3.9.6 | packaged by conda-forge | (default, Jul 6 2021, 08:46:02) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('de_DE', 'cp1252')
libhdf5: 1.10.6
libnetcdf: 4.7.4

xarray: 0.18.2.dev76+g3a7e7ca2.d20210706
pandas: 1.3.0
numpy: 1.21.0
scipy: 1.7.0
netCDF4: 1.5.6
pydap: installed
h5netcdf: 0.11.0
h5py: 3.3.0
Nio: None
zarr: 2.8.3
cftime: 1.5.0
nc_time_axis: 1.3.1
PseudoNetCDF: installed
cfgrib: None
iris: 2.4.0
bottleneck: 1.3.2
dask: 2021.06.2
distributed: 2021.06.2
matplotlib: 3.4.2
cartopy: 0.19.0.post1
seaborn: 0.11.1
numbagg: 0.2.1
fsspec: 2021.06.1
cupy: None
pint: 0.17
sparse: 0.12.0
setuptools: 49.6.0.post20210108
pip: 21.3.1
conda: None
pytest: 6.2.4
IPython: None
sphinx: None

@headtr1ck headtr1ck added bug needs triage Issue that has not been reviewed by xarray team member labels May 1, 2022
@dcherian dcherian removed the needs triage Issue that has not been reviewed by xarray team member label May 1, 2022
@headtr1ck
Copy link
Collaborator Author

It seems that this counts as "fancy indexing".
So either this intentional, or one could either add a check in Dataset._isel_fancy

if drop and new_var.ndim == 0:
    continue

or check if the indexer has ndim==0 in isel directly and do not enter the "fancy" path.

@benbovy
Copy link
Member

benbovy commented May 2, 2022

Thanks for the report @headtr1ck, I see that it is a regression bug introduced in #5692 when refactoring _isel_fancy (drop is ignored now, it shouldn't).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants