Skip to content

Commit

Permalink
GH pandas-dev#14499 Panel.ffill ignores axis parameter and fill along…
Browse files Browse the repository at this point in the history
… axis=1
  • Loading branch information
Tux1 committed Oct 28, 2016
1 parent 096d886 commit 45247b7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 3 additions & 1 deletion doc/source/whatsnew/v0.19.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ Bug Fixes


- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
is not scalar and ``values`` is not specified (:issue:`14380`)
is not scalar and ``values`` is not specified (:issue:`14380`)

- Bug in ``pd.Panel.ffill`` where ``axis`` was not propagated (:issue:`14499`)
10 changes: 8 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3233,14 +3233,20 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,

# 3d
elif self.ndim == 3:

if axis == 0:
raise NotImplementedError('Cannot fillna with axis=0 '
'for Panel')
# fill in 2d chunks
result = dict([(col, s.fillna(method=method, value=value))
result = dict([(col, s.fillna(method=method,
value=value,
axis=axis-1))
for col, s in self.iteritems()])
new_obj = self._constructor.\
from_dict(result).__finalize__(self)
new_data = new_obj._data

def test_ffill_bfill_axis(self):

else:
# 2d or less
method = missing.clean_fill_method(method)
Expand Down
30 changes: 30 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,36 @@ def test_ffill_bfill(self):
assert_panel_equal(self.panel.bfill(),
self.panel.fillna(method='bfill'))

def test_ffill_bfill_axis(self):
#GH 14499
a = Panel({
'a':np.arange(15).reshape((5, 3)),
'b':np.arange(15, 30).reshape((5, 3))
})
f1 = a.copy()
f2 = a.copy()
b1 = a.copy()
b2 = a.copy()
a['a'].loc[1, 1] = np.nan
f1['a'].loc[1, 1] = 1
f2['a'].loc[1, 1] = 3

# method='ffill'
# axis=1
assert_panel_equal(a.ffill(axis=1), f1)

# method='ffill'
# axis=2
assert_panel_equal(a.ffill(axis=2), f2)

# method='bfill'
# axis=1
assert_panel_equal(a.bfill(axis=1), b1)

# method='bfill'
# axis=2
assert_panel_equal(a.bfill(axis=2), b2)

def test_truncate_fillna_bug(self):
# #1823
result = self.panel.truncate(before=None, after=None, axis='items')
Expand Down

0 comments on commit 45247b7

Please sign in to comment.