[BUG] Dataframe.rank() produces wrong results for float columns · Issue #32593 · pandas-dev/pandas (original) (raw)

Code to reproduce the issue

import numpy as np import pandas as pd

indx = np.array([5, 4, 3, 2, 1, 6, 7, 8, 9, 10]) col1 = np.array([5, 4, 3, 5, 8, 5, 2, 1, 6, 6]) col2 = np.array([5, 4, np.nan, 5, 8, 5, np.inf, np.nan, 6, -np.inf]) pdf = pd.DataFrame(index=indx) pdf["col1"] = col1.astype('f8') pdf["col2"] = col2.astype('f8')

ranked_df = pdf.rank()

ranked_series = pd.DataFrame(index=indx) ranked_series["col1"] = pdf["col1"].rank() ranked_series["col2"] = pdf["col2"].rank()

print(ranked_df.equals(ranked_series)) #False

Problem description

Dataframe rank produces individual column ranks. But when float column is present, individual ranks are not equal to Dataframe rank.

Expected Output

True

Output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-72-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.0.0.post20200309
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None