Skip to content

Commit 58d8782

Browse files
Matias Heikkilämahepe
authored andcommitted
TST: Test sorting levels not aligned with index (#25775)
1 parent 6d2398a commit 58d8782

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/frame/test_sorting.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ 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
232+
pd.np.random.seed(0)
233+
df1 = (DataFrame(pd.np.random.rand(10, 5),
234+
columns=['a', 'b', 'c', 'd', 'e'])
235+
.assign(b=lambda df: (df.b * 10).astype(int)))
236+
df2 = df1.set_index(['a', 'b', 'c']).sort_index(
237+
axis=0, level=['b', 'a'])
238+
expected = DataFrame(df2.index.to_frame()[['a', 'b']].values,
239+
columns=['a', 'b']).assign(
240+
b=lambda df: (df.b).astype(int))
241+
result = df1.sort_values(by=['b', 'a']).reset_index()[['a', 'b']]
242+
tm.assert_frame_equal(result, expected)
243+
230244
def test_stable_categorial(self):
231245
# GH 16793
232246
df = DataFrame({

0 commit comments

Comments
 (0)