Skip to content

Commit ab359c1

Browse files
Xbarjreback
authored andcommitted
BUG: #12624 where Panel.fillna() ignores inplace=True
Added if condition for fillna when ndim==3 (for Panel) Issue: #12624 Author: Xbar <wishyx@gmail.com> Closes #12633 from Xbar/master and squashes the following commits: cfb3882 [Xbar] BUGFIX: fillNA for panel (ndim==3) Issue: 12624
1 parent 1893ffd commit ab359c1

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

Diff for: doc/source/whatsnew/v0.18.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Bug Fixes
103103

104104

105105
- Bug in ``value_counts`` when ``normalize=True`` and ``dropna=True`` where nulls still contributed to the normalized count (:issue:`12558`)
106+
- Bug in ``Panel.fillna()`` ignoring ``inplace=True`` (:issue:`12633`)
106107

107108

108109

Diff for: pandas/core/generic.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -3124,13 +3124,17 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
31243124
# fill in 2d chunks
31253125
result = dict([(col, s.fillna(method=method, value=value))
31263126
for col, s in self.iteritems()])
3127-
return self._constructor.from_dict(result).__finalize__(self)
3127+
new_obj = self._constructor.\
3128+
from_dict(result).__finalize__(self)
3129+
new_data = new_obj._data
31283130

3129-
# 2d or less
3130-
method = mis._clean_fill_method(method)
3131-
new_data = self._data.interpolate(method=method, axis=axis,
3132-
limit=limit, inplace=inplace,
3133-
coerce=True, downcast=downcast)
3131+
else:
3132+
# 2d or less
3133+
method = mis._clean_fill_method(method)
3134+
new_data = self._data.interpolate(method=method, axis=axis,
3135+
limit=limit, inplace=inplace,
3136+
coerce=True,
3137+
downcast=downcast)
31343138
else:
31353139
if method is not None:
31363140
raise ValueError('cannot specify both a fill method and value')

Diff for: pandas/tests/test_panel.py

+18
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,24 @@ def test_fillna(self):
15281528
p.iloc[0:2, 0:2, 0:2] = np.nan
15291529
self.assertRaises(NotImplementedError, lambda: p.fillna(999, limit=1))
15301530

1531+
# Test in place fillNA
1532+
# Expected result
1533+
expected = Panel([[[0, 1], [2, 1]], [[10, 11], [12, 11]]],
1534+
items=['a', 'b'], minor_axis=['x', 'y'],
1535+
dtype=np.float64)
1536+
# method='ffill'
1537+
p1 = Panel([[[0, 1], [2, np.nan]], [[10, 11], [12, np.nan]]],
1538+
items=['a', 'b'], minor_axis=['x', 'y'],
1539+
dtype=np.float64)
1540+
p1.fillna(method='ffill', inplace=True)
1541+
assert_panel_equal(p1, expected)
1542+
1543+
# method='bfill'
1544+
p2 = Panel([[[0, np.nan], [2, 1]], [[10, np.nan], [12, 11]]],
1545+
items=['a', 'b'], minor_axis=['x', 'y'], dtype=np.float64)
1546+
p2.fillna(method='bfill', inplace=True)
1547+
assert_panel_equal(p2, expected)
1548+
15311549
def test_ffill_bfill(self):
15321550
assert_panel_equal(self.panel.ffill(),
15331551
self.panel.fillna(method='ffill'))

0 commit comments

Comments
 (0)