diff --git a/doc/source/release.rst b/doc/source/release.rst index 33e421fa55960..efde15bc23d3c 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -254,7 +254,8 @@ See :ref:`Internal Refactoring` - ``swapaxes`` on a ``Panel`` with the same axes specified now return a copy - support attribute access for setting - - filter supports same api as original ``DataFrame`` filter + - ``filter`` supports same api as original ``DataFrame`` filter + - ``fillna`` refactored to ``core/generic.py``, while > 3ndim is ``NotImplemented`` - Series now inherits from ``NDFrame`` rather than directly from ``ndarray``. There are several minor changes that affect the API. diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 36c3ff9085d87..4553e4804e98b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1569,6 +1569,18 @@ def fillna(self, value=None, method=None, axis=0, inplace=False, return result + # > 3d + if self.ndim > 3: + raise NotImplementedError('cannot fillna with a method for > 3dims') + + # 3d + elif self.ndim == 3: + + # fill in 2d chunks + result = dict([ (col,s.fillna(method=method, value=value)) for col, s in compat.iteritems(self) ]) + return self._constructor.from_dict(result) + + # 2d or less method = com._clean_fill_method(method) new_data = self._data.interpolate(method=method, axis=axis, diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 45101b1e2afd5..5f90eb9fa31a7 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -750,54 +750,6 @@ def _combine_panel(self, other, func): return self._constructor(result_values, items, major, minor) - def fillna(self, value=None, method=None): - """ - Fill NaN values using the specified method. - - Member Series / TimeSeries are filled separately. - - Parameters - ---------- - value : any kind (should be same type as array) - Value to use to fill holes (e.g. 0) - - method : {'backfill', 'bfill', 'pad', 'ffill', None}, default 'pad' - Method to use for filling holes in reindexed Series - - pad / ffill: propagate last valid observation forward to next valid - backfill / bfill: use NEXT valid observation to fill gap - - Returns - ------- - y : DataFrame - - See also - -------- - DataFrame.reindex, DataFrame.asfreq - """ - if isinstance(value, (list, tuple)): - raise TypeError('"value" parameter must be a scalar or dict, but ' - 'you passed a "{0}"'.format(type(value).__name__)) - if value is None: - if method is None: - raise ValueError('must specify a fill method or value') - result = {} - for col, s in compat.iteritems(self): - result[col] = s.fillna(method=method, value=value) - - return self._constructor.from_dict(result) - else: - if method is not None: - raise ValueError('cannot specify both a fill method and value') - new_data = self._data.fillna(value) - return self._constructor(new_data) - - def ffill(self): - return self.fillna(method='ffill') - - def bfill(self): - return self.fillna(method='bfill') - def major_xs(self, key, copy=True): """ Return slice of panel along major axis diff --git a/pandas/tests/test_panel4d.py b/pandas/tests/test_panel4d.py index 9b34631ecc894..4f7e75b401216 100644 --- a/pandas/tests/test_panel4d.py +++ b/pandas/tests/test_panel4d.py @@ -849,23 +849,11 @@ def test_sort_index(self): # assert_panel_equal(sorted_panel, self.panel) def test_fillna(self): + self.assert_(not np.isfinite(self.panel4d.values).all()) filled = self.panel4d.fillna(0) self.assert_(np.isfinite(filled.values).all()) - filled = self.panel4d.fillna(method='backfill') - assert_panel_equal(filled['l1'], - self.panel4d['l1'].fillna(method='backfill')) - - panel4d = self.panel4d.copy() - panel4d['str'] = 'foo' - - filled = panel4d.fillna(method='backfill') - assert_panel_equal(filled['l1'], - panel4d['l1'].fillna(method='backfill')) - - empty = self.panel4d.reindex(labels=[]) - filled = empty.fillna(0) - assert_panel4d_equal(filled, empty) + self.assertRaises(NotImplementedError, self.panel4d.fillna, method='pad') def test_swapaxes(self): result = self.panel4d.swapaxes('labels', 'items')