Skip to content

Commit

Permalink
Deprecate passing args as positional in dropna (#41504)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed May 26, 2021
1 parent db980ba commit d662e97
Show file tree
Hide file tree
Showing 5 changed files with 27 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 @@ -682,6 +682,7 @@ Deprecations
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"upper"`` and ``"lower"``) (:issue:`41485`)
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.set_index` (other than ``"keys"``) (:issue:`41485`)
- Deprecated passing arguments as positional (except for ``"levels"``) in :meth:`MultiIndex.set_levels` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41485`)
Expand Down
1 change: 1 addition & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5835,6 +5835,7 @@ def notna(self) -> DataFrame:
def notnull(self) -> DataFrame:
return ~self.isna()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def dropna(
self,
axis: Axis = 0,
Expand Down
1 change: 1 addition & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5093,6 +5093,7 @@ def notna(self) -> Series:
def notnull(self) -> Series:
return super().notnull()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def dropna(self, axis=0, inplace=False, how=None):
"""
Return a new Series with missing values removed.
Expand Down
12 changes: 12 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,15 @@ 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"In a future version of pandas all arguments of DataFrame\.dropna "
r"will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.dropna(1)
expected = DataFrame({"a": [1, 2, 3]})
tm.assert_frame_equal(result, expected)
12 changes: 12 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,15 @@ 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"In a future version of pandas all arguments of Series\.dropna "
r"will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = ser.dropna(0)
expected = Series([1, 2, 3])
tm.assert_series_equal(result, expected)

0 comments on commit d662e97

Please sign in to comment.