File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,30 @@ def test_loc_multiindex(self):
275
275
xp = mi_int .ix [4 ]
276
276
tm .assert_frame_equal (rs , xp )
277
277
278
+ def test_getitem_partial_int (self ):
279
+ # GH 12416
280
+ # with single item
281
+ l1 = [10 , 20 ]
282
+ l2 = ['a' , 'b' ]
283
+ df = DataFrame (index = range (2 ),
284
+ columns = pd .MultiIndex .from_product ([l1 , l2 ]))
285
+ expected = DataFrame (index = range (2 ),
286
+ columns = l2 )
287
+ result = df [20 ]
288
+ tm .assert_frame_equal (result , expected )
289
+
290
+ # with list
291
+ expected = DataFrame (index = range (2 ),
292
+ columns = pd .MultiIndex .from_product ([l1 [1 :], l2 ]))
293
+ result = df [[20 ]]
294
+ tm .assert_frame_equal (result , expected )
295
+
296
+ # missing item:
297
+ with tm .assertRaisesRegexp (KeyError , '1' ):
298
+ df [1 ]
299
+ with tm .assertRaisesRegexp (KeyError , "'\[1\] not in index'" ):
300
+ df [[1 ]]
301
+
278
302
def test_loc_multiindex_indexer_none (self ):
279
303
280
304
# GH6788
You can’t perform that action at this time.
0 commit comments