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

.rename() does not check conflict with multiindex level names #3657

Closed
hazbottles opened this issue Jan 1, 2020 · 0 comments · Fixed by #3658
Closed

.rename() does not check conflict with multiindex level names #3657

hazbottles opened this issue Jan 1, 2020 · 0 comments · Fixed by #3658

Comments

@hazbottles
Copy link
Contributor

hazbottles commented Jan 1, 2020

MCVE Code Sample

>>> import xarray as xr
>>> ds = xr.Dataset({"x": 42}, {"level0": [0, 1], "level1": [3, 4]}).set_index(mindex=["level0", "level1"])
>>> ds
<xarray.Dataset>
Dimensions:  (mindex: 2)
Coordinates:
  * mindex   (mindex) MultiIndex
  - level0   (mindex) int64 0 1
  - level1   (mindex) int64 3 4
Data variables:
    x        int64 42
>>> ds.rename({"x": "level0"})
<xarray.Dataset>
Dimensions:  (mindex: 2)
Coordinates:
  * mindex   (mindex) MultiIndex
  - level0   (mindex) int64 0 1
  - level1   (mindex) int64 3 4
Data variables:
    level0   int64 42

Expected Output

raise a ValueError("conflicting Multiindex names ...")

Problem Description

Using .rename() you can get into a situation where you have a data variable or coordinate with the same name as a multi-index level name.

Output of xr.show_versions()

INSTALLED VERSIONS

commit: b3d3b44
python: 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.4.0-18362-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: None
libnetcdf: None

xarray: 0.14.1+36.gb3d3b44
pandas: 0.25.3
numpy: 1.18.0
scipy: None
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: 2.9.1
distributed: 2.9.1
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
setuptools: 42.0.2.post20191201
pip: 19.3.1
conda: None
pytest: 5.3.2
IPython: None
sphinx: None

@hazbottles hazbottles changed the title .rename() does not check conflict with multiindex variable .rename() does not check conflict with multiindex level names Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant