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