Fixes #11099 : Indexes lost upon .swap_dims() call#11100
Open
Reshief wants to merge 3 commits intopydata:mainfrom
Open
Fixes #11099 : Indexes lost upon .swap_dims() call#11100Reshief wants to merge 3 commits intopydata:mainfrom
.swap_dims() call#11100Reshief wants to merge 3 commits intopydata:mainfrom
Conversation
…st upon `ds.swap_dims()` call
Passes both new and old tests now
Contributor
|
Thanks, seems OK to me. If you want fix some related bugs there are a few documented here: xarray/properties/test_index_manipulation.py Lines 244 to 249 in 49ec516 Removing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Indexes of non-dimension variable names being lost upon
ds.swap_dims()callThis is a small patch to fix the issue underlying #11099 .
Due to Indexes only being copies in
Dataset.swap_dims()for variables whose names are dimensions before the call, indexes for multi-index variables and probably also for other indexed variables are lost in the resulting dataset.This can lead to issues further down the line like
.attrsbeing lost (as I personally encountered).The patch copies over index variables and indexes of variables that do not lose dimension-status, making the function
.swap_dims()behave consistently with.rename_dims()if the target name is not used.I added a short test to make sure that the patch fixes the reported problem in #11099 and ran the entire test suite to make sure that no unintended changes to overall behavior that has previously been tested would be observed.