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: rank() should return 0 indexed values for consistency #46964

Open
lcrmorin opened this issue May 7, 2022 · 2 comments
Open

ENH: rank() should return 0 indexed values for consistency #46964

lcrmorin opened this issue May 7, 2022 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API Design Enhancement Needs Discussion Requires discussion from core team before further action

Comments

@lcrmorin
Copy link

lcrmorin commented May 7, 2022

Is your feature request related to a problem?

I am using pandas for a ranking task. The default series.rank() method returns ranks that starts at 1 instead of 0. Thus breaking some unexpected stuff if assuming 0 indexed result, as is common in python.

Describe the solution you'd like

Series.rank() should return 0 indexed values.

API breaking implications

Breaking existing code that rely on 1-indexed ranks

Describe alternatives you've considered

Shifting the output by -1 is the obvious solution, but feels weird.

@lcrmorin lcrmorin added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels May 7, 2022
@mzeitlin11
Copy link
Member

Thanks for the request @lcrmorin.

-1 here since this would cause a bunch of churn (deprecation warnings for all users of rank about the changing result is brutal, so would probably have to add another arg instead) and the alternative is an easy way to achieve this behavior.

I'm also not sure a 0-indexed result is better - rank is not necessarily meant to be used as an indexing tool - the default method is average so users often end up with non-whole number values anyway. Th indexing use case sounds more like what argsort would do.

@attack68
Copy link
Contributor

argsort sounds like the way to go here. Although the documentation should probably link to this. Also argsort needs fixing -> #42090

@simonjayhawkins simonjayhawkins added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API Design and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 17, 2022
@mroeschke mroeschke added the Needs Discussion Requires discussion from core team before further action label May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API Design Enhancement Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

5 participants