Skip to content

CLN: removed Panel.fillna, replacing within core/generic.py/fillna #4951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ See :ref:`Internal Refactoring<whatsnew_0130.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.
Expand Down
12 changes: 12 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
48 changes: 0 additions & 48 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 2 additions & 14 deletions pandas/tests/test_panel4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down