Skip to content

Commit 2660810

Browse files
committed
deprecate passing args as positional in dropna
1 parent b2a36bd commit 2660810

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ Deprecations
647647
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
648648
- 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`)
649649
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
650+
- Deprecated passing arguments as positional in :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41485`)
650651

651652
.. ---------------------------------------------------------------------------
652653

pandas/core/frame.py

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
Appender,
7878
Substitution,
7979
deprecate_kwarg,
80+
deprecate_nonkeyword_arguments,
8081
doc,
8182
rewrite_axis_style_signature,
8283
)
@@ -5804,6 +5805,7 @@ def notna(self) -> DataFrame:
58045805
def notnull(self) -> DataFrame:
58055806
return ~self.isna()
58065807

5808+
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
58075809
def dropna(
58085810
self,
58095811
axis: Axis = 0,

pandas/core/series.py

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from pandas.util._decorators import (
5252
Appender,
5353
Substitution,
54+
deprecate_nonkeyword_arguments,
5455
doc,
5556
)
5657
from pandas.util._validators import (
@@ -5059,6 +5060,7 @@ def notna(self) -> Series:
50595060
def notnull(self) -> Series:
50605061
return super().notnull()
50615062

5063+
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
50625064
def dropna(self, axis=0, inplace=False, how=None):
50635065
"""
50645066
Return a new Series with missing values removed.

pandas/tests/frame/methods/test_dropna.py

+10
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,13 @@ def test_dropna_with_duplicate_columns(self):
231231

232232
result = df.dropna(subset=["A", "C"], how="all")
233233
tm.assert_frame_equal(result, expected)
234+
235+
def test_dropna_pos_args_deprecation(self):
236+
# https://github.com/pandas-dev/pandas/issues/41485
237+
df = DataFrame({"a": [1, 2, 3]})
238+
msg = (
239+
r"Starting with Pandas version 2\.0 all arguments of dropna except for the "
240+
r"argument 'self' will be keyword-only"
241+
)
242+
with tm.assert_produces_warning(FutureWarning, match=msg):
243+
df.dropna(1)

pandas/tests/series/methods/test_dropna.py

+10
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,13 @@ def test_datetime64_tz_dropna(self):
101101
)
102102
assert result.dtype == "datetime64[ns, Asia/Tokyo]"
103103
tm.assert_series_equal(result, expected)
104+
105+
def test_dropna_pos_args_deprecation(self):
106+
# https://github.com/pandas-dev/pandas/issues/41485
107+
ser = Series([1, 2, 3])
108+
msg = (
109+
r"Starting with Pandas version 2\.0 all arguments of dropna except for the "
110+
r"argument 'self' will be keyword-only"
111+
)
112+
with tm.assert_produces_warning(FutureWarning, match=msg):
113+
ser.dropna(0)

0 commit comments

Comments
 (0)