Skip to content

Commit e4aa7c7

Browse files
MarcoGorelliJulianWgs
authored andcommitted
Deprecate passing args as positional in dropna (pandas-dev#41504)
1 parent 24cd863 commit e4aa7c7

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ Deprecations
682682
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"upper"`` and ``"lower"``) (:issue:`41485`)
683683
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
684684
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
685+
- Deprecated passing arguments as positional in :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41485`)
685686
- Deprecated passing arguments as positional in :meth:`DataFrame.set_index` (other than ``"keys"``) (:issue:`41485`)
686687
- Deprecated passing arguments as positional (except for ``"levels"``) in :meth:`MultiIndex.set_levels` (:issue:`41485`)
687688
- Deprecated passing arguments as positional in :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41485`)

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -5835,6 +5835,7 @@ def notna(self) -> DataFrame:
58355835
def notnull(self) -> DataFrame:
58365836
return ~self.isna()
58375837

5838+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
58385839
def dropna(
58395840
self,
58405841
axis: Axis = 0,

pandas/core/series.py

+1
Original file line numberDiff line numberDiff line change
@@ -5093,6 +5093,7 @@ def notna(self) -> Series:
50935093
def notnull(self) -> Series:
50945094
return super().notnull()
50955095

5096+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
50965097
def dropna(self, axis=0, inplace=False, how=None):
50975098
"""
50985099
Return a new Series with missing values removed.

pandas/tests/frame/methods/test_dropna.py

+12
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ 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"In a future version of pandas all arguments of DataFrame\.dropna "
240+
r"will be keyword-only"
241+
)
242+
with tm.assert_produces_warning(FutureWarning, match=msg):
243+
result = df.dropna(1)
244+
expected = DataFrame({"a": [1, 2, 3]})
245+
tm.assert_frame_equal(result, expected)

pandas/tests/series/methods/test_dropna.py

+12
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,15 @@ 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"In a future version of pandas all arguments of Series\.dropna "
110+
r"will be keyword-only"
111+
)
112+
with tm.assert_produces_warning(FutureWarning, match=msg):
113+
result = ser.dropna(0)
114+
expected = Series([1, 2, 3])
115+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)