Skip to content

Commit 45247b7

Browse files
committed
GH #14499 Panel.ffill ignores axis parameter and fill along axis=1
1 parent 096d886 commit 45247b7

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

doc/source/whatsnew/v0.19.1.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ Bug Fixes
8080

8181

8282
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
83-
is not scalar and ``values`` is not specified (:issue:`14380`)
83+
is not scalar and ``values`` is not specified (:issue:`14380`)
84+
85+
- Bug in ``pd.Panel.ffill`` where ``axis`` was not propagated (:issue:`14499`)

pandas/core/generic.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -3233,14 +3233,20 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
32333233

32343234
# 3d
32353235
elif self.ndim == 3:
3236-
3236+
if axis == 0:
3237+
raise NotImplementedError('Cannot fillna with axis=0 '
3238+
'for Panel')
32373239
# fill in 2d chunks
3238-
result = dict([(col, s.fillna(method=method, value=value))
3240+
result = dict([(col, s.fillna(method=method,
3241+
value=value,
3242+
axis=axis-1))
32393243
for col, s in self.iteritems()])
32403244
new_obj = self._constructor.\
32413245
from_dict(result).__finalize__(self)
32423246
new_data = new_obj._data
32433247

3248+
def test_ffill_bfill_axis(self):
3249+
32443250
else:
32453251
# 2d or less
32463252
method = missing.clean_fill_method(method)

pandas/tests/test_panel.py

+30
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,36 @@ def test_ffill_bfill(self):
15191519
assert_panel_equal(self.panel.bfill(),
15201520
self.panel.fillna(method='bfill'))
15211521

1522+
def test_ffill_bfill_axis(self):
1523+
#GH 14499
1524+
a = Panel({
1525+
'a':np.arange(15).reshape((5, 3)),
1526+
'b':np.arange(15, 30).reshape((5, 3))
1527+
})
1528+
f1 = a.copy()
1529+
f2 = a.copy()
1530+
b1 = a.copy()
1531+
b2 = a.copy()
1532+
a['a'].loc[1, 1] = np.nan
1533+
f1['a'].loc[1, 1] = 1
1534+
f2['a'].loc[1, 1] = 3
1535+
1536+
# method='ffill'
1537+
# axis=1
1538+
assert_panel_equal(a.ffill(axis=1), f1)
1539+
1540+
# method='ffill'
1541+
# axis=2
1542+
assert_panel_equal(a.ffill(axis=2), f2)
1543+
1544+
# method='bfill'
1545+
# axis=1
1546+
assert_panel_equal(a.bfill(axis=1), b1)
1547+
1548+
# method='bfill'
1549+
# axis=2
1550+
assert_panel_equal(a.bfill(axis=2), b2)
1551+
15221552
def test_truncate_fillna_bug(self):
15231553
# #1823
15241554
result = self.panel.truncate(before=None, after=None, axis='items')

0 commit comments

Comments
 (0)