@@ -2141,25 +2141,36 @@ def test_groupby_bool_aggs(self, agg_func, skipna, vals):
2141
2141
result = getattr (df .groupby ('key' ), agg_func )(skipna = skipna )
2142
2142
assert_frame_equal (result , exp_df )
2143
2143
2144
+ @pytest .mark .parametrize ("test_series" , [True , False ])
2144
2145
@pytest .mark .parametrize ("periods,fill_method,limit" , [
2145
2146
(1 , 'ffill' , None ), (1 , 'ffill' , 1 ),
2146
2147
(1 , 'bfill' , None ), (1 , 'bfill' , 1 ),
2147
2148
(- 1 , 'ffill' , None ), (- 1 , 'ffill' , 1 ),
2148
2149
(- 1 , 'bfill' , None ), (- 1 , 'bfill' , 1 )])
2149
- def test_pct_change (self , periods , fill_method , limit ):
2150
+ def test_pct_change (self , test_series , periods , fill_method , limit ):
2150
2151
vals = [np .nan , np .nan , 1 , 2 , 4 , 10 , np .nan , np .nan ]
2151
2152
exp_vals = Series (vals ).pct_change (periods = periods ,
2152
2153
fill_method = fill_method ,
2153
2154
limit = limit ).tolist ()
2154
2155
2155
2156
df = DataFrame ({'key' : ['a' ] * len (vals ) + ['b' ] * len (vals ),
2156
2157
'vals' : vals * 2 })
2157
- exp = DataFrame ({'vals' : exp_vals * 2 })
2158
- result = df .groupby ('key' ).pct_change (periods = periods ,
2159
- fill_method = fill_method ,
2160
- limit = limit )
2161
-
2162
- tm .assert_frame_equal (result , exp )
2158
+ grp = df .groupby ('key' )
2159
+ def get_result (grp_obj ):
2160
+ return grp_obj .pct_change (periods = periods ,
2161
+ fill_method = fill_method ,
2162
+ limit = limit )
2163
+
2164
+ if test_series :
2165
+ exp = pd .Series (exp_vals * 2 )
2166
+ exp .name = 'vals'
2167
+ grp = grp ['vals' ]
2168
+ result = get_result (grp )
2169
+ tm .assert_series_equal (result , exp )
2170
+ else :
2171
+ exp = DataFrame ({'vals' : exp_vals * 2 })
2172
+ result = get_result (grp )
2173
+ tm .assert_frame_equal (result , exp )
2163
2174
2164
2175
def test_dont_clobber_name_column (self ):
2165
2176
df = DataFrame ({'key' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' ],
0 commit comments