@@ -2422,22 +2422,30 @@ def test_repeat(self):
2422
2422
2423
2423
def test_iloc_mi (self ):
2424
2424
# GH 13797
2425
-
2426
- ind_nonLex = [
2427
- ['CC' , 'CC' , 'CC' , 'BB' , 'BB' ],
2428
- ['A' , 'B' , 'B' , 'a' , 'b' ]
2429
- ]
2430
-
2431
- strCol = pd .DataFrame (
2432
- ['fooA' , 'fooB' , 'fooC' , 'fooD' , 'fooE' ])
2433
-
2434
- dat = np .arange (1 , 26 ).reshape (5 , 5 )
2435
- df = pd .concat ([strCol , pd .DataFrame (dat )], axis = 1 )
2436
- df1 = pd .DataFrame (df .values , index = ind_nonLex )
2437
-
2438
- assert df1 .iloc [0 , 0 ] == 'fooA'
2439
- assert df1 .iloc [4 , 0 ] == 'fooE'
2440
- assert df1 .iloc [4 , 5 ] == 25
2425
+ # Test if iloc can handle integer locations in MultiIndexed DataFrame
2426
+
2427
+ data = [
2428
+ ['str00' , 'str01' ],
2429
+ ['str10' , 'str11' ],
2430
+ ['str20' , 'srt21' ],
2431
+ ['str30' , 'str31' ],
2432
+ ['str40' , 'str41' ]
2433
+ ]
2434
+
2435
+ mi = pd .MultiIndex .from_tuples (
2436
+ [('CC' ,'A' ),
2437
+ ('CC' ,'B' ),
2438
+ ('CC' ,'B' ),
2439
+ ('BB' ,'a' ),
2440
+ ('BB' ,'b' )
2441
+ ])
2442
+
2443
+ ans = pd .DataFrame (data )
2444
+ df_mi = pd .DataFrame (data , index = mi )
2445
+
2446
+ res = pd .DataFrame ([[df_mi .iloc [r ,c ] for c in range (2 )] for r in range (5 )])
2447
+
2448
+ assert_frame_equal (res , ans )
2441
2449
2442
2450
2443
2451
if __name__ == '__main__' :
0 commit comments