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

duplicate coord names in DataArray constructor #2226

Closed
tv3141 opened this issue Jun 12, 2018 · 3 comments · Fixed by #8491
Closed

duplicate coord names in DataArray constructor #2226

tv3141 opened this issue Jun 12, 2018 · 3 comments · Fixed by #8491

Comments

@tv3141
Copy link
Contributor

tv3141 commented Jun 12, 2018

Code Sample

>>> import numpy as np
>>> import xarray as xr
>>> da = xr.DataArray(np.zeros((2,3)), coords=[('unknown', [1, 2]), ('unknown', [0, 90, 180])])
>>> da
<xarray.DataArray (unknown: 3)>
array([[0., 0., 0.],
       [0., 0., 0.]])
Coordinates:
  * unknown  (unknown) int64 0 90 180
>>> da.dims
('unknown', 'unknown')
>>> da.coords
Coordinates:
  * unknown  (unknown) int64 0 90 180
>>> da.sel(unknown=90)
ValueError: conflicting sizes for dimension 'unknown': length 2 on <this-array> and length 3 on 'unknown'

Problem description

The DaraArray constructor creates an invalid DataArray given duplicate coordinate names.

Expected Output

The DaraArray constructor should raise an Exception given duplicate coordinates names.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 3.16.0-5-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8

xarray: 0.10.4
pandas: 0.23.0
numpy: 1.14.3
scipy: 1.1.0
netCDF4: 1.3.1
h5netcdf: 0.5.1
h5py: 2.8.0
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.5
distributed: 1.21.8
matplotlib: 2.2.2
cartopy: 0.16.0
seaborn: None
setuptools: 39.1.0
pip: 10.0.1
conda: None
pytest: 3.5.1
IPython: None
sphinx: None

@fujiisoup
Copy link
Member

Thanks for raising an issue.
It looks similar to #1499.

The DaraArray constructor should raise an Exception given duplicate coordinates names.

Agreed.
Do you mind to send a fix for this?

@stale
Copy link

stale bot commented May 12, 2020

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale
Copy link

stale bot commented Apr 29, 2022

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

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

Successfully merging a pull request may close this issue.

3 participants