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

Test for variable name in coords True after xr.merge with compat="minimal" #7405

Closed
4 tasks done
BENR0 opened this issue Dec 28, 2022 · 2 comments · Fixed by #8104
Closed
4 tasks done

Test for variable name in coords True after xr.merge with compat="minimal" #7405

BENR0 opened this issue Dec 28, 2022 · 2 comments · Fixed by #8104
Labels
bug topic-combine combine/concat/merge

Comments

@BENR0
Copy link

BENR0 commented Dec 28, 2022

What happened?

Merging two DataArrays with compat="minimal" drops the conflicting variable from coords but the test if that variable is in coords results to True even though the variable gets dropped.

What did you expect to happen?

The test should be False

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr

da1 = xr.DataArray(np.zeros((2, 2)), dims=("y", "x"), name="1")
c1 = ("y", ["1", "2"])  
da1["c1"] = c1

da2 = xr.DataArray(np.zeros((2, 2)), dims=("y", "x"), name="2")
c2 = ("y", ["3", "4"])
da2["c1"] = c2

xrds = xr.merge([da1, da2], compat="minimal")

"c1" in xrds.coords # results to True but should be False

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.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0] python-bits: 64 OS: Linux OS-release: 5.10.0-1049-oem 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.12.0
pandas: 1.4.2
numpy: 1.22.3
scipy: 1.8.0
netCDF4: 1.5.8
pydap: None
h5netcdf: 1.0.0
h5py: 3.6.0
Nio: None
zarr: 2.11.3
cftime: 1.6.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.10
cfgrib: None
iris: None
bottleneck: 1.3.5
dask: 2022.05.0
distributed: 2022.5.0
matplotlib: 3.5.2
cartopy: 0.20.2
seaborn: None
numbagg: None
fsspec: 2022.8.2
cupy: None
pint: 0.19.2
sparse: None
flox: 0.6.5
numpy_groupies: 0.9.20
setuptools: 62.2.0
pip: 22.1
conda: None
pytest: 7.1.2
mypy: None
IPython: 8.3.0
sphinx: 4.5.0

@BENR0 BENR0 added bug needs triage Issue that has not been reviewed by xarray team member labels Dec 28, 2022
@dcherian
Copy link
Contributor

Thanks for the clear bug report. Here's some extra info:

"c1" in xr.merge([da1, da2], compat='minimal') # False
"c1" in xr.merge([da1, da2], compat='minimal').coords  # True
"c1" in xr.merge([da1, da2], compat='minimal').indexes # False

@benbovy this may have happened during the indexes work.

@dcherian dcherian removed the needs triage Issue that has not been reviewed by xarray team member label Jan 15, 2023
@benbovy
Copy link
Member

benbovy commented Jan 16, 2023

Yes thanks for the report. Looks like Dataset._coord_names got out of sync somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug topic-combine combine/concat/merge
Projects
Development

Successfully merging a pull request may close this issue.

3 participants