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

rank() on a Series of just 1 null assigns rank=1 to the null value. #18243

Closed
2 tasks done
rgiaccio opened this issue Aug 16, 2024 · 2 comments · Fixed by #18252
Closed
2 tasks done

rank() on a Series of just 1 null assigns rank=1 to the null value. #18243

rgiaccio opened this issue Aug 16, 2024 · 2 comments · Fixed by #18252
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@rgiaccio
Copy link

rgiaccio commented Aug 16, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

print(pl.Series([]).rank().to_list())
print(pl.Series([None]).rank().to_list())
print(pl.Series([None, None]).rank().to_list())
print(pl.Series([None, None, None]).rank().to_list())

Output:

[]
[1.0]
[None, None]
[None, None, None]

Log output

No response

Issue description

Ranks of series [null] should not be [1.0] but [null], because the rank of null should be null.
This only happens with series of just 1 null. Ranking series with 0 or more than 1 null gives correct results.

This issue is a generalization of #17570

Expected behavior

import polars as pl

print(pl.Series([]).rank().to_list())
print(pl.Series([None]).rank().to_list())
print(pl.Series([None, None]).rank().to_list())
print(pl.Series([None, None, None]).rank().to_list())

Output:

[]
[None]
[None, None]
[None, None, None]

Installed versions

--------Version info---------
Polars:               1.5.0
Index type:           UInt32
Platform:             macOS-14.5-x86_64-i386-64bit
Python:               3.11.4 (main, Oct  4 2023, 02:12:57) [Clang 15.0.0 (clang-1500.0.40.1)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         1.6.0
numpy:                2.0.1
openpyxl:             <not installed>
pandas:               <not installed>
pyarrow:              <not installed>
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@rgiaccio rgiaccio added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 16, 2024
@rgiaccio rgiaccio changed the title rank() on a Series of length 1 assigns rank=1 to the null value. rank() on a Series of just 1 null assigns rank=1 to the null value. Aug 16, 2024
@ritchie46
Copy link
Member

Thanks for the simplification!

@rgiaccio
Copy link
Author

Thanks for the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants