You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there a reason the coords dictionary values cannot be a tuple? I found this fairly baffling to debug when it tripped me up.
# this works
xarray.DataArray(np.random.random((3, 3, 3)),
dims=('one', 'two', 'three'),
coords={
'one': ['four', 'five', 'six'],
}
)
# this throws the following error
# ValueError: dimensions ('four',) must have the same length as the number of data dimensions, ndim=0
xarray.DataArray(np.random.random((3, 3, 3)),
dims=('one', 'two', 'three'),
coords={
'one': ('four', 'five', 'six'),
}
)
even if there was a clearer error it would help quite a bit. As it stands you are thinking, 'what?! four isn't a dimension!'
using 0.8.2
The text was updated successfully, but these errors were encountered:
Tuples are overloaded so you can avoid writing another constructor -- they're interpreted as (dims, data[, attrs]), e.g., as described in the Dataset constructor. Otherwise it gets quite verbose to specify coordinates with dimensions.
Looking at the docs more carefully, we do mention this in the general overview of data structures, but not the API docs for DataArray.__init__. We should probably fix that.
This isn't clear to me either from reading the Data Structures section of the docs.
In my case I triggered the error by attempting to instantiate a DataArray passing a nested tuple coords=[('dim1', (point1, point2, point3)),...]. Since I consider tuple(list()) to be an anti-pattern I started looking elsewhere for the source of the error. Making explicit the use of tuple overloading would be helpful.
is there a reason the
coords
dictionary values cannot be a tuple? I found this fairly baffling to debug when it tripped me up.even if there was a clearer error it would help quite a bit. As it stands you are thinking, 'what?! four isn't a dimension!'
using 0.8.2
The text was updated successfully, but these errors were encountered: