Skip to content

Commit 3c4ca22

Browse files
committed
add degenerate test case
1 parent 269cb3b commit 3c4ca22

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/test_multilevel.py

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.core.index import Index, MultiIndex
1212
from pandas import Panel, DataFrame, Series, notnull, isnull, Timestamp
1313

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

26142615
tm.assert_index_equal(result.index, expected)
2616+
2617+
def test_sort_non_lexsorted(self):
2618+
# degenerate case where we sort but don't
2619+
# have a satisfying result :<
2620+
2621+
idx = MultiIndex([['A', 'B', 'C'],
2622+
['c', 'b', 'a']],
2623+
[[0, 1, 2, 0, 1, 2],
2624+
[0, 2, 1, 1, 0, 2]])
2625+
2626+
df = DataFrame({'col': range(len(idx))}, index=idx)
2627+
assert df.index.is_lexsorted() is False
2628+
assert df.index.is_monotonic is False
2629+
2630+
result = df.sort_index()
2631+
assert result.index.is_lexsorted() is False
2632+
assert result.index.is_monotonic is True
2633+
2634+
with pytest.raises(UnsortedIndexError):
2635+
result.loc[pd.IndexSlice['B':'C', 'a':'c'], :]

0 commit comments

Comments
 (0)