Skip to content

Commit

Permalink
parameterize test_pct_change_periods_freq (#19897)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggli authored and jreback committed Feb 25, 2018
1 parent d40fb54 commit 92dbc78
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 46 deletions.
45 changes: 20 additions & 25 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,31 @@ def test_pct_change_shift_over_nas(self):
edf = DataFrame({'a': expected, 'b': expected})
assert_frame_equal(chg, edf)

def test_pct_change_periods_freq(self):
@pytest.mark.parametrize("freq, periods, fill_method, limit",
[('5B', 5, None, None),
('3B', 3, None, None),
('3B', 3, 'bfill', None),
('7B', 7, 'pad', 1),
('7B', 7, 'bfill', 3),
('14B', 14, None, None)])
def test_pct_change_periods_freq(self, freq, periods, fill_method, limit):
# GH 7292
rs_freq = self.tsframe.pct_change(freq='5B')
rs_periods = self.tsframe.pct_change(5)
assert_frame_equal(rs_freq, rs_periods)

rs_freq = self.tsframe.pct_change(freq='3B', fill_method=None)
rs_periods = self.tsframe.pct_change(3, fill_method=None)
assert_frame_equal(rs_freq, rs_periods)

rs_freq = self.tsframe.pct_change(freq='3B', fill_method='bfill')
rs_periods = self.tsframe.pct_change(3, fill_method='bfill')
assert_frame_equal(rs_freq, rs_periods)

rs_freq = self.tsframe.pct_change(freq='7B',
fill_method='pad',
limit=1)
rs_periods = self.tsframe.pct_change(7, fill_method='pad', limit=1)
assert_frame_equal(rs_freq, rs_periods)

rs_freq = self.tsframe.pct_change(freq='7B',
fill_method='bfill',
limit=3)
rs_periods = self.tsframe.pct_change(7, fill_method='bfill', limit=3)
rs_freq = self.tsframe.pct_change(freq=freq,
fill_method=fill_method,
limit=limit)
rs_periods = self.tsframe.pct_change(periods,
fill_method=fill_method,
limit=limit)
assert_frame_equal(rs_freq, rs_periods)

empty_ts = DataFrame(index=self.tsframe.index,
columns=self.tsframe.columns)
rs_freq = empty_ts.pct_change(freq='14B')
rs_periods = empty_ts.pct_change(14)
rs_freq = empty_ts.pct_change(freq=freq,
fill_method=fill_method,
limit=limit)
rs_periods = empty_ts.pct_change(periods,
fill_method=fill_method,
limit=limit)
assert_frame_equal(rs_freq, rs_periods)

def test_frame_ctor_datetime64_column(self):
Expand Down
41 changes: 20 additions & 21 deletions pandas/tests/series/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,30 @@ def test_pct_change_shift_over_nas(self):
expected = Series([np.nan, 0.5, 0., 2.5 / 1.5 - 1, .2])
assert_series_equal(chg, expected)

def test_pct_change_periods_freq(self):
@pytest.mark.parametrize("freq, periods, fill_method, limit",
[('5B', 5, None, None),
('3B', 3, None, None),
('3B', 3, 'bfill', None),
('7B', 7, 'pad', 1),
('7B', 7, 'bfill', 3),
('14B', 14, None, None)])
def test_pct_change_periods_freq(self, freq, periods, fill_method, limit):
# GH 7292
rs_freq = self.ts.pct_change(freq='5B')
rs_periods = self.ts.pct_change(5)
assert_series_equal(rs_freq, rs_periods)

rs_freq = self.ts.pct_change(freq='3B', fill_method=None)
rs_periods = self.ts.pct_change(3, fill_method=None)
assert_series_equal(rs_freq, rs_periods)

rs_freq = self.ts.pct_change(freq='3B', fill_method='bfill')
rs_periods = self.ts.pct_change(3, fill_method='bfill')
assert_series_equal(rs_freq, rs_periods)

rs_freq = self.ts.pct_change(freq='7B', fill_method='pad', limit=1)
rs_periods = self.ts.pct_change(7, fill_method='pad', limit=1)
assert_series_equal(rs_freq, rs_periods)

rs_freq = self.ts.pct_change(freq='7B', fill_method='bfill', limit=3)
rs_periods = self.ts.pct_change(7, fill_method='bfill', limit=3)
rs_freq = self.ts.pct_change(freq=freq,
fill_method=fill_method,
limit=limit)
rs_periods = self.ts.pct_change(periods,
fill_method=fill_method,
limit=limit)
assert_series_equal(rs_freq, rs_periods)

empty_ts = Series(index=self.ts.index)
rs_freq = empty_ts.pct_change(freq='14B')
rs_periods = empty_ts.pct_change(14)
rs_freq = empty_ts.pct_change(freq=freq,
fill_method=fill_method,
limit=limit)
rs_periods = empty_ts.pct_change(periods,
fill_method=fill_method,
limit=limit)
assert_series_equal(rs_freq, rs_periods)

def test_autocorr(self):
Expand Down

0 comments on commit 92dbc78

Please sign in to comment.