@@ -492,6 +492,44 @@ def test_loc_axis_arguments(self):
492
492
with pytest .raises (ValueError ):
493
493
df .loc (axis = "foo" )[:, :, ["C1" , "C3" ]]
494
494
495
+ def test_loc_axis_single_level_multi_col_indexing_multiindex_col_df (self ):
496
+
497
+ # GH29519
498
+ df = pd .DataFrame (
499
+ np .arange (27 ).reshape (3 , 9 ),
500
+ columns = pd .MultiIndex .from_product (
501
+ [["a1" , "a2" , "a3" ], ["b1" , "b2" , "b3" ]]
502
+ ),
503
+ )
504
+ result = df .loc (axis = 1 )["a1" :"a2" ]
505
+ expected = df .iloc [:, :- 3 ]
506
+
507
+ tm .assert_frame_equal (result , expected )
508
+
509
+ def test_loc_axis_single_level_single_col_indexing_multiindex_col_df (self ):
510
+
511
+ # GH29519
512
+ df = pd .DataFrame (
513
+ np .arange (27 ).reshape (3 , 9 ),
514
+ columns = pd .MultiIndex .from_product (
515
+ [["a1" , "a2" , "a3" ], ["b1" , "b2" , "b3" ]]
516
+ ),
517
+ )
518
+ result = df .loc (axis = 1 )["a1" ]
519
+ expected = df .iloc [:, :3 ]
520
+ expected .columns = ["b1" , "b2" , "b3" ]
521
+
522
+ tm .assert_frame_equal (result , expected )
523
+
524
+ def test_loc_ax_single_level_indexer_simple_df (self ):
525
+
526
+ # GH29519
527
+ # test single level indexing on single index column data frame
528
+ df = pd .DataFrame (np .arange (9 ).reshape (3 , 3 ), columns = ["a" , "b" , "c" ])
529
+ result = df .loc (axis = 1 )["a" ]
530
+ expected = pd .Series (np .array ([0 , 3 , 6 ]), name = "a" )
531
+ tm .assert_series_equal (result , expected )
532
+
495
533
def test_per_axis_per_level_setitem (self ):
496
534
497
535
# test index maker
0 commit comments