Skip to content

Commit 8ef9a63

Browse files
mahepejreback
authored andcommitted
TST: Test sorting levels not aligned with index (#25775) (#26492)
1 parent 6ce7fc7 commit 8ef9a63

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/frame/test_sorting.py

+12
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ def test_stable_descending_multicolumn_sort(self):
227227
kind='mergesort')
228228
assert_frame_equal(sorted_df, expected)
229229

230+
def test_sort_multi_index(self):
231+
# GH 25775, testing that sorting by index works with a multi-index.
232+
df = DataFrame({'a': [3, 1, 2], 'b': [0, 0, 0],
233+
'c': [0, 1, 2], 'd': list('abc')})
234+
result = df.set_index(list('abc')).sort_index(level=list('ba'))
235+
236+
expected = DataFrame({'a': [1, 2, 3], 'b': [0, 0, 0],
237+
'c': [1, 2, 0], 'd': list('bca')})
238+
expected = expected.set_index(list('abc'))
239+
240+
tm.assert_frame_equal(result, expected)
241+
230242
def test_stable_categorial(self):
231243
# GH 16793
232244
df = DataFrame({

0 commit comments

Comments
 (0)