Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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