Skip to content

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

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

Closed
mcocdawc opened this issue Oct 10, 2017 · 8 comments
Closed

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

mcocdawc opened this issue Oct 10, 2017 · 8 comments
Labels
Enhancement setops union, intersection, difference, symmetric_difference

Comments

@mcocdawc
Copy link
Contributor

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.

@TomAugspurger
Copy link
Contributor

+1 for this (and all the other set-ops).

@mcocdawc are you interested in submitting a pull request?

@TomAugspurger TomAugspurger added this to the Next Major Release milestone Oct 10, 2017
@mcocdawc
Copy link
Contributor Author

Interested definetely, but I don't have time for it now. :(

@Giftlin
Copy link
Contributor

Giftlin commented Oct 14, 2017

I am interested in submitting a pull request. Can I?

@jreback
Copy link
Contributor

jreback commented Oct 14, 2017

sure

@jreback
Copy link
Contributor

jreback commented Oct 14, 2017

this needs to be done for all Index set methods (union, difference, intersect) and tested systematically. Further there are several related issues here:

xref #17010, #17378, #17376

Giftlin added a commit to Giftlin/pandas that referenced this issue Oct 14, 2017
Giftlin added a commit to Giftlin/pandas that referenced this issue Oct 14, 2017
Giftlin added a commit to Giftlin/pandas that referenced this issue Oct 14, 2017
Giftlin added a commit to Giftlin/pandas that referenced this issue Oct 14, 2017
ENH: sort=bool keyword argument for index.difference  pandas-dev#17839
@Licht-T
Copy link
Contributor

Licht-T commented Oct 15, 2017

Oops, I am almost done patching in all Index classes.
difference and intersection are okay, but I have a question do we really need sort option in union?

@Licht-T
Copy link
Contributor

Licht-T commented Oct 15, 2017

If the sort option needed in union, how do we define the unsorted union order?
idx1.join(idx2.difference(idx1))?

@jbrockmendel
Copy link
Member

The set methods all have sort keyword. Closing a complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement setops union, intersection, difference, symmetric_difference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants