From 8f7df750ef1b83b1db23b0316daf115f099da80a Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Oct 2022 17:11:43 -0700 Subject: [PATCH 1/9] DEPR: non-keyword args in mask, to_stata --- doc/source/whatsnew/v2.0.0.rst | 2 ++ pandas/core/frame.py | 7 ++----- pandas/core/generic.py | 4 +--- pandas/core/series.py | 4 +--- pandas/tests/frame/indexing/test_mask.py | 17 ----------------- pandas/tests/io/test_stata.py | 3 +-- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0880b8e2cac12..45a95b8a2cf27 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -183,6 +183,8 @@ Removal of prior version deprecations/changes - Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`) - Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`) - Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`) +- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`) - Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) - Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) - Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fb333aff66b72..1c2be53c3dde7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2621,10 +2621,10 @@ def _from_arrays( compression_options=_shared_docs["compression_options"] % "path", ) @deprecate_kwarg(old_arg_name="fname", new_arg_name="path") - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "path"]) def to_stata( self, path: FilePath | WriteBuffer[bytes], + *, convert_dates: dict[Hashable, str] | None = None, write_index: bool = True, byteorder: str | None = None, @@ -2635,7 +2635,6 @@ def to_stata( convert_strl: Sequence[Hashable] | None = None, compression: CompressionOptions = "infer", storage_options: StorageOptions = None, - *, value_labels: dict[Hashable, dict[float, str]] | None = None, ) -> None: """ @@ -11970,13 +11969,11 @@ def mask( # error: Signature of "mask" incompatible with supertype "NDFrame" @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) def mask( # type: ignore[override] self, cond, other=lib.no_default, + *, inplace: bool = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7a1026d32d4f3..5f610da42d92c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10035,9 +10035,6 @@ def mask( ... @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) @doc( where, klass=_shared_doc_kwargs["klass"], @@ -10050,6 +10047,7 @@ def mask( self: NDFrameT, cond, other=lib.no_default, + *, inplace: bool_t = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/core/series.py b/pandas/core/series.py index b7d12158fd909..c9917919fd3b0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6139,13 +6139,11 @@ def mask( # error: Signature of "mask" incompatible with supertype "NDFrame" @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) def mask( # type: ignore[override] self, cond, other=lib.no_default, + *, inplace: bool = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/tests/frame/indexing/test_mask.py b/pandas/tests/frame/indexing/test_mask.py index 3a31123da7679..e8a49ab868425 100644 --- a/pandas/tests/frame/indexing/test_mask.py +++ b/pandas/tests/frame/indexing/test_mask.py @@ -92,23 +92,6 @@ def test_mask_dtype_bool_conversion(self): result = bools.mask(mask) tm.assert_frame_equal(result, expected) - def test_mask_pos_args_deprecation(self, frame_or_series): - # https://github.com/pandas-dev/pandas/issues/41485 - obj = DataFrame({"a": range(5)}) - expected = DataFrame({"a": [-1, 1, -1, 3, -1]}) - obj = tm.get_obj(obj, frame_or_series) - expected = tm.get_obj(expected, frame_or_series) - - cond = obj % 2 == 0 - msg = ( - r"In a future version of pandas all arguments of " - f"{frame_or_series.__name__}.mask except for " - r"the arguments 'cond' and 'other' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = obj.mask(cond, -1, False) - tm.assert_equal(result, expected) - def test_mask_stringdtype(frame_or_series): # GH 40824 diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index 566b2e4cd9353..368e9d5f6e6a1 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -816,8 +816,7 @@ def test_big_dates(self, datapath): # {c : c[-2:] for c in columns} with tm.ensure_clean() as path: expected.index.name = "index" - with tm.assert_produces_warning(FutureWarning, match="keyword-only"): - expected.to_stata(path, date_conversion) + expected.to_stata(path, convert_dates=date_conversion) written_and_read_again = self.read_dta(path) tm.assert_frame_equal( written_and_read_again.set_index("index"), From f94491b79238c5aad98dfd3e695a622fa36016bb Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Oct 2022 17:18:04 -0700 Subject: [PATCH 2/9] DEPR: non-keyword args in set_axis, where --- doc/source/whatsnew/v2.0.0.rst | 2 ++ pandas/core/frame.py | 7 ++----- pandas/core/generic.py | 7 ++----- pandas/core/series.py | 6 ++---- pandas/tests/frame/indexing/test_where.py | 14 ------------- pandas/tests/frame/methods/test_set_axis.py | 23 --------------------- 6 files changed, 8 insertions(+), 51 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 45a95b8a2cf27..8486d2c49d2dc 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -185,6 +185,8 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`) - Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`) - Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523) +- Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`) - Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) - Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) - Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1c2be53c3dde7..c7891c9c7b2c5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5140,7 +5140,6 @@ def set_axis( ... # error: Signature of "set_axis" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) @Appender( """ Examples @@ -5182,9 +5181,9 @@ def set_axis( def set_axis( self, labels, + *, axis: Axis = 0, inplace: bool | lib.NoDefault = lib.no_default, - *, copy: bool | lib.NoDefault = lib.no_default, ): return super().set_axis(labels, axis=axis, inplace=inplace, copy=copy) @@ -11908,13 +11907,11 @@ def where( # error: Signature of "where" incompatible with supertype "NDFrame" @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) def where( # type: ignore[override] self, cond, other=lib.no_default, + *, inplace: bool = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5f610da42d92c..a607749a0a56b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -750,13 +750,12 @@ def set_axis( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) def set_axis( self: NDFrameT, labels, + *, axis: Axis = 0, inplace: bool_t | lib.NoDefault = lib.no_default, - *, copy: bool_t | lib.NoDefault = lib.no_default, ) -> NDFrameT | None: """ @@ -9827,9 +9826,6 @@ def where( ... @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) @doc( klass=_shared_doc_kwargs["klass"], cond="True", @@ -9841,6 +9837,7 @@ def where( self: NDFrameT, cond, other=np.nan, + *, inplace: bool_t = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/core/series.py b/pandas/core/series.py index c9917919fd3b0..59190ff0985e4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4992,7 +4992,6 @@ def set_axis( ... # error: Signature of "set_axis" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) @Appender( """ Examples @@ -5021,6 +5020,7 @@ def set_axis( def set_axis( # type: ignore[override] self, labels, + *, axis: Axis = 0, inplace: bool | lib.NoDefault = lib.no_default, copy: bool | lib.NoDefault = lib.no_default, @@ -6078,13 +6078,11 @@ def where( # error: Signature of "where" incompatible with supertype "NDFrame" @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "cond", "other"] - ) def where( # type: ignore[override] self, cond, other=lib.no_default, + *, inplace: bool = False, axis: Axis | None = None, level: Level = None, diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index ea559230d1595..1212659ea24e2 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -863,20 +863,6 @@ def test_where_duplicate_axes_mixed_dtypes(): tm.assert_frame_equal(c.astype("f8"), d.astype("f8")) -def test_where_non_keyword_deprecation(frame_or_series): - # GH 41485 - obj = frame_or_series(range(5)) - msg = ( - "In a future version of pandas all arguments of " - f"{frame_or_series.__name__}.where except for the arguments 'cond' " - "and 'other' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = obj.where(obj > 1, 10, False) - expected = frame_or_series([10, 10, 2, 3, 4]) - tm.assert_equal(expected, result) - - def test_where_columns_casting(): # GH 42295 diff --git a/pandas/tests/frame/methods/test_set_axis.py b/pandas/tests/frame/methods/test_set_axis.py index f105a38e6fdd0..8e597e1e9fa69 100644 --- a/pandas/tests/frame/methods/test_set_axis.py +++ b/pandas/tests/frame/methods/test_set_axis.py @@ -168,26 +168,3 @@ class TestSeriesSetAxis(SharedSetAxisTests): def obj(self): ser = Series(np.arange(4), index=[1, 3, 5, 7], dtype="int64") return ser - - -def test_nonkeyword_arguments_deprecation_warning(): - # 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\.set_axis " - r"except for the argument 'labels' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.set_axis([1, 2, 4], 0) - expected = DataFrame({"a": [1, 2, 3]}, index=[1, 2, 4]) - tm.assert_frame_equal(result, expected) - - ser = Series([1, 2, 3]) - msg = ( - r"In a future version of pandas all arguments of Series\.set_axis " - r"except for the argument 'labels' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.set_axis([1, 2, 4], 0) - expected = Series([1, 2, 3], index=[1, 2, 4]) - tm.assert_series_equal(result, expected) From 1ae6a3b5bbc53ce04b9b624b61936324ed33004a Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Oct 2022 17:59:41 -0700 Subject: [PATCH 3/9] DEPR: non-keyword args in rename_axis, clip --- doc/source/whatsnew/v2.0.0.rst | 2 ++ pandas/core/frame.py | 7 ++----- pandas/core/generic.py | 6 +++--- pandas/core/series.py | 7 ++----- pandas/tests/frame/methods/test_clip.py | 12 ------------ pandas/tests/series/methods/test_clip.py | 12 ------------ 6 files changed, 9 insertions(+), 37 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 8486d2c49d2dc..423165fa68747 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -187,6 +187,8 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`) - Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523) - Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`) +- Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`) +- Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`) - Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) - Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) - Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c7891c9c7b2c5..35b61eb5bb3c4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11829,19 +11829,16 @@ def bfill( # type: ignore[override] ) -> DataFrame | None: return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "lower", "upper"] - ) def clip( self: DataFrame, lower: float | None = None, upper: float | None = None, + *, axis: Axis | None = None, inplace: bool = False, - *args, **kwargs, ) -> DataFrame | None: - return super().clip(lower, upper, axis, inplace, *args, **kwargs) + return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs) @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"]) def interpolate( diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a607749a0a56b..b57aa5405b899 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1153,10 +1153,10 @@ def rename_axis( ... @rewrite_axis_style_signature("mapper", [("copy", True)]) - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "mapper"]) def rename_axis( self: NDFrameT, mapper: IndexLabel | lib.NoDefault = lib.no_default, + *, inplace: bool_t = False, **kwargs, ) -> NDFrameT | None: @@ -7999,9 +7999,9 @@ def clip( self: NDFrameT, lower=None, upper=None, + *, axis: Axis | None = None, inplace: bool_t = False, - *args, **kwargs, ) -> NDFrameT | None: """ @@ -8104,7 +8104,7 @@ def clip( """ inplace = validate_bool_kwarg(inplace, "inplace") - axis = nv.validate_clip_with_axis(axis, args, kwargs) + axis = nv.validate_clip_with_axis(axis, (), kwargs) if axis is not None: axis = self._get_axis_number(axis) diff --git a/pandas/core/series.py b/pandas/core/series.py index 59190ff0985e4..59d1f76cb3124 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -6000,19 +6000,16 @@ def bfill( # type: ignore[override] ) -> Series | None: return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "lower", "upper"] - ) def clip( self: Series, lower=None, upper=None, + *, axis: Axis | None = None, inplace: bool = False, - *args, **kwargs, ) -> Series | None: - return super().clip(lower, upper, axis, inplace, *args, **kwargs) + return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs) @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"]) def interpolate( diff --git a/pandas/tests/frame/methods/test_clip.py b/pandas/tests/frame/methods/test_clip.py index c851e65a7ad4f..f8d9adf44dbc2 100644 --- a/pandas/tests/frame/methods/test_clip.py +++ b/pandas/tests/frame/methods/test_clip.py @@ -164,15 +164,3 @@ def test_clip_with_na_args(self, float_frame): result = df.clip(lower=t, axis=0) expected = DataFrame({"col_0": [9, -3, 0, 6, 5], "col_1": [2, -4, 6, 8, 3]}) tm.assert_frame_equal(result, expected) - - def test_clip_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.clip except " - r"for the arguments 'lower' and 'upper' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.clip(0, 1, 0) - expected = DataFrame({"a": [1, 1, 1]}) - tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/series/methods/test_clip.py b/pandas/tests/series/methods/test_clip.py index bc6d5aeb0a581..b123e8a12a852 100644 --- a/pandas/tests/series/methods/test_clip.py +++ b/pandas/tests/series/methods/test_clip.py @@ -137,15 +137,3 @@ def test_clip_with_timestamps_and_oob_datetimes(self): expected = Series([Timestamp.min, Timestamp.max], dtype="object") tm.assert_series_equal(result, expected) - - def test_clip_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.clip except " - r"for the arguments 'lower' and 'upper' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.clip(0, 1, 0) - expected = Series([1, 1, 1]) - tm.assert_series_equal(result, expected) From 885b3db101ea4bace3cbfb5c0052a99fba0e2879 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Oct 2022 19:38:22 -0700 Subject: [PATCH 4/9] DEPR: non-keyword arguments in ffill, bfill --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/frame.py | 10 ++++----- pandas/core/generic.py | 4 ++-- pandas/core/series.py | 10 ++++----- pandas/tests/frame/methods/test_fillna.py | 24 ---------------------- pandas/tests/series/methods/test_fillna.py | 24 ---------------------- 6 files changed, 11 insertions(+), 62 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 423165fa68747..f70556a585a50 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -189,6 +189,7 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`) - Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`) - Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`) +- Disallow passing non-keyword arguments to :meth:`Series.bfill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill` and :meth:`DataFrame.ffill` (:issue:`41508`) - Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) - Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) - Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 35b61eb5bb3c4..c703db78c14b3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11774,10 +11774,9 @@ def ffill( ) -> DataFrame | None: ... - # error: Signature of "ffill" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def ffill( # type: ignore[override] + def ffill( self, + *, axis: None | Axis = None, inplace: bool = False, limit: None | int = None, @@ -11818,10 +11817,9 @@ def bfill( ) -> DataFrame | None: ... - # error: Signature of "bfill" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def bfill( # type: ignore[override] + def bfill( self, + *, axis: None | Axis = None, inplace: bool = False, limit: None | int = None, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b57aa5405b899..7b291300e3433 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7006,10 +7006,10 @@ def ffill( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(klass=_shared_doc_kwargs["klass"]) def ffill( self: NDFrameT, + *, axis: None | Axis = None, inplace: bool_t = False, limit: None | int = None, @@ -7062,10 +7062,10 @@ def bfill( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) @doc(klass=_shared_doc_kwargs["klass"]) def bfill( self: NDFrameT, + *, axis: None | Axis = None, inplace: bool_t = False, limit: None | int = None, diff --git a/pandas/core/series.py b/pandas/core/series.py index 59d1f76cb3124..b98730527edf2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5945,10 +5945,9 @@ def ffill( ) -> Series | None: ... - # error: Signature of "ffill" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def ffill( # type: ignore[override] + def ffill( self, + *, axis: None | Axis = None, inplace: bool = False, limit: None | int = None, @@ -5989,10 +5988,9 @@ def bfill( ) -> Series | None: ... - # error: Signature of "bfill" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def bfill( # type: ignore[override] + def bfill( self, + *, axis: None | Axis = None, inplace: bool = False, limit: None | int = None, diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index ccd564b46cffa..869cd32aa9ef9 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -399,18 +399,6 @@ def test_ffill(self, datetime_frame): datetime_frame.ffill(), datetime_frame.fillna(method="ffill") ) - def test_ffill_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.ffill " - r"will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.ffill(0) - expected = DataFrame({"a": [1, 2, 3]}) - tm.assert_frame_equal(result, expected) - def test_bfill(self, datetime_frame): datetime_frame["A"][:5] = np.nan datetime_frame["A"][-5:] = np.nan @@ -419,18 +407,6 @@ def test_bfill(self, datetime_frame): datetime_frame.bfill(), datetime_frame.fillna(method="bfill") ) - def test_bfill_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.bfill " - r"will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.bfill(0) - expected = DataFrame({"a": [1, 2, 3]}) - tm.assert_frame_equal(result, expected) - def test_frame_pad_backfill_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index ac12b513aad4e..26416c7a2b483 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -888,18 +888,6 @@ def test_ffill(self): ts[2] = np.NaN tm.assert_series_equal(ts.ffill(), ts.fillna(method="ffill")) - def test_ffill_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.ffill " - r"will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.ffill(0) - expected = Series([1, 2, 3]) - tm.assert_series_equal(result, expected) - def test_ffill_mixed_dtypes_without_missing_data(self): # GH#14956 series = Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1]) @@ -911,18 +899,6 @@ def test_bfill(self): ts[2] = np.NaN tm.assert_series_equal(ts.bfill(), ts.fillna(method="bfill")) - def test_bfill_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.bfill " - r"will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.bfill(0) - expected = Series([1, 2, 3]) - tm.assert_series_equal(result, expected) - def test_pad_nan(self): x = Series( [np.nan, 1.0, np.nan, 3.0, np.nan], ["z", "a", "b", "c", "d"], dtype=float From 742e9648c20124a5148c3779639f09aa4036b116 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 22 Oct 2022 20:20:03 -0700 Subject: [PATCH 5/9] DEPR: non-keyword arguments in replace, sort_values --- doc/source/whatsnew/v2.0.0.rst | 3 +++ pandas/core/frame.py | 6 ++---- pandas/core/generic.py | 6 ++---- pandas/core/series.py | 9 +++------ pandas/tests/frame/methods/test_sort_values.py | 12 ------------ pandas/tests/series/methods/test_sort_values.py | 12 ------------ 6 files changed, 10 insertions(+), 38 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index f70556a585a50..035322e31505c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -190,6 +190,9 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`) - Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`) - Disallow passing non-keyword arguments to :meth:`Series.bfill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill` and :meth:`DataFrame.ffill` (:issue:`41508`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.replace`, :meth:`Series.replace` except for ``to_replace`` and ``value`` (:issue:`47587`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_values` except for ``by`` (:issue:`41505`) +- Disallow passing non-keyword arguments to :meth:`Series.sort_values` (:issue:`41505`) - Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) - Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) - Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c703db78c14b3..0cac5d621fd0c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5717,14 +5717,12 @@ def replace( ... # error: Signature of "replace" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "to_replace", "value"] - ) @doc(NDFrame.replace, **_shared_doc_kwargs) def replace( # type: ignore[override] self, to_replace=None, value=lib.no_default, + *, inplace: bool = False, limit: int | None = None, regex: bool = False, @@ -6866,12 +6864,12 @@ def sort_values( # TODO: Just move the sort_values doc here. # error: Signature of "sort_values" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "by"]) @Substitution(**_shared_doc_kwargs) @Appender(NDFrame.sort_values.__doc__) def sort_values( # type: ignore[override] self, by: IndexLabel, + *, axis: Axis = 0, ascending: bool | list[bool] | tuple[bool, ...] = True, inplace: bool = False, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7b291300e3433..27e2ff4b8914e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4812,9 +4812,9 @@ def sort_values( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) def sort_values( self: NDFrameT, + *, axis: Axis = 0, ascending: bool_t | Sequence[bool_t] = True, inplace: bool_t = False, @@ -7124,9 +7124,6 @@ def replace( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "to_replace", "value"] - ) @doc( _shared_docs["replace"], klass=_shared_doc_kwargs["klass"], @@ -7137,6 +7134,7 @@ def replace( self: NDFrameT, to_replace=None, value=lib.no_default, + *, inplace: bool_t = False, limit: int | None = None, regex: bool_t = False, diff --git a/pandas/core/series.py b/pandas/core/series.py index b98730527edf2..bafc90ee4cf5b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3523,10 +3523,9 @@ def sort_values( ) -> None: ... - # error: Signature of "sort_values" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self"]) - def sort_values( # type: ignore[override] + def sort_values( self, + *, axis: Axis = 0, ascending: bool | int | Sequence[bool] | Sequence[int] = True, inplace: bool = False, @@ -5313,9 +5312,6 @@ def replace( ... # error: Signature of "replace" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "to_replace", "value"] - ) @doc( NDFrame.replace, klass=_shared_doc_kwargs["klass"], @@ -5326,6 +5322,7 @@ def replace( # type: ignore[override] self, to_replace=None, value=lib.no_default, + *, inplace: bool = False, limit: int | None = None, regex: bool = False, diff --git a/pandas/tests/frame/methods/test_sort_values.py b/pandas/tests/frame/methods/test_sort_values.py index 51b590263f893..d7f1d900db052 100644 --- a/pandas/tests/frame/methods/test_sort_values.py +++ b/pandas/tests/frame/methods/test_sort_values.py @@ -860,18 +860,6 @@ def test_sort_column_level_and_index_label( tm.assert_frame_equal(result, expected) - def test_sort_values_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\.sort_values " - r"except for the argument 'by' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.sort_values("a", 0) - expected = DataFrame({"a": [1, 2, 3]}) - tm.assert_frame_equal(result, expected) - def test_sort_values_validate_ascending_for_value_error(self): # GH41634 df = DataFrame({"D": [23, 7, 21]}) diff --git a/pandas/tests/series/methods/test_sort_values.py b/pandas/tests/series/methods/test_sort_values.py index adc578d948163..b5f589b3b2514 100644 --- a/pandas/tests/series/methods/test_sort_values.py +++ b/pandas/tests/series/methods/test_sort_values.py @@ -187,18 +187,6 @@ def test_sort_values_ignore_index( tm.assert_series_equal(result_ser, expected) tm.assert_series_equal(ser, Series(original_list)) - def test_sort_values_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\.sort_values " - r"will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.sort_values(0) - expected = Series([1, 2, 3]) - tm.assert_series_equal(result, expected) - def test_mergesort_decending_stability(self): # GH 28697 s = Series([1, 2, 1, 3], ["first", "b", "second", "c"]) From 5c0c036dc413aed794288c6455175a233fbe29f2 Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 23 Oct 2022 07:29:36 -0700 Subject: [PATCH 6/9] typo fixup --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 035322e31505c..921c8af0aa346 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -185,7 +185,7 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`) - Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`) - Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`) -- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523) +- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523`) - Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`) - Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`) - Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`) From 662412e08b4e200aceb6f85649dfddece871c9aa Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 23 Oct 2022 10:42:27 -0700 Subject: [PATCH 7/9] fix asv --- asv_bench/benchmarks/io/stata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asv_bench/benchmarks/io/stata.py b/asv_bench/benchmarks/io/stata.py index 4ae2745af8bff..5942cbe01876f 100644 --- a/asv_bench/benchmarks/io/stata.py +++ b/asv_bench/benchmarks/io/stata.py @@ -44,7 +44,7 @@ def time_read_stata(self, convert_dates): read_stata(self.fname) def time_write_stata(self, convert_dates): - self.df.to_stata(self.fname, self.convert_dates) + self.df.to_stata(self.fname, convert_dates=self.convert_dates) class StataMissing(Stata): From e4f36ed318d169c4476155e740c483d17a10566b Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 23 Oct 2022 14:55:22 -0700 Subject: [PATCH 8/9] troubleshoot asvs --- asv_bench/benchmarks/io/stata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asv_bench/benchmarks/io/stata.py b/asv_bench/benchmarks/io/stata.py index 5942cbe01876f..52c9d29fc0d95 100644 --- a/asv_bench/benchmarks/io/stata.py +++ b/asv_bench/benchmarks/io/stata.py @@ -54,7 +54,7 @@ def setup(self, convert_dates): missing_data = np.random.randn(self.N) missing_data[missing_data < 0] = np.nan self.df[f"missing_{i}"] = missing_data - self.df.to_stata(self.fname, self.convert_dates) + self.df.to_stata(self.fname, convert_dates=self.convert_dates) from ..pandas_vb_common import setup # noqa: F401 isort:skip From 4bd4921b73e0a6ed3645d8795ef21078adc81ede Mon Sep 17 00:00:00 2001 From: Brock Date: Sun, 23 Oct 2022 17:17:12 -0700 Subject: [PATCH 9/9] update asv --- asv_bench/benchmarks/io/stata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asv_bench/benchmarks/io/stata.py b/asv_bench/benchmarks/io/stata.py index 52c9d29fc0d95..1ff929d6dbdea 100644 --- a/asv_bench/benchmarks/io/stata.py +++ b/asv_bench/benchmarks/io/stata.py @@ -38,7 +38,7 @@ def setup(self, convert_dates): ) self.df["float32_"] = np.array(np.random.randn(N), dtype=np.float32) self.convert_dates = {"index": convert_dates} - self.df.to_stata(self.fname, self.convert_dates) + self.df.to_stata(self.fname, convert_dates=self.convert_dates) def time_read_stata(self, convert_dates): read_stata(self.fname)