Skip to content

Commit

Permalink
add degenerate test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Mar 25, 2017
1 parent 9955590 commit cf02fcf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pandas.core.index import Index, MultiIndex
from pandas import Panel, DataFrame, Series, notnull, isnull, Timestamp

from pandas.core.common import UnsortedIndexError
from pandas.types.common import is_float_dtype, is_integer_dtype
import pandas.core.common as com
import pandas.util.testing as tm
Expand Down Expand Up @@ -2612,3 +2613,23 @@ def my_func(group):
names=['letter', 'size', None])

tm.assert_index_equal(result.index, expected)

def test_sort_non_lexsorted(self):
# degenerate case where we sort but don't
# have a satisfying result :<

idx = MultiIndex([['A', 'B', 'C'],
['c', 'b', 'a']],
[[0, 1, 2, 0, 1, 2],
[0, 2, 1, 1, 0, 2]])

df = DataFrame({'col': range(len(idx))}, index=idx)
assert df.index.is_lexsorted() is False
assert df.index.is_monotonic is False

result = df.sort_index()
assert result.index.is_lexsorted() is False
assert result.index.is_monotonic is True

with pytest.raises(UnsortedIndexError):
result.loc[pd.IndexSlice['B':'C', 'a':'c'], :]

0 comments on commit cf02fcf

Please sign in to comment.