Skip to content
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

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

Open
mcocdawc opened this issue Oct 10, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@mcocdawc
Copy link
Contributor

commented Oct 10, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2017

+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

This comment has been minimized.

Copy link
Contributor Author

commented Oct 13, 2017

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

@Giftlin

This comment has been minimized.

Copy link
Contributor

commented Oct 14, 2017

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

@jreback

This comment has been minimized.

Copy link
Contributor

commented Oct 14, 2017

sure

@jreback

This comment has been minimized.

Copy link
Contributor

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

Merge pull request #14 from Giftlin/patch-4
ENH: sort=bool keyword argument for index.difference  pandas-dev#17839
@Licht-T

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.