We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 966757f commit a31d603Copy full SHA for a31d603
pandas/tests/indexes/multi/test_indexing.py
@@ -437,3 +437,21 @@ def test_timestamp_multiindex_indexer():
437
)
438
should_be = pd.Series(data=np.arange(24, len(qidx) + 24), index=qidx, name="foo")
439
tm.assert_series_equal(result, should_be)
440
+
441
442
+def test_multiindex_loc_order():
443
+ # GH 22797
444
+ # Try to respect order of keys given for MultiIndex.loc
445
+ df = pd.DataFrame(
446
+ np.arange(12).reshape((4, 3)),
447
+ index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
448
+ columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
449
+ )
450
451
+ res = df.loc[["b", "a"], :]
452
+ exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
453
+ tm.assert_index_equal(res.index, exp_index)
454
455
+ res = df.loc[(["b", "a"], [2, 1]), :]
456
+ exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
457
0 commit comments