Skip to content

Commit cfb3882

Browse files
committed
BUGFIX: fillNA for panel (ndim==3) Issue: 12624
closes pandas-dev#12624
1 parent a5670f2 commit cfb3882

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

doc/source/whatsnew/v0.18.1.txt

+4-33
Original file line numberDiff line numberDiff line change
@@ -89,46 +89,17 @@ Bug Fixes
8989
~~~~~~~~~
9090

9191
- Bug in ``Period`` and ``PeriodIndex`` creation raises ``KeyError`` if ``freq="Minute"`` is specified. Note that "Minute" freq is deprecated in v0.17.0, and recommended to use ``freq="T"`` instead (:issue:`11854`)
92-
- Bug in ``Series`` construction with ``Categorical`` and ``dtype='category'`` is specified (:issue:`12574`)
93-
94-
95-
96-
97-
98-
99-
10092

93+
- Bug in ``Series`` construction with ``Categorical`` and ``dtype='category'`` is specified (:issue:`12574`)
10194

95+
- BUG: Can't get period code with frequency alias 'minute' or 'Minute'
10296

10397
- Bug in ``value_counts`` when ``normalize=True`` and ``dropna=True`` where nulls still contributed to the normalized count (:issue:`12558`)
10498

105-
106-
107-
108-
109-
110-
111-
112-
113-
114-
115-
11699
- Bug in ``CategoricalIndex.get_loc`` returns different result from regular ``Index`` (:issue:`12531`)
117100

101+
- Bug in ``Panel.fillna()`` ignores ``inplace=True`` (:issue:`12633`)
118102

119-
120-
121-
122-
123-
124-
125-
126-
127-
128-
129-
130-
131-
132-
103+
- BUG: Crosstab with margins=True ignoring dropna=True
133104

134105
- Bug in ``pivot_table`` when ``margins=True`` and ``dropna=True`` where nulls still contributed to margin count (:issue:`12577`)

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')

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)