Skip to content
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

Deprecate passing args as positional in dropna #41504

Merged
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably share this test using frame_or_series fixture?

# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar as in other PRs, can you still assert the result?

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)