Skip to content

ENH: add ignore_index to nlargest and nsmallest method #43994

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
erfannariman opened this issue Oct 12, 2021 · 6 comments
Closed

ENH: add ignore_index to nlargest and nsmallest method #43994

erfannariman opened this issue Oct 12, 2021 · 6 comments
Labels
API - Consistency Internal Consistency of API/Behavior Enhancement Needs Discussion Requires discussion from core team before further action

Comments

@erfannariman
Copy link
Member

Describe the solution you'd like

Just like other methods where we select a subset or reorder, we have a ignore_index argument, to reset the index.

In [1]: import pandas as pd

In [2]: df = pd.DataFrame({"A": range(10), "B": range(10, 20)})

In [3]: df.nlargest(n=2, columns="A")
Out[3]: 
   A   B
9  9  19
8  8  18

In [4]: df.nlargest(n=2, columns="A", ignore_index=True)
Out[3]: 
   A   B
0  9  19
1  8  18
@erfannariman erfannariman added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 12, 2021
@alimcmaster1
Copy link
Member

take

Thanks for the issue.

Lets get a +1 from a core developer before making an API changes. Saves you work if its not something that will be merged.

Not sure it makes sense to add this to just nlargest and nsmallest seems a bit selective.

@erfannariman erfannariman removed their assignment Oct 13, 2021
@erfannariman
Copy link
Member Author

Not sure it makes sense to add this to just nlargest and nsmallest seems a bit selective.

The reason I opened this issue is that we have ignore_index in drop_duplicates, sort_values, explode, sample and probably others as well.

@lithomas1 lithomas1 added the API - Consistency Internal Consistency of API/Behavior label Oct 15, 2021
@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 16, 2021
@mroeschke
Copy link
Member

My 2 cents; I'd personally prefer ignore_index to be removed in methods since it's equivalent to chaining reset_index(drop=True) correct?

@erfannariman
Copy link
Member Author

My 2 cents; I'd personally prefer ignore_index to be removed in methods since it's equivalent to chaining reset_index(drop=True) correct?

I am not sure if that is consistent with the API design, since then you could also argue about as_index argument in groupby since you can achieve the same by chaining reset_index.

@mroeschke
Copy link
Member

I am not sure if that is consistent with the API design, since then you could also argue about as_index argument in groupby since you can achieve the same by chaining reset_index.

xref #35860

@erfannariman
Copy link
Member Author

I see, will close this for now, since there are discussions about deprecation and it looks it leans more in favour of actually doing so. So adding ignore_index does not make sense in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Enhancement Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

4 participants