Skip to content

Commit 334b076

Browse files
Tux1jreback
authored andcommitted
BUG: axis kw not propogating on pct_change #11150
1 parent d63a410 commit 334b076

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

doc/source/whatsnew/v0.17.1.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ API changes
4444
Legacy Python syntax (``set([x, y])``) (:issue:`11215`)
4545
- Indexing with a null key will raise a ``TypeError``, instead of a ``ValueError`` (:issue:`11356`)
4646
- ``Series.sort_index()`` now correctly handles the ``inplace`` option (:issue:`11402`)
47+
4748
- ``DataFrame.itertuples()`` now returns ``namedtuple`` objects, when possible. (:issue:`11269`)
4849

4950
.. _whatsnew_0171.deprecations:
@@ -83,6 +84,7 @@ Bug Fixes
8384
- Bug in ``HDFStore.append`` with strings whose encoded length exceded the max unencoded length (:issue:`11234`)
8485
- Bug in merging ``datetime64[ns, tz]`` dtypes (:issue:`11405`)
8586
- Bug in ``HDFStore.select`` when comparing with a numpy scalar in a where clause (:issue:`11283`)
87+
8688
- Bug in using ``DataFrame.ix`` with a multi-index indexer(:issue:`11372`)
8789

8890

@@ -107,7 +109,7 @@ Bug Fixes
107109

108110

109111

110-
112+
- Bug in ``DataFrame.pct_change()`` not propagating ``axis`` keyword on ``.fillna`` method (:issue:`11150`)
111113

112114

113115

@@ -116,6 +118,7 @@ Bug Fixes
116118

117119

118120

121+
119122
- Bug in ``DataFrame.to_latex()`` produces an extra rule when ``header=False`` (:issue:`7124`)
120123

121124

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4567,7 +4567,7 @@ def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None,
45674567
if fill_method is None:
45684568
data = self
45694569
else:
4570-
data = self.fillna(method=fill_method, limit=limit)
4570+
data = self.fillna(method=fill_method, limit=limit, axis=axis)
45714571

45724572
rs = (data.div(data.shift(periods=periods, freq=freq,
45734573
axis=axis, **kwargs)) - 1)

pandas/tests/test_generic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,21 @@ def test_set_attribute(self):
16991699
assert_equal(df.y, 5)
17001700
assert_series_equal(df['y'], Series([2, 4, 6], name='y'))
17011701

1702+
def test_pct_change(self):
1703+
# GH 11150
1704+
pnl = DataFrame([np.arange(0, 40, 10), np.arange(0, 40, 10), np.arange(0, 40, 10)]).astype(np.float64)
1705+
pnl.iat[1,0] = np.nan
1706+
pnl.iat[1,1] = np.nan
1707+
pnl.iat[2,3] = 60
1708+
1709+
mask = pnl.isnull()
1710+
1711+
for axis in range(2):
1712+
expected = pnl.ffill(axis=axis)/pnl.ffill(axis=axis).shift(axis=axis) - 1
1713+
expected[mask] = np.nan
1714+
result = pnl.pct_change(axis=axis, fill_method='pad')
1715+
1716+
self.assert_frame_equal(result, expected)
17021717

17031718
class TestPanel(tm.TestCase, Generic):
17041719
_typ = Panel
@@ -1878,6 +1893,7 @@ def test_pipe_panel(self):
18781893
with tm.assertRaises(ValueError):
18791894
result = wp.pipe((f, 'y'), x=1, y=1)
18801895

1896+
18811897
if __name__ == '__main__':
18821898
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
18831899
exit=False)

0 commit comments

Comments
 (0)