Skip to content

API: allow Series/Panel dropna to accept other args for compat with DataFrame (GH5233/GH5250) #5251

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
Oct 17, 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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
(:issue:`5189`, related :issue:`5004`)
- ``MultiIndex`` constructor now validates that passed levels and labels are
compatible. (:issue:`5213`, :issue:`5214`)
- Unity ``dropna`` for Series/DataFrame signature (:issue:`5250`),
tests from :issue:`5234`, courtesy of @rockg

.. _release.bug_fixes-0.13.0:

Expand Down
2 changes: 0 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2459,8 +2459,6 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
return result

axis = self._get_axis_number(axis)
if axis not in (0, 1): # pragma: no cover
raise AssertionError('axis must be 0 or 1')
agg_axis = 1 - axis

agg_obj = self
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def _reindex_multi(self, axes, copy, fill_value):
return Panel(new_values, items=new_items, major_axis=new_major,
minor_axis=new_minor)

def dropna(self, axis=0, how='any'):
def dropna(self, axis=0, how='any', **kwargs):
"""
Drop 2D from panel, holding passed axis constant

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2178,14 +2178,15 @@ def to_csv(self, path, index=True, sep=",", na_rep='',
index_label=index_label, mode=mode, nanRep=nanRep,
encoding=encoding, date_format=date_format)

def dropna(self):
def dropna(self, axis=0, **kwargs):
"""
Return Series without null values

Returns
-------
valid : Series
"""
axis = self._get_axis_number(axis or 0)
return remove_na(self)

valid = lambda self: self.dropna()
Expand Down
3 changes: 2 additions & 1 deletion pandas/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,12 @@ def cumsum(self, axis=0, dtype=None, out=None):
return self._constructor(new_array, index=self.index, sparse_index=new_array.sp_index).__finalize__(self)
return Series(new_array, index=self.index).__finalize__(self)

def dropna(self):
def dropna(self, axis=0, **kwargs):
"""
Analogous to Series.dropna. If fill_value=NaN, returns a dense Series
"""
# TODO: make more efficient
axis = self._get_axis_number(axis or 0)
dense_valid = self.to_dense().valid()
if isnull(self.fill_value):
return dense_valid
Expand Down
3 changes: 3 additions & 0 deletions pandas/stats/tests/test_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def test_series_rhs(self):
expected = ols(y=y, x={'x': x})
assert_series_equal(model.beta, expected.beta)

# GH 5233/5250
assert_series_equal(model.y_predict, model.predict(x=x))

def test_various_attributes(self):
# just make sure everything "works". test correctness elsewhere

Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3550,6 +3550,9 @@ def test_dropna_empty(self):
s = Series([])
self.assert_(len(s.dropna()) == 0)

# invalid axis
self.assertRaises(ValueError, s.dropna, axis=1)

def test_drop_duplicates(self):
s = Series([1, 2, 3, 3])

Expand Down