Skip to content

Commit

Permalink
deprecate passing args as positional in dropna
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed May 16, 2021
1 parent b2a36bd commit 2660810
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ Deprecations
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`)
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
- Deprecated passing arguments as positional in :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41485`)

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
Appender,
Substitution,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
rewrite_axis_style_signature,
)
Expand Down Expand Up @@ -5804,6 +5805,7 @@ def notna(self) -> DataFrame:
def notnull(self) -> DataFrame:
return ~self.isna()

@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
def dropna(
self,
axis: Axis = 0,
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._validators import (
Expand Down Expand Up @@ -5059,6 +5060,7 @@ def notna(self) -> Series:
def notnull(self) -> Series:
return super().notnull()

@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
def dropna(self, axis=0, inplace=False, how=None):
"""
Return a new Series with missing values removed.
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/methods/test_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,13 @@ def test_dropna_with_duplicate_columns(self):

result = df.dropna(subset=["A", "C"], how="all")
tm.assert_frame_equal(result, expected)

def test_dropna_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
df = DataFrame({"a": [1, 2, 3]})
msg = (
r"Starting with Pandas version 2\.0 all arguments of dropna except for the "
r"argument 'self' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
df.dropna(1)
10 changes: 10 additions & 0 deletions pandas/tests/series/methods/test_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,13 @@ def test_datetime64_tz_dropna(self):
)
assert result.dtype == "datetime64[ns, Asia/Tokyo]"
tm.assert_series_equal(result, expected)

def test_dropna_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
ser = Series([1, 2, 3])
msg = (
r"Starting with Pandas version 2\.0 all arguments of dropna except for the "
r"argument 'self' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
ser.dropna(0)

0 comments on commit 2660810

Please sign in to comment.