Description
Code Sample, a copy-pastable example if possible
import pandas as pd
int_values = (2, -9223372036854775808)
float_values = (2.0, -1.797693e308)
df = pd.DataFrame(dict(int=int_values,
float=float_values), columns=("int", "float"))
print("df")
print(df)
print()
print("sort by int")
print(df.sort_values(["int"]))
print()
print("sort by float")
print(df.sort_values(["float"]))
print()
print("sort by (int, float)")
print(df.sort_values(["int", "float"]))
produces
$ python wrong.py
df
int float
0 2 2.000000e+00
1 -9223372036854775808 -1.797693e+308
sort by int
int float
1 -9223372036854775808 -1.797693e+308
0 2 2.000000e+00
sort by float
int float
1 -9223372036854775808 -1.797693e+308
0 2 2.000000e+00
sort by (int, float)
int float
0 2 2.000000e+00
1 -9223372036854775808 -1.797693e+308
As you can see the first two calls (only sorting by int
or by float
) sort correctly whereas df.sort_values(["int", "float"])
does not seem to sort at all. Row with index 1
should appear first, and then row with index 0
.
Using pandas 0.17.0
I get the correct result:
int float
1 -9223372036854775808 -1.797693e+308
0 2 2.000000e+00
This issue was discussed at http://stackoverflow.com/questions/41225286/sort-by-broken-in-pandas-0-18-0
Output of pd.show_versions()
INSTALLED VERSIONS [1/193]
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.19.1
nose: None
pip: 7.1.2
setuptools: 18.2
Cython: None
numpy: 1.10.4
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None