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

renaming Variable to a dimension name does not convert to IndexVariable #4107

Closed
dcherian opened this issue May 28, 2020 · 0 comments · Fixed by #6999
Closed

renaming Variable to a dimension name does not convert to IndexVariable #4107

dcherian opened this issue May 28, 2020 · 0 comments · Fixed by #6999
Assignees

Comments

@dcherian
Copy link
Contributor

Seen in #4103

MCVE Code Sample

from xarray.tests import assert_identical

coord_1 = xr.DataArray([1, 2], dims=["coord_1"], attrs={"attrs": True})
da = xr.DataArray([1, 0], [coord_1])
obj = da.reset_index("coord_1").rename({"coord_1_": "coord_1"})
assert_identical(da, obj)

Expected Output

Problem Description

AssertionErrorTraceback (most recent call last)
<ipython-input-19-02ef6bd89884> in <module>
----> 1 assert_identical(da, obj)

~/work/python/xarray/xarray/tests/__init__.py in assert_identical(a, b)
    160     xarray.testing.assert_identical(a, b)
    161     xarray.testing._assert_internal_invariants(a)
--> 162     xarray.testing._assert_internal_invariants(b)
    163 
    164 

~/work/python/xarray/xarray/testing.py in _assert_internal_invariants(xarray_obj)
    265         _assert_variable_invariants(xarray_obj)
    266     elif isinstance(xarray_obj, DataArray):
--> 267         _assert_dataarray_invariants(xarray_obj)
    268     elif isinstance(xarray_obj, Dataset):
    269         _assert_dataset_invariants(xarray_obj)

~/work/python/xarray/xarray/testing.py in _assert_dataarray_invariants(da)
    210     assert all(
    211         isinstance(v, IndexVariable) for (k, v) in da._coords.items() if v.dims == (k,)
--> 212     ), {k: type(v) for k, v in da._coords.items()}
    213     for k, v in da._coords.items():
    214         _assert_variable_invariants(v, k)

AssertionError: {'coord_1': <class 'xarray.core.variable.Variable'>}

Versions

Output of xr.show_versions()
@dcherian dcherian changed the title renaming Variable to a dimension name does not convert to IndexVariables renaming Variable to a dimension name does not convert to IndexVariable May 28, 2020
@dcherian dcherian mentioned this issue Sep 15, 2021
54 tasks
@benbovy benbovy self-assigned this Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants