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: Add ignore_index to sort_index #30578

Merged

Conversation

charlesdong1991
Copy link
Member

@charlesdong1991 charlesdong1991 commented Dec 31, 2019

@jreback
I just looked back at #30114 and found out that i overlooked to add ignore_index to sort_index, and this might be the reason this issue is still left open. I added this to sort_index to close this issue.

pandas/core/frame.py Outdated Show resolved Hide resolved
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @charlesdong1991 for the PR.

pandas/tests/series/methods/test_sort_index.py Outdated Show resolved Hide resolved
sr = Series(original_list)
expected = Series(sorted_list, index=output_index)

# Test when inplace is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can inplace be parameterised easily

Copy link
Member Author

@charlesdong1991 charlesdong1991 Dec 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emm, i think in this case, if using parameterization, might not look very clean and less readable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be parametrized - what do you think makes it less readable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok with trying parameterize as a followup, as for .sort_values and .duplicated these tests look very much like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emm, okay! i thought with inplace being Ture, we do not need to do something like df = df.sort_index(inplace=True), but False needs to be like this, and testing object will be different, one is testing if original changes, another is to test if assigned new df is changed.

Sorry to bring up discussion here, it definitely can be parametrized, was just my preference on such case. I will parametrize all three methods in the follow-up PR for sure!

pandas/tests/series/methods/test_sort_index.py Outdated Show resolved Hide resolved
pandas/core/series.py Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
@simonjayhawkins simonjayhawkins added API Design Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Dec 31, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally good - a few comments

({"A": [1, 2, 3]}, {"A": [3, 2, 1]}, False, True, [0, 1, 2]),
({"A": [1, 2, 3]}, {"A": [1, 2, 3]}, True, True, [0, 1, 2]),
({"A": [1, 2, 3]}, {"A": [3, 2, 1]}, False, False, [2, 1, 0]),
({"A": [1, 2, 3]}, {"A": [1, 2, 3]}, True, False, [0, 1, 2]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but can you use a non-default index as part of the expectation? Right now the parametrization can't disambiguate between the default index and ignore_index argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! changed!

sr = Series(original_list)
expected = Series(sorted_list, index=output_index)

# Test when inplace is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be parametrized - what do you think makes it less readable?

pandas/core/series.py Outdated Show resolved Hide resolved
sr = Series(original_list)
expected = Series(sorted_list, index=output_index)

# Test when inplace is False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok with trying parameterize as a followup, as for .sort_values and .duplicated these tests look very much like this.

@jreback jreback added this to the 1.0 milestone Jan 3, 2020
pandas/core/series.py Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/series.py Outdated Show resolved Hide resolved
@WillAyd
Copy link
Member

WillAyd commented Jan 3, 2020

Lgtm

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. if you can followup with a parameterization / deduplication of tests PR would be great

@jreback jreback merged commit 43e251d into pandas-dev:master Jan 3, 2020
@charlesdong1991
Copy link
Member Author

thanks! will do @jreback

@stonereese
Copy link

Hi,ignore_index = True works just fine and meets my expectations when axis =0,but when axis = 1, the number of index after reset using ignore = Ture is equal to the number of columns instead of the original index number,like new_index = range(len(columns)).
Is this a bug, or where am I going wrong?
THKS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: add ignore_index keyword to .sort_* & .drop_duplicates
6 participants