From 2637df9f5fba3038579fc0d2c56cca6fe532cfdb Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 3 Nov 2022 13:24:52 -0700 Subject: [PATCH] DEPR: enforce non-positional, keyword deprecations --- doc/source/whatsnew/v2.0.0.rst | 4 ++++ pandas/core/frame.py | 8 +++----- pandas/core/generic.py | 24 +--------------------- pandas/core/series.py | 9 +++----- pandas/tests/frame/methods/test_fillna.py | 12 ----------- pandas/tests/io/formats/test_to_csv.py | 4 +--- pandas/tests/series/methods/test_drop.py | 13 ------------ pandas/tests/series/methods/test_fillna.py | 12 ----------- 8 files changed, 12 insertions(+), 74 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index b7995dca0a825..1bf732bd3f644 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -293,6 +293,8 @@ Removal of prior version deprecations/changes - Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`) - Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`) - Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`) +- Removed arguments ``verbose`` and ``encoding`` from :meth:`DataFrame.to_excel` and :meth:`Series.to_excel` (:issue:`47912`) +- Removed argument ``line_terminator`` from :meth:`DataFrame.to_csv` and :meth:`Series.to_csv`, use ``lineterminator`` instead (:issue:`45302`) - Removed argument ``inplace`` from :meth:`DataFrame.set_axis` and :meth:`Series.set_axis`, use ``obj = obj.set_axis(..., copy=False)`` instead (:issue:`48130`) - Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`) - Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`) @@ -310,6 +312,8 @@ Removal of prior version deprecations/changes - Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`) - Removed ``errors`` keyword from :meth:`DataFrame.where`, :meth:`Series.where`, :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`47728`) - Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.drop` and :meth:`Series.drop` except ``labels`` (:issue:`41486`) +- Disallow passing non-keyword arguments to :meth:`DataFrame.fillna` and :meth:`Series.fillna` except ``value`` (:issue:`41485`) - Disallow passing non-keyword arguments to :meth:`StringMethods.split` and :meth:`StringMethods.rsplit` except for ``pat`` (:issue:`47448`) - Disallow passing non-keyword arguments to :meth:`DataFrame.set_index` except ``keys`` (:issue:`41495`) - Disallow passing non-keyword arguments to :meth:`Resampler.interpolate` except ``method`` (:issue:`41699`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 58859054943b3..c51a12acff530 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5157,12 +5157,10 @@ def drop( ) -> DataFrame | None: ... - # error: Signature of "drop" incompatible with supertype "NDFrame" - # github.com/python/mypy/issues/12387 - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) - def drop( # type: ignore[override] + def drop( self, labels: IndexLabel = None, + *, axis: Axis = 0, index: IndexLabel = None, columns: IndexLabel = None, @@ -5532,11 +5530,11 @@ def fillna( ... # error: Signature of "fillna" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"]) @doc(NDFrame.fillna, **_shared_doc_kwargs) def fillna( # type: ignore[override] self, value: Hashable | Mapping | Series | DataFrame = None, + *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f88fe35360074..cdb863eae3b99 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -87,8 +87,6 @@ SettingWithCopyWarning, ) from pandas.util._decorators import ( - deprecate_kwarg, - deprecate_nonkeyword_arguments, doc, rewrite_axis_style_signature, ) @@ -2131,8 +2129,6 @@ def _repr_data_resource_(self): # I/O Methods @final - @deprecate_kwarg(old_arg_name="verbose", new_arg_name=None) - @deprecate_kwarg(old_arg_name="encoding", new_arg_name=None) @doc( klass="object", storage_options=_shared_docs["storage_options"], @@ -2152,9 +2148,7 @@ def to_excel( startcol: int = 0, engine: str | None = None, merge_cells: bool_t = True, - encoding: lib.NoDefault = lib.no_default, inf_rep: str = "inf", - verbose: lib.NoDefault = lib.no_default, freeze_panes: tuple[int, int] | None = None, storage_options: StorageOptions = None, ) -> None: @@ -2204,24 +2198,9 @@ def to_excel( merge_cells : bool, default True Write MultiIndex and Hierarchical Rows as merged cells. - encoding : str, optional - Encoding of the resulting excel file. Only necessary for xlwt, - other writers support unicode natively. - - .. deprecated:: 1.5.0 - - This keyword was not used. - inf_rep : str, default 'inf' Representation for infinity (there is no native representation for infinity in Excel). - verbose : bool, default True - Display more information in the error logs. - - .. deprecated:: 1.5.0 - - This keyword was not used. - freeze_panes : tuple of int (length 2), optional Specifies the one-based bottommost row and rightmost column that is to be frozen. @@ -3470,7 +3449,6 @@ def to_csv( storage_options=_shared_docs["storage_options"], compression_options=_shared_docs["compression_options"] % "path_or_buf", ) - @deprecate_kwarg(old_arg_name="line_terminator", new_arg_name="lineterminator") def to_csv( self, path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None, @@ -4395,10 +4373,10 @@ def drop( ) -> NDFrameT | None: ... - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) def drop( self: NDFrameT, labels: IndexLabel = None, + *, axis: Axis = 0, index: IndexLabel = None, columns: IndexLabel = None, diff --git a/pandas/core/series.py b/pandas/core/series.py index 9f05eba00b05c..0037523dc8cbd 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -67,7 +67,6 @@ from pandas.util._decorators import ( Appender, Substitution, - deprecate_nonkeyword_arguments, doc, ) from pandas.util._exceptions import find_stack_level @@ -5022,12 +5021,10 @@ def drop( ) -> Series | None: ... - # error: Signature of "drop" incompatible with supertype "NDFrame" - # github.com/python/mypy/issues/12387 - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"]) - def drop( # type: ignore[override] + def drop( self, labels: IndexLabel = None, + *, axis: Axis = 0, index: IndexLabel = None, columns: IndexLabel = None, @@ -5171,11 +5168,11 @@ def fillna( ... # error: Signature of "fillna" incompatible with supertype "NDFrame" - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"]) @doc(NDFrame.fillna, **_shared_doc_kwargs) def fillna( # type: ignore[override] self, value: Hashable | Mapping | Series | DataFrame = None, + *, method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 94831da910150..a3424f09f334c 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -611,18 +611,6 @@ def test_fillna_downcast_dict(self): expected = DataFrame({"col1": [1, 2]}) tm.assert_frame_equal(result, expected) - def test_fillna_pos_args_deprecation(self): - # https://github.com/pandas-dev/pandas/issues/41485 - df = DataFrame({"a": [1, 2, 3, np.nan]}, dtype=float) - msg = ( - r"In a future version of pandas all arguments of DataFrame.fillna " - r"except for the argument 'value' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.fillna(0, None, None) - expected = DataFrame({"a": [1, 2, 3, 0]}, dtype=float) - tm.assert_frame_equal(result, expected) - def test_fillna_with_columns_and_limit(self): # GH40989 df = DataFrame( diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 2b86e9c7b3de2..51f607f425fa2 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -388,9 +388,7 @@ def test_to_csv_single_level_multi_index(self, ind, expected, frame_or_series): # see gh-19589 obj = frame_or_series(pd.Series([1], ind, name="data")) - with tm.assert_produces_warning(FutureWarning, match="lineterminator"): - # GH#9568 standardize on lineterminator matching stdlib - result = obj.to_csv(line_terminator="\n", header=True) + result = obj.to_csv(lineterminator="\n", header=True) assert result == expected def test_to_csv_string_array_ascii(self): diff --git a/pandas/tests/series/methods/test_drop.py b/pandas/tests/series/methods/test_drop.py index c960c281b2b95..dc4a11fd881fb 100644 --- a/pandas/tests/series/methods/test_drop.py +++ b/pandas/tests/series/methods/test_drop.py @@ -90,19 +90,6 @@ def test_drop_non_empty_list(data, index, drop_labels): ser.drop(drop_labels) -def test_drop_pos_args_deprecation(): - # 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\.drop " - r"except for the argument 'labels' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = ser.drop(1, 0) - expected = Series([1, 3], index=[0, 2]) - tm.assert_series_equal(result, expected) - - def test_drop_index_ea_dtype(any_numeric_ea_dtype): # GH#45860 df = Series(100, index=Index([1, 2, 2], dtype=any_numeric_ea_dtype)) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index caa14a440d04c..d879f124bb699 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -829,18 +829,6 @@ def test_fillna_datetime64_with_timezone_tzinfo(self): ) tm.assert_series_equal(result, expected) - def test_fillna_pos_args_deprecation(self): - # https://github.com/pandas-dev/pandas/issues/41485 - srs = Series([1, 2, 3, np.nan], dtype=float) - msg = ( - r"In a future version of pandas all arguments of Series.fillna " - r"except for the argument 'value' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = srs.fillna(0, None, None) - expected = Series([1, 2, 3, 0], dtype=float) - tm.assert_series_equal(result, expected) - @pytest.mark.parametrize( "input, input_fillna, expected_data, expected_categories", [