Skip to content

Commit eea5653

Browse files
committed
GH pandas-dev#14499 Panel.ffill ignores axis parameter and fill along axis=1
1 parent 096d886 commit eea5653

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -3208,7 +3208,10 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
32083208
# set the default here, so functions examining the signaure
32093209
# can detect if something was set (e.g. in groupby) (GH9221)
32103210
if axis is None:
3211-
axis = 0
3211+
if self.ndim == 3:
3212+
axis = 1
3213+
else:
3214+
axis = 0
32123215
axis = self._get_axis_number(axis)
32133216
method = missing.clean_fill_method(method)
32143217

@@ -3233,9 +3236,13 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
32333236

32343237
# 3d
32353238
elif self.ndim == 3:
3236-
3239+
if axis == 0:
3240+
raise NotImplementedError('Cannot fillna with axis=0 '
3241+
'for Panel')
32373242
# fill in 2d chunks
3238-
result = dict([(col, s.fillna(method=method, value=value))
3243+
result = dict([(col, s.fillna(method=method,
3244+
value=value,
3245+
axis=axis-1))
32393246
for col, s in self.iteritems()])
32403247
new_obj = self._constructor.\
32413248
from_dict(result).__finalize__(self)

pandas/tests/test_panel.py

+31
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,37 @@ 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, dtype=float).reshape((5, 3)),
1526+
'b':np.arange(15, 30, dtype=float).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+
b1['a'].loc[1, 1] = 7
1536+
b2['a'].loc[1, 1] = 5
1537+
# method='ffill'
1538+
# axis=1
1539+
assert_panel_equal(a.ffill(axis=1), f1)
1540+
1541+
# method='ffill'
1542+
# axis=2
1543+
assert_panel_equal(a.ffill(axis=2), f2)
1544+
1545+
# method='bfill'
1546+
# axis=1
1547+
assert_panel_equal(a.bfill(axis=1), b1)
1548+
1549+
# method='bfill'
1550+
# axis=2
1551+
assert_panel_equal(a.bfill(axis=2), b2)
1552+
15221553
def test_truncate_fillna_bug(self):
15231554
# #1823
15241555
result = self.panel.truncate(before=None, after=None, axis='items')

0 commit comments

Comments
 (0)