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

BUG: sorting with large float and multiple columns incorrect #14922

Closed
uweschmitt opened this issue Dec 19, 2016 · 5 comments
Closed

BUG: sorting with large float and multiple columns incorrect #14922

uweschmitt opened this issue Dec 19, 2016 · 5 comments
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@uweschmitt
Copy link
Contributor

uweschmitt commented Dec 19, 2016

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

@jreback
Copy link
Contributor

jreback commented Dec 19, 2016

pls show a copy-pastable example.

@jreback
Copy link
Contributor

jreback commented Dec 19, 2016

yes, pls update the top message. idea is that the repro is just a copy-paste

@jreback
Copy link
Contributor

jreback commented Dec 19, 2016

also pls try to make a more useful than 'not working' (e.g. what is the problem)

@uweschmitt
Copy link
Contributor Author

Ok now ? I was in a hurry...

@jreback
Copy link
Contributor

jreback commented Dec 19, 2016

ok, confirmed on master. ty. if you'd like to digin and see what's happening would be great.

@jreback jreback added Bug Difficulty Intermediate Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Dec 19, 2016
@jreback jreback added this to the Next Major Release milestone Dec 19, 2016
@jreback jreback changed the title sort_values not working as exepected BUG: sorting with large float and multiple columns incorrect Dec 19, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 22, 2016
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
closes pandas-dev#14922

Having the `int` equivalent of `NaT` in an `int64` column caused wrong
sorting because this special value was considered as "missing value".

Author: Uwe <uwe.schmitt@id.ethz.ch>

Closes pandas-dev#14944 from uweschmitt/fix-gh-14922 and squashes the following commits:

c244438 [Uwe] further cleanup tests
4f28026 [Uwe] fixed typo in whatsnew/v0.20.0.txt
60cca5d [Uwe] add fix of GH14922 to release notes for 0.20.0
04dcbe8 [Uwe] further test cleanup
21e610c [Uwe] extended tests + minor cleanup
358a31e [Uwe] Merge branch 'fix-pandas-devgh-14922' of github.com:uweschmitt/pandas into fix-pandas-devgh-14922
03699c6 [Uwe] Fix GH 14922
1afdbb8 [Uwe] Fix GH 14922
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants