@@ -337,6 +337,35 @@ def test_nth(self):
337
337
expected = DataFrame (1 , columns = ['a' , 'b' ], index = expected_dates )
338
338
assert_frame_equal (result , expected )
339
339
340
+ def test_nth_multi_index (self ):
341
+ # PR 9090, related to issue 8979
342
+ # test nth on MultiIndex, should match .first()
343
+ grouped = self .three_group .groupby (['A' , 'B' ])
344
+ result = grouped .nth (0 )
345
+ expected = grouped .first ()
346
+ assert_frame_equal (result , expected )
347
+
348
+
349
+ def test_nth_multi_index_as_expected (self ):
350
+ # PR 9090, related to issue 8979
351
+ # test nth on MultiIndex
352
+ three_group = DataFrame ({'A' : ['foo' , 'foo' , 'foo' , 'foo' ,
353
+ 'bar' , 'bar' , 'bar' , 'bar' ,
354
+ 'foo' , 'foo' , 'foo' ],
355
+ 'B' : ['one' , 'one' , 'one' , 'two' ,
356
+ 'one' , 'one' , 'one' , 'two' ,
357
+ 'two' , 'two' , 'one' ],
358
+ 'C' : ['dull' , 'dull' , 'shiny' , 'dull' ,
359
+ 'dull' , 'shiny' , 'shiny' , 'dull' ,
360
+ 'shiny' , 'shiny' , 'shiny' ]})
361
+ grouped = three_group .groupby (['A' , 'B' ])
362
+ result = grouped .nth (0 )
363
+ expected = DataFrame ({'C' : ['dull' , 'dull' , 'dull' , 'dull' ]},
364
+ index = MultiIndex .from_arrays ([['bar' , 'bar' , 'foo' , 'foo' ], ['one' , 'two' , 'one' , 'two' ]],
365
+ names = ['A' , 'B' ]))
366
+ assert_frame_equal (result , expected )
367
+
368
+
340
369
def test_grouper_index_types (self ):
341
370
# related GH5375
342
371
# groupby misbehaving when using a Floatlike index
0 commit comments