We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6e9651e commit 4bd7e62Copy full SHA for 4bd7e62
pandas/tests/indexes/multi/test_indexing.py
@@ -525,3 +525,21 @@ def test_slice_locs_with_missing_value(index_arr, expected, start_idx, end_idx):
525
idx = MultiIndex.from_arrays(index_arr)
526
result = idx.slice_locs(start=start_idx, end=end_idx)
527
assert result == expected
528
+
529
530
+def test_multiindex_loc_order():
531
+ # GH 22797
532
+ # Try to respect order of keys given for MultiIndex.loc
533
+ df = pd.DataFrame(
534
+ np.arange(12).reshape((4, 3)),
535
+ index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
536
+ columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
537
+ )
538
539
+ res = df.loc[["b", "a"], :]
540
+ exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
541
+ tm.assert_index_equal(res.index, exp_index)
542
543
+ res = df.loc[(["b", "a"], [2, 1]), :]
544
+ exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
545
0 commit comments