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

swap_dims does not propagate indexes properly #8914

Open
5 tasks
dcherian opened this issue Apr 5, 2024 · 0 comments
Open
5 tasks

swap_dims does not propagate indexes properly #8914

dcherian opened this issue Apr 5, 2024 · 0 comments

Comments

@dcherian
Copy link
Contributor

dcherian commented Apr 5, 2024

What happened?

Found by hypothesis

import xarray as xr
import numpy as np

var = xr.Variable(dims="2", data=np.array(['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:00.000000002', '1970-01-01T00:00:00.000000001'], dtype='datetime64[ns]'))
var1 = xr.Variable(data=np.array([0], dtype=np.uint32), dims=['1'], attrs={})

state = xr.Dataset()
state['2'] = var
state = state.stack({"0": ["2"]})
state['1'] = var1
state['1_'] = var1#.copy(deep=True)
state = state.swap_dims({"1": "1_"})
xr.testing.assertions._assert_internal_invariants(state, False)

This swaps simple pandas indexed dims, but the multi-index that is in the dataset and not affected by the swap_dims op ends up broken.

cc @benbovy

What did you expect to happen?

No response

Minimal Complete Verifiable Example

No response

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

No response

Anything else we need to know?

No response

Environment

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

No branches or pull requests

1 participant