Skip to content

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

Closed
@auderson

Description

@auderson
Contributor
  • 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

Activity

added
Needs TriageIssue that has not been reviewed by a pandas team member
on Jan 7, 2021
vangorade

vangorade commented on Jan 7, 2021

@vangorade
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

jreback commented on Jan 7, 2021

@jreback
Contributor

was fixed by #38681

added this to the No action milestone on Jan 7, 2021
added
ReshapingConcat, Merge/Join, Stack/Unstack, Explode
on Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDuplicate ReportDuplicate issue or pull requestNeeds TriageIssue that has not been reviewed by a pandas team memberReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jreback@auderson@vangorade

        Issue actions

          BUG: DataFrame.rank() wrong result for inf · Issue #39015 · pandas-dev/pandas