Fixes #11099 : Indexes lost upon .swap_dims() call
#11100
+23
−1
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.