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
Dataset allows assignment of new variables with dimension names that are used in a MultiIndex, even if the lengths do not match the existing coordinate.
a=pd.DataFrame({'a': [1, 2], 'b': [3, 4]}).unstack('a')
a.index.names= ['dim0', 'dim1']
a.index.name='stacked_dim'b=xr.Dataset(coords={'dim0': ['a', 'b'], 'dim1': [0, 1]})
b=b.stack(dim_stacked=['dim0', 'dim1'])
assert(len(b.dim0) ==4)
# This should raise an errors because the length is != 4b['c'] = (('dim0',), [10, 11])
b
Instead, it reports dim0 as a new dimension without coordinates:
Thanks for raising an issue, with a reproduceable example.
This looks a bug. It looks we just skip the duplicate check of the dimension names which are level variables of MultiIndex.
After the assignment, b['dim0'] returns [0, 1] not a level variable of the MultiIndex.
Dataset
allows assignment of new variables with dimension names that are used in a MultiIndex, even if the lengths do not match the existing coordinate.Instead, it reports
dim0
as a new dimension without coordinates:Similar cases of coordinates that aren't used do raise an error:
Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: