Skip to content

Index.intersection changed behavior to sort by default in pandas 0.24 #24959

Closed
@shoyer

Description

@shoyer

Prior to #24521 (i.e., for pandas 0.23 and earlier), pandas.Index.intersection would not sort values:

# pandas 0.23.3
In [21]: pd.Index(['c', 'b', 'a']).intersection(['b', 'a'])
Out[21]: Index(['b', 'a'], dtype='object')

Now it does:

In [28]: pd.Index(['c', 'b', 'a']).intersection(['b', 'a'])
Out[28]: Index(['a', 'b'], dtype='object')

This turned up in a failure in xarray's test suite (not a real bug): pydata/xarray#2717

It's fine to change this for consistency, but a deprecation cycle would probably make sense so users aren't surprised by the behavior of their code changing, e.g., we could default to sort=None and issue a FutureWarning for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDeprecateFunctionality to remove in pandasIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions