Skip to content

Commit 032fd5a

Browse files
committed
Added test cases for pct_change op
1 parent ce77b79 commit 032fd5a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/generic/test_generic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,32 @@ def test_copy_and_deepcopy(self):
592592
assert obj_copy is not obj
593593
self._compare(obj_copy, obj)
594594

595+
@pytest.mark.parametrize("periods,fill_method,limit,exp", [
596+
(1, "ffill", None, [np.nan, np.nan, np.nan, 1, 1, 1.5, 0, 0]),
597+
(1, "ffill", 1, [np.nan, np.nan, np.nan, 1, 1, 1.5, 0, np.nan]),
598+
(1, "bfill", None, [np.nan, 0, 0, 1, 1, 1.5, np.nan, np.nan]),
599+
(1, "bfill", 1, [np.nan, np.nan, 0, 1, 1, 1.5, np.nan, np.nan]),
600+
(-1, "ffill", None, [np.nan, np.nan, -.5, -.5, -.6, 0, 0, np.nan]),
601+
(-1, "ffill", 1, [np.nan, np.nan, -.5, -.5, -.6, 0, np.nan, np.nan]),
602+
(-1, "bfill", None, [0, 0, -.5, -.5, -.6, np.nan, np.nan, np.nan]),
603+
(-1, "bfill", 1, [np.nan, 0, -.5, -.5, -.6, np.nan, np.nan, np.nan])
604+
])
605+
def test_pct_change(self, periods, fill_method, limit, exp):
606+
obj = self._construct(0)
607+
if type(obj) is Panel:
608+
pytest.skip("Not testing deprecated Panel")
609+
is_frame = type(obj) is DataFrame
610+
ser = pd.Series([np.nan, np.nan, 1, 2, 4, 10, np.nan, np.nan])
611+
obj = pd.concat((obj, ser))
612+
613+
func = getattr(obj, 'pct_change')
614+
res = func(periods=periods, fill_method=fill_method, limit=limit)
615+
616+
# Convert output into Series, regardless of input type
617+
if is_frame:
618+
res = res[0]
619+
res.name = None
620+
tm.assert_series_equal(res, pd.Series(exp))
595621

596622
class TestNDFrame(object):
597623
# tests that don't fit elsewhere

0 commit comments

Comments
 (0)