Skip to content

Commit 92dbc78

Browse files
mingglijreback
authored andcommitted
parameterize test_pct_change_periods_freq (#19897)
1 parent d40fb54 commit 92dbc78

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed

pandas/tests/frame/test_timeseries.py

+20-25
Original file line numberDiff line numberDiff line change
@@ -122,36 +122,31 @@ def test_pct_change_shift_over_nas(self):
122122
edf = DataFrame({'a': expected, 'b': expected})
123123
assert_frame_equal(chg, edf)
124124

125-
def test_pct_change_periods_freq(self):
125+
@pytest.mark.parametrize("freq, periods, fill_method, limit",
126+
[('5B', 5, None, None),
127+
('3B', 3, None, None),
128+
('3B', 3, 'bfill', None),
129+
('7B', 7, 'pad', 1),
130+
('7B', 7, 'bfill', 3),
131+
('14B', 14, None, None)])
132+
def test_pct_change_periods_freq(self, freq, periods, fill_method, limit):
126133
# GH 7292
127-
rs_freq = self.tsframe.pct_change(freq='5B')
128-
rs_periods = self.tsframe.pct_change(5)
129-
assert_frame_equal(rs_freq, rs_periods)
130-
131-
rs_freq = self.tsframe.pct_change(freq='3B', fill_method=None)
132-
rs_periods = self.tsframe.pct_change(3, fill_method=None)
133-
assert_frame_equal(rs_freq, rs_periods)
134-
135-
rs_freq = self.tsframe.pct_change(freq='3B', fill_method='bfill')
136-
rs_periods = self.tsframe.pct_change(3, fill_method='bfill')
137-
assert_frame_equal(rs_freq, rs_periods)
138-
139-
rs_freq = self.tsframe.pct_change(freq='7B',
140-
fill_method='pad',
141-
limit=1)
142-
rs_periods = self.tsframe.pct_change(7, fill_method='pad', limit=1)
143-
assert_frame_equal(rs_freq, rs_periods)
144-
145-
rs_freq = self.tsframe.pct_change(freq='7B',
146-
fill_method='bfill',
147-
limit=3)
148-
rs_periods = self.tsframe.pct_change(7, fill_method='bfill', limit=3)
134+
rs_freq = self.tsframe.pct_change(freq=freq,
135+
fill_method=fill_method,
136+
limit=limit)
137+
rs_periods = self.tsframe.pct_change(periods,
138+
fill_method=fill_method,
139+
limit=limit)
149140
assert_frame_equal(rs_freq, rs_periods)
150141

151142
empty_ts = DataFrame(index=self.tsframe.index,
152143
columns=self.tsframe.columns)
153-
rs_freq = empty_ts.pct_change(freq='14B')
154-
rs_periods = empty_ts.pct_change(14)
144+
rs_freq = empty_ts.pct_change(freq=freq,
145+
fill_method=fill_method,
146+
limit=limit)
147+
rs_periods = empty_ts.pct_change(periods,
148+
fill_method=fill_method,
149+
limit=limit)
155150
assert_frame_equal(rs_freq, rs_periods)
156151

157152
def test_frame_ctor_datetime64_column(self):

pandas/tests/series/test_timeseries.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -355,31 +355,30 @@ def test_pct_change_shift_over_nas(self):
355355
expected = Series([np.nan, 0.5, 0., 2.5 / 1.5 - 1, .2])
356356
assert_series_equal(chg, expected)
357357

358-
def test_pct_change_periods_freq(self):
358+
@pytest.mark.parametrize("freq, periods, fill_method, limit",
359+
[('5B', 5, None, None),
360+
('3B', 3, None, None),
361+
('3B', 3, 'bfill', None),
362+
('7B', 7, 'pad', 1),
363+
('7B', 7, 'bfill', 3),
364+
('14B', 14, None, None)])
365+
def test_pct_change_periods_freq(self, freq, periods, fill_method, limit):
359366
# GH 7292
360-
rs_freq = self.ts.pct_change(freq='5B')
361-
rs_periods = self.ts.pct_change(5)
362-
assert_series_equal(rs_freq, rs_periods)
363-
364-
rs_freq = self.ts.pct_change(freq='3B', fill_method=None)
365-
rs_periods = self.ts.pct_change(3, fill_method=None)
366-
assert_series_equal(rs_freq, rs_periods)
367-
368-
rs_freq = self.ts.pct_change(freq='3B', fill_method='bfill')
369-
rs_periods = self.ts.pct_change(3, fill_method='bfill')
370-
assert_series_equal(rs_freq, rs_periods)
371-
372-
rs_freq = self.ts.pct_change(freq='7B', fill_method='pad', limit=1)
373-
rs_periods = self.ts.pct_change(7, fill_method='pad', limit=1)
374-
assert_series_equal(rs_freq, rs_periods)
375-
376-
rs_freq = self.ts.pct_change(freq='7B', fill_method='bfill', limit=3)
377-
rs_periods = self.ts.pct_change(7, fill_method='bfill', limit=3)
367+
rs_freq = self.ts.pct_change(freq=freq,
368+
fill_method=fill_method,
369+
limit=limit)
370+
rs_periods = self.ts.pct_change(periods,
371+
fill_method=fill_method,
372+
limit=limit)
378373
assert_series_equal(rs_freq, rs_periods)
379374

380375
empty_ts = Series(index=self.ts.index)
381-
rs_freq = empty_ts.pct_change(freq='14B')
382-
rs_periods = empty_ts.pct_change(14)
376+
rs_freq = empty_ts.pct_change(freq=freq,
377+
fill_method=fill_method,
378+
limit=limit)
379+
rs_periods = empty_ts.pct_change(periods,
380+
fill_method=fill_method,
381+
limit=limit)
383382
assert_series_equal(rs_freq, rs_periods)
384383

385384
def test_autocorr(self):

0 commit comments

Comments
 (0)