ENH: sort=bool keyword argument for index.difference · Issue #17839 · pandas-dev/pandas (original) (raw)
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.