Skip to content

Commit b7e8b6f

Browse files
committed
Merge pull request #5251 from jreback/dropna
API: allow Series/Panel dropna to accept other args for compat with DataFrame (GH5233/GH5250)
2 parents 79607c5 + 2cdda0c commit b7e8b6f

File tree

7 files changed

+13
-5
lines changed

7 files changed

+13
-5
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
409409
(:issue:`5189`, related :issue:`5004`)
410410
- ``MultiIndex`` constructor now validates that passed levels and labels are
411411
compatible. (:issue:`5213`, :issue:`5214`)
412+
- Unity ``dropna`` for Series/DataFrame signature (:issue:`5250`),
413+
tests from :issue:`5234`, courtesy of @rockg
412414

413415
.. _release.bug_fixes-0.13.0:
414416

pandas/core/frame.py

-2
Original file line numberDiff line numberDiff line change
@@ -2459,8 +2459,6 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
24592459
return result
24602460

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

24662464
agg_obj = self

pandas/core/panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def _reindex_multi(self, axes, copy, fill_value):
615615
return Panel(new_values, items=new_items, major_axis=new_major,
616616
minor_axis=new_minor)
617617

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

pandas/core/series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2178,14 +2178,15 @@ def to_csv(self, path, index=True, sep=",", na_rep='',
21782178
index_label=index_label, mode=mode, nanRep=nanRep,
21792179
encoding=encoding, date_format=date_format)
21802180

2181-
def dropna(self):
2181+
def dropna(self, axis=0, **kwargs):
21822182
"""
21832183
Return Series without null values
21842184
21852185
Returns
21862186
-------
21872187
valid : Series
21882188
"""
2189+
axis = self._get_axis_number(axis or 0)
21892190
return remove_na(self)
21902191

21912192
valid = lambda self: self.dropna()

pandas/sparse/series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,12 @@ def cumsum(self, axis=0, dtype=None, out=None):
569569
return self._constructor(new_array, index=self.index, sparse_index=new_array.sp_index).__finalize__(self)
570570
return Series(new_array, index=self.index).__finalize__(self)
571571

572-
def dropna(self):
572+
def dropna(self, axis=0, **kwargs):
573573
"""
574574
Analogous to Series.dropna. If fill_value=NaN, returns a dense Series
575575
"""
576576
# TODO: make more efficient
577+
axis = self._get_axis_number(axis or 0)
577578
dense_valid = self.to_dense().valid()
578579
if isnull(self.fill_value):
579580
return dense_valid

pandas/stats/tests/test_ols.py

+3
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ def test_series_rhs(self):
379379
expected = ols(y=y, x={'x': x})
380380
assert_series_equal(model.beta, expected.beta)
381381

382+
# GH 5233/5250
383+
assert_series_equal(model.y_predict, model.predict(x=x))
384+
382385
def test_various_attributes(self):
383386
# just make sure everything "works". test correctness elsewhere
384387

pandas/tests/test_series.py

+3
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,9 @@ def test_dropna_empty(self):
35503550
s = Series([])
35513551
self.assert_(len(s.dropna()) == 0)
35523552

3553+
# invalid axis
3554+
self.assertRaises(ValueError, s.dropna, axis=1)
3555+
35533556
def test_drop_duplicates(self):
35543557
s = Series([1, 2, 3, 3])
35553558

0 commit comments

Comments
 (0)