-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Harmonize returned multi-indexed indexes when applying concat
along new dimension
#6889
Harmonize returned multi-indexed indexes when applying concat
along new dimension
#6889
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FabianHofmann for the #6881 issue report and for the fix, that makes a lot of sense! It will also fix the general case of any custom (non-pandas) multi-coordinate index with one of the names matching a dimension name.
I left a minor suggestion below.
Co-authored-by: Benoit Bovy <[email protected]>
Thanks @benbovy¸ glad that the proposed fix can help here! |
@benbovy I applied your suggestion (+ a small fix) and merged with the up to date main branch. All tests pass. |
LGTM, thanks @FabianHofmann! Could you update |
@benbovy done :) |
Co-authored-by: Benoit Bovy <[email protected]>
All good, thanks @FabianHofmann ! |
Great, thanks for the nice review @benbovy |
In the current implementation, the
concat
function does not ensure that the indexes that belong to the sameMultiIndex
relate to the sameMultiIndex
object inDataset.indexes
when concatenating along a new dimension. This becomes a problem as soon as the returned dataset needs to be aligned (for broadcasting, reindexing etc.), see #6881 for example. As far as I understand, this bug was introduced in #5692 following the idea that theconcat
function should disentangle indexes and dimensions.It can be fixed by not removing the index name from the list of indexes which should be merged, see
xarray/xarray/core/concat.py
Line 493 in 9050a8b
dim_names
. Instead of removing all dimension names from this list, I suggest to only remove unlabeled dimensions from this list.