@@ -297,9 +297,9 @@ def test_nth(self):
297297 # as it keeps the order in the series (and not the group order)
298298 # related GH 7287
299299 expected = s .groupby (g ,sort = False ).first ()
300- expected .index = range (1 ,10 )
301- result = s .groupby (g ).nth (0 ,dropna = 'all' )
302- assert_series_equal (result ,expected )
300+ expected .index = pd . Index ( range (1 ,10 ), name = 0 )
301+ result = s .groupby (g ).nth (0 , dropna = 'all' )
302+ assert_series_equal (result , expected )
303303
304304 # doc example
305305 df = DataFrame ([[1 , np .nan ], [1 , 4 ], [5 , 6 ]], columns = ['A' , 'B' ])
@@ -807,9 +807,10 @@ def test_apply_issues(self):
807807 # GH 5789
808808 # don't auto coerce dates
809809 df = pd .read_csv (StringIO (s ), header = None , names = ['date' , 'time' , 'value' ])
810- expected = Series (['00:00' ,'02:00' ,'02:00' ],index = ['2011.05.16' ,'2011.05.17' ,'2011.05.18' ])
810+ exp_idx = pd .Index (['2011.05.16' ,'2011.05.17' ,'2011.05.18' ], dtype = object , name = 'date' )
811+ expected = Series (['00:00' ,'02:00' ,'02:00' ], index = exp_idx )
811812 result = df .groupby ('date' ).apply (lambda x : x ['time' ][x ['value' ].idxmax ()])
812- assert_series_equal (result ,expected )
813+ assert_series_equal (result , expected )
813814
814815 def test_len (self ):
815816 df = tm .makeTimeDataFrame ()
@@ -1700,7 +1701,8 @@ def test_groupby_as_index_apply(self):
17001701 # apply doesn't maintain the original ordering
17011702 # changed in GH5610 as the as_index=False returns a MI here
17021703 exp_not_as_apply = MultiIndex .from_tuples ([(0 , 0 ), (0 , 2 ), (1 , 1 ), (2 , 4 )])
1703- exp_as_apply = MultiIndex .from_tuples ([(1 , 0 ), (1 , 2 ), (2 , 1 ), (3 , 4 )])
1704+ tp = [(1 , 0 ), (1 , 2 ), (2 , 1 ), (3 , 4 )]
1705+ exp_as_apply = MultiIndex .from_tuples (tp , names = ['user_id' , None ])
17041706
17051707 assert_index_equal (res_as_apply , exp_as_apply )
17061708 assert_index_equal (res_not_as_apply , exp_not_as_apply )
@@ -1922,6 +1924,8 @@ def _testit(op):
19221924 for (cat1 , cat2 ), group in grouped :
19231925 expd .setdefault (cat1 , {})[cat2 ] = op (group ['C' ])
19241926 exp = DataFrame (expd ).T .stack (dropna = False )
1927+ exp .index .names = ['A' , 'B' ]
1928+
19251929 result = op (grouped )['C' ]
19261930 assert_series_equal (result , exp )
19271931
@@ -1974,7 +1978,7 @@ def test_cython_agg_nothing_to_agg_with_dates(self):
19741978 def test_groupby_timedelta_cython_count (self ):
19751979 df = DataFrame ({'g' : list ('ab' * 2 ),
19761980 'delt' : np .arange (4 ).astype ('timedelta64[ns]' )})
1977- expected = Series ([2 , 2 ], index = ['a' , 'b' ], name = 'delt' )
1981+ expected = Series ([2 , 2 ], index = pd . Index ( ['a' , 'b' ], name = 'g' ) , name = 'delt' )
19781982 result = df .groupby ('g' ).delt .count ()
19791983 tm .assert_series_equal (expected , result )
19801984
@@ -2385,13 +2389,13 @@ def test_count_object(self):
23852389 df = pd .DataFrame ({'a' : ['a' ] * 3 + ['b' ] * 3 ,
23862390 'c' : [2 ] * 3 + [3 ] * 3 })
23872391 result = df .groupby ('c' ).a .count ()
2388- expected = pd .Series ([3 , 3 ], index = [2 , 3 ], name = 'a' )
2392+ expected = pd .Series ([3 , 3 ], index = pd . Index ( [2 , 3 ], name = 'c' ) , name = 'a' )
23892393 tm .assert_series_equal (result , expected )
23902394
23912395 df = pd .DataFrame ({'a' : ['a' , np .nan , np .nan ] + ['b' ] * 3 ,
23922396 'c' : [2 ] * 3 + [3 ] * 3 })
23932397 result = df .groupby ('c' ).a .count ()
2394- expected = pd .Series ([1 , 3 ], index = [2 , 3 ], name = 'a' )
2398+ expected = pd .Series ([1 , 3 ], index = pd . Index ( [2 , 3 ], name = 'c' ) , name = 'a' )
23952399 tm .assert_series_equal (result , expected )
23962400
23972401 def test_count_cross_type (self ): # GH8169
0 commit comments