Skip to content

ENH: sort=bool keyword argument for index.difference #17839

Closed
@mcocdawc

Description

@mcocdawc

I often want to remove certain elements from an index while retaining the original ordering of the index. For this reason a sort keyword in the index.difference method would be required:

In: index = pd.Index([0, 1, 2, 4, 3])
In: index.difference({1, 2})
Out: Int64Index([0, 3, 4], dtype='int64')
# It would be cool to have instead
In: index.difference({1, 2}, sort=False)
Out: Int64Index([0, 4, 3], dtype='int64')

I think that this usecase appears frequently and setting the default to sort=True doesn't affect existing code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancementsetopsunion, intersection, difference, symmetric_difference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions