From f4e05a90de3a04dd0b8b5018981731cc975b6d91 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 31 Oct 2022 10:16:35 -0700 Subject: [PATCH 1/2] DEPR: non-keyword args, errors arg --- doc/source/whatsnew/v2.0.0.rst | 3 +++ pandas/core/frame.py | 17 ++----------- pandas/core/generic.py | 19 -------------- pandas/core/series.py | 17 ++----------- pandas/core/strings/accessor.py | 11 +++------ pandas/io/html.py | 3 +-- pandas/tests/frame/indexing/test_where.py | 14 ----------- pandas/tests/io/test_html.py | 26 -------------------- pandas/tests/series/methods/test_fillna.py | 11 ++------- pandas/tests/strings/test_split_partition.py | 17 ------------- 10 files changed, 13 insertions(+), 125 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index eab8df5ccff73..b7c2a6c6781b0 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -198,7 +198,9 @@ Removal of prior version deprecations/changes - Removed argument ``inplace`` from :meth:`Categorical.remove_unused_categories` (:issue:`37918`) - 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`) +- 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:`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`) - Disallow passing non-keyword arguments to :meth:`DataFrame.reset_index` and :meth:`Series.reset_index` except ``level`` (:issue:`41496`) @@ -215,6 +217,7 @@ Removal of prior version deprecations/changes - Disallow passing non-keyword arguments to :func:`concat` except for ``objs`` (:issue:`41485`) - Disallow passing non-keyword arguments to :func:`pivot` except for ``data`` (:issue:`48301`) - Disallow passing non-keyword arguments to :meth:`DataFrame.pivot` (:issue:`48301`) +- Disallow passing non-keyword arguments to :func:`read_html` except for ``io`` (:issue:`27573`) - Disallow passing non-keyword arguments to :func:`read_json` except for ``path_or_buf`` (:issue:`27573`) - Disallow passing non-keyword arguments to :func:`read_sas` except for ``filepath_or_buffer`` (:issue:`47154`) - Disallow passing non-keyword arguments to :func:`read_stata` except for ``filepath_or_buffer`` (:issue:`48128`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 17c4bde9d0279..42953f3ca7fdf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -95,7 +95,6 @@ from pandas.util._decorators import ( Appender, Substitution, - deprecate_kwarg, deprecate_nonkeyword_arguments, doc, rewrite_axis_style_signature, @@ -11782,7 +11781,6 @@ def where( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> DataFrame: ... @@ -11795,7 +11793,6 @@ def where( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -11808,13 +11805,10 @@ def where( inplace: bool = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> DataFrame | None: ... - # error: Signature of "where" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - def where( # type: ignore[override] + def where( self, cond, other=lib.no_default, @@ -11822,7 +11816,6 @@ def where( # type: ignore[override] inplace: bool = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = "raise", ) -> DataFrame | None: return super().where( cond, @@ -11841,7 +11834,6 @@ def mask( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> DataFrame: ... @@ -11854,7 +11846,6 @@ def mask( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -11867,13 +11858,10 @@ def mask( inplace: bool = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> DataFrame | None: ... - # error: Signature of "mask" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - def mask( # type: ignore[override] + def mask( self, cond, other=lib.no_default, @@ -11881,7 +11869,6 @@ def mask( # type: ignore[override] inplace: bool = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = "raise", ) -> DataFrame | None: return super().mask( cond, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8bf3820d2ea3c..39bc9fafd9f6d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9727,7 +9727,6 @@ def where( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> NDFrameT: ... @@ -9740,7 +9739,6 @@ def where( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -9753,11 +9751,9 @@ def where( inplace: bool_t = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> NDFrameT | None: ... - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @doc( klass=_shared_doc_kwargs["klass"], cond="True", @@ -9773,7 +9769,6 @@ def where( inplace: bool_t = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = "raise", ) -> NDFrameT | None: """ Replace values where the condition is {cond_rev}. @@ -9802,15 +9797,6 @@ def where( unused and defaults to 0. level : int, default None Alignment level if needed. - errors : str, {{'raise', 'ignore'}}, default 'raise' - Note that currently this parameter won't affect - the results and will always coerce to a suitable dtype. - - - 'raise' : allow exceptions to be raised. - - 'ignore' : suppress exceptions. On error return original object. - - .. deprecated:: 1.5.0 - This argument had no effect. Returns ------- @@ -9933,7 +9919,6 @@ def mask( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> NDFrameT: ... @@ -9946,7 +9931,6 @@ def mask( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -9959,11 +9943,9 @@ def mask( inplace: bool_t = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> NDFrameT | None: ... - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) @doc( where, klass=_shared_doc_kwargs["klass"], @@ -9980,7 +9962,6 @@ def mask( inplace: bool_t = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = "raise", ) -> NDFrameT | None: inplace = validate_bool_kwarg(inplace, "inplace") diff --git a/pandas/core/series.py b/pandas/core/series.py index 7854bf6180733..645623f56e46d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -67,7 +67,6 @@ from pandas.util._decorators import ( Appender, Substitution, - deprecate_kwarg, deprecate_nonkeyword_arguments, doc, ) @@ -6019,7 +6018,6 @@ def where( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> Series: ... @@ -6032,7 +6030,6 @@ def where( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -6045,13 +6042,10 @@ def where( inplace: bool = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> Series | None: ... - # error: Signature of "where" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - def where( # type: ignore[override] + def where( self, cond, other=lib.no_default, @@ -6059,7 +6053,6 @@ def where( # type: ignore[override] inplace: bool = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = lib.no_default, ) -> Series | None: return super().where( cond, @@ -6078,7 +6071,6 @@ def mask( inplace: Literal[False] = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> Series: ... @@ -6091,7 +6083,6 @@ def mask( inplace: Literal[True], axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> None: ... @@ -6104,13 +6095,10 @@ def mask( inplace: bool = ..., axis: Axis | None = ..., level: Level = ..., - errors: IgnoreRaise | lib.NoDefault = ..., ) -> Series | None: ... - # error: Signature of "mask" incompatible with supertype "NDFrame" - @deprecate_kwarg(old_arg_name="errors", new_arg_name=None) - def mask( # type: ignore[override] + def mask( self, cond, other=lib.no_default, @@ -6118,7 +6106,6 @@ def mask( # type: ignore[override] inplace: bool = False, axis: Axis | None = None, level: Level = None, - errors: IgnoreRaise | lib.NoDefault = lib.no_default, ) -> Series | None: return super().mask( cond, diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 0888fa6985560..0024cbcb01bfc 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -21,10 +21,7 @@ F, Scalar, ) -from pandas.util._decorators import ( - Appender, - deprecate_nonkeyword_arguments, -) +from pandas.util._decorators import Appender from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( @@ -840,14 +837,13 @@ def cat( """, } ) - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"]) @forbid_nonstring_types(["bytes"]) def split( self, pat: str | re.Pattern | None = None, + *, n=-1, expand: bool = False, - *, regex: bool | None = None, ): if regex is False and is_re(pat): @@ -872,9 +868,8 @@ def split( "regex_examples": "", } ) - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"]) @forbid_nonstring_types(["bytes"]) - def rsplit(self, pat=None, n=-1, expand: bool = False): + def rsplit(self, pat=None, *, n=-1, expand: bool = False): result = self._data.array._str_rsplit(pat, n=n) return self._wrap_result(result, expand=expand, returns_string=expand) diff --git a/pandas/io/html.py b/pandas/io/html.py index a08b73d94250b..b9bffdc7b871e 100644 --- a/pandas/io/html.py +++ b/pandas/io/html.py @@ -27,7 +27,6 @@ AbstractMethodError, EmptyDataError, ) -from pandas.util._decorators import deprecate_nonkeyword_arguments from pandas.core.dtypes.common import is_list_like @@ -1026,9 +1025,9 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, extract_links, ** return ret -@deprecate_nonkeyword_arguments(version="2.0") def read_html( io: FilePath | ReadBuffer[str], + *, match: str | Pattern = ".+", flavor: str | None = None, header: int | Sequence[int] | None = None, diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 1212659ea24e2..501822f856a63 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -1009,20 +1009,6 @@ def test_where_dt64_2d(): _check_where_equivalences(df, mask, other, expected) -def test_where_mask_deprecated(frame_or_series): - # GH 47728 - obj = DataFrame(np.random.randn(4, 3)) - obj = tm.get_obj(obj, frame_or_series) - - mask = obj > 0 - - with tm.assert_produces_warning(FutureWarning): - obj.where(mask, -1, errors="raise") - - with tm.assert_produces_warning(FutureWarning): - obj.mask(mask, -1, errors="raise") - - def test_where_producing_ea_cond_for_np_dtype(): # GH#44014 df = DataFrame({"a": Series([1, pd.NA, 2], dtype="Int64"), "b": [1, 2, 3]}) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 0ea1203359153..65e1a1e9830cc 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -133,32 +133,6 @@ def test_to_html_compat(self): res = self.read_html(out, attrs={"class": "dataframe"}, index_col=0)[0] tm.assert_frame_equal(res, df) - @pytest.mark.network - @tm.network( - url=( - "https://www.fdic.gov/resources/resolutions/" - "bank-failures/failed-bank-list/index.html" - ), - check_before_test=True, - ) - def test_banklist_url_positional_match(self): - url = "https://www.fdic.gov/resources/resolutions/bank-failures/failed-bank-list/index.html" # noqa E501 - # Passing match argument as positional should cause a FutureWarning. - with tm.assert_produces_warning(FutureWarning): - df1 = self.read_html( - # lxml cannot find attrs leave out for now - url, - "First Federal Bank of Florida", # attrs={"class": "dataTable"} - ) - with tm.assert_produces_warning(FutureWarning): - # lxml cannot find attrs leave out for now - df2 = self.read_html( - url, - "Metcalf Bank", - ) # attrs={"class": "dataTable"}) - - assert_framelist_equal(df1, df2) - @pytest.mark.network @tm.network( url=( diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 409a3b231fa95..18a4d8355c764 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -151,17 +151,10 @@ def test_fillna_consistency(self): ) tm.assert_series_equal(result, expected) - # where (we ignore the errors=) - with tm.assert_produces_warning(FutureWarning, match="the 'errors' keyword"): - result = ser.where( - [True, False], Timestamp("20130101", tz="US/Eastern"), errors="ignore" - ) + result = ser.where([True, False], Timestamp("20130101", tz="US/Eastern")) tm.assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning, match="the 'errors' keyword"): - result = ser.where( - [True, False], Timestamp("20130101", tz="US/Eastern"), errors="ignore" - ) + result = ser.where([True, False], Timestamp("20130101", tz="US/Eastern")) tm.assert_series_equal(result, expected) # with a non-datetime diff --git a/pandas/tests/strings/test_split_partition.py b/pandas/tests/strings/test_split_partition.py index 7d73414a672c8..74458c13e8df7 100644 --- a/pandas/tests/strings/test_split_partition.py +++ b/pandas/tests/strings/test_split_partition.py @@ -130,23 +130,6 @@ def test_rsplit_max_number(any_string_dtype): tm.assert_series_equal(result, exp) -@pytest.mark.parametrize("method", ["split", "rsplit"]) -def test_posargs_deprecation(method): - # GH 47423; Deprecate passing n as positional. - s = Series(["foo,bar,lorep"]) - - msg = ( - f"In a future version of pandas all arguments of StringMethods.{method} " - "except for the argument 'pat' will be keyword-only" - ) - - with tm.assert_produces_warning(FutureWarning, match=msg): - result = getattr(s.str, method)(",", 3) - - expected = Series([["foo", "bar", "lorep"]]) - tm.assert_series_equal(result, expected) - - def test_split_blank_string(any_string_dtype): # expand blank split GH 20067 values = Series([""], name="test", dtype=any_string_dtype) From bbb0b2472515cf25efa1fa701b545214ac719b91 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 1 Nov 2022 10:40:15 -0700 Subject: [PATCH 2/2] Update doc/source/whatsnew/v2.0.0.rst --- 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 b7c2a6c6781b0..b97cdd5d1e298 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -198,7 +198,7 @@ Removal of prior version deprecations/changes - Removed argument ``inplace`` from :meth:`Categorical.remove_unused_categories` (:issue:`37918`) - 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`) -- Removed ``errors`` keyword from :meth:`DataFrame.where`, :meth:`Series.where`, :meth:`DataFrame.mask` and :meth:`Series.mask (:issue:`47728`) +- 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:`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`)