Skip to content

BUG: DataFrame.rank() wrong result for inf #39015

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
2 of 3 tasks
auderson opened this issue Jan 7, 2021 · 2 comments
Closed
2 of 3 tasks

BUG: DataFrame.rank() wrong result for inf #39015

auderson opened this issue Jan 7, 2021 · 2 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Needs Triage Issue that has not been reviewed by a pandas team member Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@auderson
Copy link
Contributor

auderson commented Jan 7, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(3, 4))
df.iloc[0, 0] = np.inf

df
          0         1         2         3
0       inf -0.614812 -0.316211 -0.049311
1  1.254238 -0.082490 -0.199442 -0.373851
2 -1.440219  0.723572  0.028726 -0.904849

df.rank()
     0    1    2    3
0  NaN  1.0  1.0  3.0
1  2.0  2.0  2.0  2.0
2  1.0  3.0  3.0  1.0

df.iloc[0, 0] = -np.inf

df.rank()
     0    1    2    3
0  1.0  1.0  1.0  3.0
1  3.0  2.0  2.0  2.0
2  2.0  3.0  3.0  1.0

Problem description

as you can see, -inf and inf get different results.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-118-generic
Version : #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.2.0
numpy : 1.18.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.0.0.post20201207
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : 0.10.1
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: 0.9.0
bs4 : None
bottleneck : None
fsspec : 0.8.4
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0

@auderson auderson added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 7, 2021
@vangorade
Copy link
Contributor

Thanks @auderson for reporting issue.

master gives the expected output

>>> pd.__version__
'1.3.0.dev0+361.g23f2eb14c'   

>>> df = pd.DataFrame(np.random.randn(3, 4))
>>> df.iloc[0, 0] = np.inf

>>> df
          0         1         2         3
0       inf  1.644946  1.047380  1.661329
1  0.046478 -1.447429  0.137414  0.998330
2 -0.474645  0.735952 -0.234013 -0.230222

>>> df.rank()
     0    1    2    3
0  3.0  3.0  3.0  3.0
1  2.0  1.0  2.0  2.0
2  1.0  2.0  1.0  1.0

>>> df.iloc[0, 0] = -np.inf

>>>  df.rank()
     0    1    2    3
0  1.0  3.0  3.0  3.0
1  3.0  1.0  2.0  2.0
2  2.0  2.0  1.0  1.0

@jreback
Copy link
Contributor

jreback commented Jan 7, 2021

was fixed by #38681

@jreback jreback closed this as completed Jan 7, 2021
@jreback jreback added this to the No action milestone Jan 7, 2021
@jreback jreback added Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Needs Triage Issue that has not been reviewed by a pandas team member Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants