Skip to content

Skip identical indexes with non-unique values in align? #956

Closed
@shoyer

Description

@shoyer

Currently, when objects with with non-unique (duplicated) values in one of their indexes are passed to align, an error surfaces from pandas:
InvalidIndexError: Reindexing only valid with uniquely valued Index objects

We could certainly give a more informative error here (see this complaint on StackOverflow), but a bigger issue is that this probably isn't strictly necessary. Instead, we could skip indexes for alignment if they are already equal. This is slightly less principled (a non-unique index may indicate something has gone wrong), but certainly more convenient and more inline with how pandas works (e.g., it even allows arithmetic between objects with non-unique indexes, which I believe does not work currently in xarray).

Currently, we do this as a special case when merging arrays and exactly one has labels (see _align_for_merge in #950). But we could probably do this in general, either by default or with a flag to enable it (or turn it off). This would then propagate to every xarray operation that uses align under the covers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions