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

MergeError: coordinate mytime1 shares a name with a dataset dimension …. This is disallowed by the xarray data model. #2931

Closed
ahmedshaaban1 opened this issue Apr 30, 2019 · 3 comments

Comments

@ahmedshaaban1
Copy link

import xarray as xr
import pandas as p
import numpy as np

var1 = np.ones((364))
tt1=p.date_range('1/1/2018','12/30/2018')
tt1.name= 'time1_name'

var=xr.Dataset(
		data_vars={
			'var1':(('mytime1'),var1),
			},
		coords={
			'mytime1':tt1,
			}
)

Problem description

I got the following error "MergeError: coordinate mytime1 shares a name with a dataset dimension, but is not a 1D variable along that dimension. This is disallowed by the xarray data model." when I inlcude name attribue "time1_name" to the var1 dimension mytime1.

Expected Output

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.14.final.0 python-bits: 64 OS: Darwin OS-release: 18.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

xarray: 0.10.9
pandas: 0.23.4
numpy: 1.14.2
scipy: 1.0.0
netCDF4: 1.3.1
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: None
cftime: None
PseudonetCDF: None
rasterio: None
iris: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.16.1
distributed: 1.20.2
matplotlib: 2.1.2
cartopy: 0.16.0
seaborn: 0.8.1
setuptools: 40.8.0
pip: 18.1
conda: 4.4.10
pytest: 3.3.2
IPython: 5.4.1
sphinx: 1.6.6

@TomNicholas
Copy link
Member

So in xarray coordinates which have the same name as dimensions are given special status - they are known as "dimension coordinates". (Yes this is confusing and I think there are plans to make this structure clearer in the future.)

Dimension coordinates have to be 1D along the corresponding dimension, as indicated by the error message. However in your example you didn't specify the dimension which you want the coordinate tt1 to have, because you didn't put it in a tuple with the desired dimensions like you did with the variable var1. If you add the desired dimension in then the error is no longer thrown, and I think gives you the dataset you want:

import xarray as xr
import pandas as p
import numpy as np

var1 = np.ones((364))
tt1=p.date_range('1/1/2018','12/30/2018')
tt1.name= 'time1_name'

var=xr.Dataset(
		data_vars={
			'var1':(('mytime1'),var1),
			},
		coords={
			'mytime1':(('mytime1'), tt1),
			}
)

which when printed gives

<xarray.Dataset>
Dimensions:  (mytime1: 364)
Coordinates:
  * mytime1  (mytime1) datetime64[ns] 2018-01-01 2018-01-02 ... 2018-12-30
Data variables:
    var1     (mytime1) float64 1.0 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0 1.0

@ahmedshaaban1
Copy link
Author

Thanks ... in case I used delattr to delete the name so that I can avoid the error message, then what is the difference between specifing or ignoring the dimnsion that the coordinate is attached.
coords={ 'mytime1':(('mytime1'), tt1), }
and
coords={ 'mytime1': tt1, }

@shoyer
Copy link
Member

shoyer commented May 6, 2019

Yes, we'd like to remove this "feature" -- see #2368 for more discussion

joelfiddes added a commit to ArcticSnow/TopoPyScale that referenced this issue Apr 21, 2023
…he xarray dataset, see this issue:

  pydata/xarray#2931 xarray.core.merge.MergeError:

  Error that needed fixing:
  coordinate point_id shares a name with a dataset dimension, but is not a 1D variable along that dimension. This is disallowed by the xarray data model.
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

No branches or pull requests

4 participants