@@ -297,9 +297,9 @@ def test_nth(self):
297
297
# as it keeps the order in the series (and not the group order)
298
298
# related GH 7287
299
299
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 )
303
303
304
304
# doc example
305
305
df = DataFrame ([[1 , np .nan ], [1 , 4 ], [5 , 6 ]], columns = ['A' , 'B' ])
@@ -807,9 +807,10 @@ def test_apply_issues(self):
807
807
# GH 5789
808
808
# don't auto coerce dates
809
809
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 )
811
812
result = df .groupby ('date' ).apply (lambda x : x ['time' ][x ['value' ].idxmax ()])
812
- assert_series_equal (result ,expected )
813
+ assert_series_equal (result , expected )
813
814
814
815
def test_len (self ):
815
816
df = tm .makeTimeDataFrame ()
@@ -1700,7 +1701,8 @@ def test_groupby_as_index_apply(self):
1700
1701
# apply doesn't maintain the original ordering
1701
1702
# changed in GH5610 as the as_index=False returns a MI here
1702
1703
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 ])
1704
1706
1705
1707
assert_index_equal (res_as_apply , exp_as_apply )
1706
1708
assert_index_equal (res_not_as_apply , exp_not_as_apply )
@@ -1922,6 +1924,8 @@ def _testit(op):
1922
1924
for (cat1 , cat2 ), group in grouped :
1923
1925
expd .setdefault (cat1 , {})[cat2 ] = op (group ['C' ])
1924
1926
exp = DataFrame (expd ).T .stack (dropna = False )
1927
+ exp .index .names = ['A' , 'B' ]
1928
+
1925
1929
result = op (grouped )['C' ]
1926
1930
assert_series_equal (result , exp )
1927
1931
@@ -1974,7 +1978,7 @@ def test_cython_agg_nothing_to_agg_with_dates(self):
1974
1978
def test_groupby_timedelta_cython_count (self ):
1975
1979
df = DataFrame ({'g' : list ('ab' * 2 ),
1976
1980
'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' )
1978
1982
result = df .groupby ('g' ).delt .count ()
1979
1983
tm .assert_series_equal (expected , result )
1980
1984
@@ -2385,13 +2389,13 @@ def test_count_object(self):
2385
2389
df = pd .DataFrame ({'a' : ['a' ] * 3 + ['b' ] * 3 ,
2386
2390
'c' : [2 ] * 3 + [3 ] * 3 })
2387
2391
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' )
2389
2393
tm .assert_series_equal (result , expected )
2390
2394
2391
2395
df = pd .DataFrame ({'a' : ['a' , np .nan , np .nan ] + ['b' ] * 3 ,
2392
2396
'c' : [2 ] * 3 + [3 ] * 3 })
2393
2397
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' )
2395
2399
tm .assert_series_equal (result , expected )
2396
2400
2397
2401
def test_count_cross_type (self ): # GH8169
0 commit comments