Repository: pandas-dev/pandas
Pull request: Test added: uint64 multicolumn sort
- [x] closes #9918
- [x] tests added / passed
- [x] passes `black pandas`
- [x] added test test_sort_multicolumn_uint64

Problem statement:
uint64 multicolumn sort
Sorting uint64 columns is incorrect when sorting on multiple columns:

``` python
>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame({'a': pd.Series([18446637057563306014, 1162265347240853609]), 'b': pd.Series([1, 2])})
>>> df['a'] = df['a'].astype(np.uint64)
>>> df.sort(['a', 'b'])['a']
0    18446637057563306014
1     1162265347240853609
Name: a, dtype: uint64
>>> df.sort(['a'])['a']
1     1162265347240853609
0    18446637057563306014
Name: a, dtype: uint64
>>> pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.32-40.87-jump1.03
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.15.2
nose: 1.3.4
Cython: None
numpy: 1.9.1
scipy: 0.15.1
statsmodels: None
IPython: 2.3.1
sphinx: None
patsy: None
dateutil: 2.4.0
pytz: 2014.10
bottleneck: None
tables: None
numexpr: 2.4
matplotlib: 1.4.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None
```

Hints from issue discussion:
`uint64` not super-well supported; marked as a bug

This looks to work on master. Could use a test:

```
In [59]: >>> df = pd.DataFrame({'a': pd.Series([18446637057563306014, 1162265347240853609]), 'b': pd.Series([1, 2])})
    ...: >>> df['a'] = df['a'].astype(np.uint64)
    ...: >>> df.sort_values(['a', 'b'])['a']
Out[59]:
1     1162265347240853609
0    18446637057563306014
Name: a, dtype: uint64

In [60]: df.sort_values(['a'])['a']
Out[60]:
1     1162265347240853609
0    18446637057563306014
Name: a, dtype: uint64

In [61]: pd.__version__
Out[61]: '0.26.0.dev0+593.g9d45934af'
```

Commit message: GH9918
Added test

Patch to review:
diff --git a/pandas/tests/frame/test_sorting.py b/pandas/tests/frame/test_sorting.py
index 9ea78b974fcbb..66899d9824315 100644
--- a/pandas/tests/frame/test_sorting.py
+++ b/pandas/tests/frame/test_sorting.py
@@ -735,3 +735,25 @@ def test_sort_index_na_position_with_categories_raises(self):
 
         with pytest.raises(ValueError):
             df.sort_values(by="c", ascending=False, na_position="bad_position")
+
+    def test_sort_multicolumn_uint64(self):
+        # GH9918
+        # uint64 multicolumn sort
+
+        df = pd.DataFrame(
+            {
+                "a": pd.Series([18446637057563306014, 1162265347240853609]),
+                "b": pd.Series([1, 2]),
+            }
+        )
+        df["a"] = df["a"].astype(np.uint64)
+        result = df.sort_values(["a", "b"]).reset_index(drop=True)
+
+        expected = pd.DataFrame(
+            {
+                "a": pd.Series([1162265347240853609, 18446637057563306014]),
+                "b": pd.Series([2, 1]),
+            }
+        )
+
+        tm.assert_frame_equal(result, expected)


Code review comments:
diff_hunk: @@ -735,3 +735,25 @@ def test_sort_index_na_position_with_categories_raises(self):
 
         with pytest.raises(ValueError):
             df.sort_values(by="c", ascending=False, na_position="bad_position")
+
+    def test_sort_multicolumn_uint64(self):
+        # GH9918
+        # uint64 multicolumn sort
+
+        df = pd.DataFrame(
+            {
+                "a": pd.Series([18446637057563306014, 1162265347240853609]),
+                "b": pd.Series([1, 2]),
+            }
+        )
+        df["a"] = df["a"].astype(np.uint64)
+        result = df.sort_values(["a", "b"]).reset_index(drop=True)
path: pandas/tests/frame/test_sorting.py
text: @user1:
Instead of `.reset_index(drop=True)`, can you assign the correct expected index to `expected` (`...index=pd.Index([1, 0])`)