Skip to content

Commit 6c4f599

Browse files
committed
Added test for GroupBy pct_change
1 parent a7a7f8c commit 6c4f599

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/groupby/test_groupby.py

+22
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,28 @@ def test_groupby_bool_aggs(self, agg_func, skipna, vals):
21412141
result = getattr(df.groupby('key'), agg_func)(skipna=skipna)
21422142
assert_frame_equal(result, exp_df)
21432143

2144+
@pytest.mark.parametrize("periods,fill_method,limit,freq", [
2145+
(1, 'ffill', None, None), (1, 'ffill', 1, None),
2146+
(1, 'bfill', None, None), (1, 'bfill', 1, None),
2147+
(-1, 'ffill', None, None), (-1, 'ffill', 1, None),
2148+
(-1, 'bfill', None, None), (-1, 'bfill', 1, None)])
2149+
def test_pct_change(self, periods, fill_method, limit, freq):
2150+
vals = [np.nan, np.nan, 1, 2, 4, 10, np.nan, np.nan]
2151+
exp_vals = Series(vals).pct_change(periods=periods,
2152+
fill_method=fill_method,
2153+
limit=limit,
2154+
freq=freq).tolist()
2155+
2156+
df = DataFrame({'key': ['a'] * len(vals) + ['b'] * len(vals),
2157+
'vals': vals * 2})
2158+
exp = DataFrame({'vals': exp_vals * 2})
2159+
result = df.groupby('key').pct_change(periods=periods,
2160+
fill_method=fill_method,
2161+
limit=limit,
2162+
freq=freq)
2163+
2164+
tm.assert_frame_equal(result, exp)
2165+
21442166
def test_dont_clobber_name_column(self):
21452167
df = DataFrame({'key': ['a', 'a', 'a', 'b', 'b', 'b'],
21462168
'name': ['foo', 'bar', 'baz'] * 2})

0 commit comments

Comments
 (0)