@@ -438,6 +438,7 @@ def test_timestamp_multiindex_indexer():
438
438
)
439
439
should_be = pd .Series (data = np .arange (24 , len (qidx ) + 24 ), index = qidx , name = "foo" )
440
440
tm .assert_series_equal (result , should_be )
441
+ < << << << HEAD
441
442
442
443
443
444
def test_get_loc_with_values_including_missing_values ():
@@ -526,3 +527,21 @@ def test_slice_locs_with_missing_value(index_arr, expected, start_idx, end_idx):
526
527
idx = MultiIndex .from_arrays (index_arr )
527
528
result = idx .slice_locs (start = start_idx , end = end_idx )
528
529
assert result == expected
530
+
531
+
532
+ def test_multiindex_loc_order ():
533
+ # GH 22797
534
+ # Try to respect order of keys given for MultiIndex.loc
535
+ df = pd .DataFrame (
536
+ np .arange (12 ).reshape ((4 , 3 )),
537
+ index = [["a" , "a" , "b" , "b" ], [1 , 2 , 1 , 2 ]],
538
+ columns = [["Ohio" , "Ohio" , "Colorado" ], ["Green" , "Red" , "Green" ]],
539
+ )
540
+
541
+ res = df .loc [["b" , "a" ], :]
542
+ exp_index = pd .MultiIndex .from_arrays ([["b" , "b" , "a" , "a" ], [1 , 2 , 1 , 2 ]])
543
+ tm .assert_index_equal (res .index , exp_index )
544
+
545
+ res = df .loc [(["b" , "a" ], [2 , 1 ]), :]
546
+ exp_index = pd .MultiIndex .from_arrays ([["b" , "b" , "a" , "a" ], [2 , 1 , 2 , 1 ]])
547
+ tm .assert_index_equal (res .index , exp_index )
0 commit comments