Skip to content

reset multi-index to single index (level): coordinate not renamed #6989

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

Closed
4 tasks done
benbovy opened this issue Sep 5, 2022 · 0 comments · Fixed by #6992
Closed
4 tasks done

reset multi-index to single index (level): coordinate not renamed #6989

benbovy opened this issue Sep 5, 2022 · 0 comments · Fixed by #6992

Comments

@benbovy
Copy link
Member

benbovy commented Sep 5, 2022

What happened?

Resetting a multi-index to a single level (i.e., a single index) does not rename the remaining level coordinate to the dimension name.

What did you expect to happen?

While it is certainly more consistent not to rename the level coordinate here (since an index can be assigned to a non-dimension coordinate now), it breaks from the old behavior. I think it's better not introduce any breaking change. As discussed elsewhere, we might eventually want to deprecate reset_index in favor of drop_indexes (#6971).

Minimal Complete Verifiable Example

import pandas as pd
import xarray as xr

midx = pd.MultiIndex.from_product([["a", "b"], [1, 2]], names=("foo", "bar"))

ds = xr.Dataset(coords={"x": midx})
# <xarray.Dataset>
# Dimensions:  (x: 4)
# Coordinates:
#   * x        (x) object MultiIndex
#   * foo      (x) object 'a' 'a' 'b' 'b'
#   * bar      (x) int64 1 2 1 2
# Data variables:
#     *empty*

rds = ds.reset_index("foo")

# v2022.03.0
#
# <xarray.Dataset>
# Dimensions:  (x: 4)
# Coordinates:
#   * x        (x) int64 1 2 1 2
#     foo      (x) object 'a' 'a' 'b' 'b'
# Data variables:
#     *empty*

# v2022.06.0
# 
# <xarray.Dataset>
# Dimensions:  (x: 4)
# Coordinates:
#     foo      (x) object 'a' 'a' 'b' 'b'
#   * bar      (x) int64 1 2 1 2
# Dimensions without coordinates: x
# Data variables:
#     *empty*

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.

Relevant log output

No response

Anything else we need to know?

No response

Environment

@benbovy benbovy added bug needs triage Issue that has not been reviewed by xarray team member labels Sep 5, 2022
@benbovy benbovy self-assigned this Sep 5, 2022
@benbovy benbovy added topic-indexing regression and removed needs triage Issue that has not been reviewed by xarray team member labels Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant