Skip to content

Commit d687383

Browse files
committed
Refactored test_pct_change
1 parent 9e9c295 commit d687383

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pandas/tests/generic/test_generic.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -603,19 +603,14 @@ def test_copy_and_deepcopy(self):
603603
(-1, "bfill", 1, [np.nan, 0, -.5, -.5, -.6, np.nan, np.nan, np.nan])
604604
])
605605
def test_pct_change(self, periods, fill_method, limit, exp):
606-
obj = self._construct(0)
607-
is_frame = type(obj) is DataFrame
608-
ser = pd.Series([np.nan, np.nan, 1, 2, 4, 10, np.nan, np.nan])
609-
obj = pd.concat((obj, ser))
610-
606+
vals = [np.nan, np.nan, 1, 2, 4, 10, np.nan, np.nan]
607+
obj = self._typ(vals)
611608
func = getattr(obj, 'pct_change')
612609
res = func(periods=periods, fill_method=fill_method, limit=limit)
613-
614-
# Convert output into Series, regardless of input type
615-
if is_frame:
616-
res = res[0]
617-
res.name = None
618-
tm.assert_series_equal(res, pd.Series(exp))
610+
if type(obj) is DataFrame:
611+
tm.assert_frame_equal(res, DataFrame(exp))
612+
else:
613+
tm.assert_series_equal(res, Series(exp))
619614

620615

621616
class TestNDFrame(object):

0 commit comments

Comments
 (0)