Skip to content

Commit 848b975

Browse files
jbrockmendelmroeschke
authored andcommitted
DEPR: non-keyword args, errors arg (pandas-dev#49415)
* DEPR: non-keyword args, errors arg * Update doc/source/whatsnew/v2.0.0.rst Co-authored-by: Matthew Roeschke <[email protected]>
1 parent a791127 commit 848b975

File tree

10 files changed

+13
-125
lines changed

10 files changed

+13
-125
lines changed

doc/source/whatsnew/v2.0.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ Removal of prior version deprecations/changes
208208
- Removed argument ``inplace`` from :meth:`Categorical.remove_unused_categories` (:issue:`37918`)
209209
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
210210
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
211+
- Removed ``errors`` keyword from :meth:`DataFrame.where`, :meth:`Series.where`, :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`47728`)
211212
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
213+
- Disallow passing non-keyword arguments to :meth:`StringMethods.split` and :meth:`StringMethods.rsplit` except for ``pat`` (:issue:`47448`)
212214
- Disallow passing non-keyword arguments to :meth:`DataFrame.set_index` except ``keys`` (:issue:`41495`)
213215
- Disallow passing non-keyword arguments to :meth:`Resampler.interpolate` except ``method`` (:issue:`41699`)
214216
- Disallow passing non-keyword arguments to :meth:`DataFrame.reset_index` and :meth:`Series.reset_index` except ``level`` (:issue:`41496`)
@@ -225,6 +227,7 @@ Removal of prior version deprecations/changes
225227
- Disallow passing non-keyword arguments to :func:`concat` except for ``objs`` (:issue:`41485`)
226228
- Disallow passing non-keyword arguments to :func:`pivot` except for ``data`` (:issue:`48301`)
227229
- Disallow passing non-keyword arguments to :meth:`DataFrame.pivot` (:issue:`48301`)
230+
- Disallow passing non-keyword arguments to :func:`read_html` except for ``io`` (:issue:`27573`)
228231
- Disallow passing non-keyword arguments to :func:`read_json` except for ``path_or_buf`` (:issue:`27573`)
229232
- Disallow passing non-keyword arguments to :func:`read_sas` except for ``filepath_or_buffer`` (:issue:`47154`)
230233
- Disallow passing non-keyword arguments to :func:`read_stata` except for ``filepath_or_buffer`` (:issue:`48128`)

pandas/core/frame.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
from pandas.util._decorators import (
9696
Appender,
9797
Substitution,
98-
deprecate_kwarg,
9998
deprecate_nonkeyword_arguments,
10099
doc,
101100
rewrite_axis_style_signature,
@@ -11772,7 +11771,6 @@ def where(
1177211771
inplace: Literal[False] = ...,
1177311772
axis: Axis | None = ...,
1177411773
level: Level = ...,
11775-
errors: IgnoreRaise | lib.NoDefault = ...,
1177611774
) -> DataFrame:
1177711775
...
1177811776

@@ -11785,7 +11783,6 @@ def where(
1178511783
inplace: Literal[True],
1178611784
axis: Axis | None = ...,
1178711785
level: Level = ...,
11788-
errors: IgnoreRaise | lib.NoDefault = ...,
1178911786
) -> None:
1179011787
...
1179111788

@@ -11798,21 +11795,17 @@ def where(
1179811795
inplace: bool = ...,
1179911796
axis: Axis | None = ...,
1180011797
level: Level = ...,
11801-
errors: IgnoreRaise | lib.NoDefault = ...,
1180211798
) -> DataFrame | None:
1180311799
...
1180411800

11805-
# error: Signature of "where" incompatible with supertype "NDFrame"
11806-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
11807-
def where( # type: ignore[override]
11801+
def where(
1180811802
self,
1180911803
cond,
1181011804
other=lib.no_default,
1181111805
*,
1181211806
inplace: bool = False,
1181311807
axis: Axis | None = None,
1181411808
level: Level = None,
11815-
errors: IgnoreRaise | lib.NoDefault = "raise",
1181611809
) -> DataFrame | None:
1181711810
return super().where(
1181811811
cond,
@@ -11831,7 +11824,6 @@ def mask(
1183111824
inplace: Literal[False] = ...,
1183211825
axis: Axis | None = ...,
1183311826
level: Level = ...,
11834-
errors: IgnoreRaise | lib.NoDefault = ...,
1183511827
) -> DataFrame:
1183611828
...
1183711829

@@ -11844,7 +11836,6 @@ def mask(
1184411836
inplace: Literal[True],
1184511837
axis: Axis | None = ...,
1184611838
level: Level = ...,
11847-
errors: IgnoreRaise | lib.NoDefault = ...,
1184811839
) -> None:
1184911840
...
1185011841

@@ -11857,21 +11848,17 @@ def mask(
1185711848
inplace: bool = ...,
1185811849
axis: Axis | None = ...,
1185911850
level: Level = ...,
11860-
errors: IgnoreRaise | lib.NoDefault = ...,
1186111851
) -> DataFrame | None:
1186211852
...
1186311853

11864-
# error: Signature of "mask" incompatible with supertype "NDFrame"
11865-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
11866-
def mask( # type: ignore[override]
11854+
def mask(
1186711855
self,
1186811856
cond,
1186911857
other=lib.no_default,
1187011858
*,
1187111859
inplace: bool = False,
1187211860
axis: Axis | None = None,
1187311861
level: Level = None,
11874-
errors: IgnoreRaise | lib.NoDefault = "raise",
1187511862
) -> DataFrame | None:
1187611863
return super().mask(
1187711864
cond,

pandas/core/generic.py

-19
Original file line numberDiff line numberDiff line change
@@ -9724,7 +9724,6 @@ def where(
97249724
inplace: Literal[False] = ...,
97259725
axis: Axis | None = ...,
97269726
level: Level = ...,
9727-
errors: IgnoreRaise | lib.NoDefault = ...,
97289727
) -> NDFrameT:
97299728
...
97309729

@@ -9737,7 +9736,6 @@ def where(
97379736
inplace: Literal[True],
97389737
axis: Axis | None = ...,
97399738
level: Level = ...,
9740-
errors: IgnoreRaise | lib.NoDefault = ...,
97419739
) -> None:
97429740
...
97439741

@@ -9750,11 +9748,9 @@ def where(
97509748
inplace: bool_t = ...,
97519749
axis: Axis | None = ...,
97529750
level: Level = ...,
9753-
errors: IgnoreRaise | lib.NoDefault = ...,
97549751
) -> NDFrameT | None:
97559752
...
97569753

9757-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
97589754
@doc(
97599755
klass=_shared_doc_kwargs["klass"],
97609756
cond="True",
@@ -9770,7 +9766,6 @@ def where(
97709766
inplace: bool_t = False,
97719767
axis: Axis | None = None,
97729768
level: Level = None,
9773-
errors: IgnoreRaise | lib.NoDefault = "raise",
97749769
) -> NDFrameT | None:
97759770
"""
97769771
Replace values where the condition is {cond_rev}.
@@ -9799,15 +9794,6 @@ def where(
97999794
unused and defaults to 0.
98009795
level : int, default None
98019796
Alignment level if needed.
9802-
errors : str, {{'raise', 'ignore'}}, default 'raise'
9803-
Note that currently this parameter won't affect
9804-
the results and will always coerce to a suitable dtype.
9805-
9806-
- 'raise' : allow exceptions to be raised.
9807-
- 'ignore' : suppress exceptions. On error return original object.
9808-
9809-
.. deprecated:: 1.5.0
9810-
This argument had no effect.
98119797
98129798
Returns
98139799
-------
@@ -9930,7 +9916,6 @@ def mask(
99309916
inplace: Literal[False] = ...,
99319917
axis: Axis | None = ...,
99329918
level: Level = ...,
9933-
errors: IgnoreRaise | lib.NoDefault = ...,
99349919
) -> NDFrameT:
99359920
...
99369921

@@ -9943,7 +9928,6 @@ def mask(
99439928
inplace: Literal[True],
99449929
axis: Axis | None = ...,
99459930
level: Level = ...,
9946-
errors: IgnoreRaise | lib.NoDefault = ...,
99479931
) -> None:
99489932
...
99499933

@@ -9956,11 +9940,9 @@ def mask(
99569940
inplace: bool_t = ...,
99579941
axis: Axis | None = ...,
99589942
level: Level = ...,
9959-
errors: IgnoreRaise | lib.NoDefault = ...,
99609943
) -> NDFrameT | None:
99619944
...
99629945

9963-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
99649946
@doc(
99659947
where,
99669948
klass=_shared_doc_kwargs["klass"],
@@ -9977,7 +9959,6 @@ def mask(
99779959
inplace: bool_t = False,
99789960
axis: Axis | None = None,
99799961
level: Level = None,
9980-
errors: IgnoreRaise | lib.NoDefault = "raise",
99819962
) -> NDFrameT | None:
99829963

99839964
inplace = validate_bool_kwarg(inplace, "inplace")

pandas/core/series.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
from pandas.util._decorators import (
6868
Appender,
6969
Substitution,
70-
deprecate_kwarg,
7170
deprecate_nonkeyword_arguments,
7271
doc,
7372
)
@@ -6003,7 +6002,6 @@ def where(
60036002
inplace: Literal[False] = ...,
60046003
axis: Axis | None = ...,
60056004
level: Level = ...,
6006-
errors: IgnoreRaise | lib.NoDefault = ...,
60076005
) -> Series:
60086006
...
60096007

@@ -6016,7 +6014,6 @@ def where(
60166014
inplace: Literal[True],
60176015
axis: Axis | None = ...,
60186016
level: Level = ...,
6019-
errors: IgnoreRaise | lib.NoDefault = ...,
60206017
) -> None:
60216018
...
60226019

@@ -6029,21 +6026,17 @@ def where(
60296026
inplace: bool = ...,
60306027
axis: Axis | None = ...,
60316028
level: Level = ...,
6032-
errors: IgnoreRaise | lib.NoDefault = ...,
60336029
) -> Series | None:
60346030
...
60356031

6036-
# error: Signature of "where" incompatible with supertype "NDFrame"
6037-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
6038-
def where( # type: ignore[override]
6032+
def where(
60396033
self,
60406034
cond,
60416035
other=lib.no_default,
60426036
*,
60436037
inplace: bool = False,
60446038
axis: Axis | None = None,
60456039
level: Level = None,
6046-
errors: IgnoreRaise | lib.NoDefault = lib.no_default,
60476040
) -> Series | None:
60486041
return super().where(
60496042
cond,
@@ -6062,7 +6055,6 @@ def mask(
60626055
inplace: Literal[False] = ...,
60636056
axis: Axis | None = ...,
60646057
level: Level = ...,
6065-
errors: IgnoreRaise | lib.NoDefault = ...,
60666058
) -> Series:
60676059
...
60686060

@@ -6075,7 +6067,6 @@ def mask(
60756067
inplace: Literal[True],
60766068
axis: Axis | None = ...,
60776069
level: Level = ...,
6078-
errors: IgnoreRaise | lib.NoDefault = ...,
60796070
) -> None:
60806071
...
60816072

@@ -6088,21 +6079,17 @@ def mask(
60886079
inplace: bool = ...,
60896080
axis: Axis | None = ...,
60906081
level: Level = ...,
6091-
errors: IgnoreRaise | lib.NoDefault = ...,
60926082
) -> Series | None:
60936083
...
60946084

6095-
# error: Signature of "mask" incompatible with supertype "NDFrame"
6096-
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
6097-
def mask( # type: ignore[override]
6085+
def mask(
60986086
self,
60996087
cond,
61006088
other=lib.no_default,
61016089
*,
61026090
inplace: bool = False,
61036091
axis: Axis | None = None,
61046092
level: Level = None,
6105-
errors: IgnoreRaise | lib.NoDefault = lib.no_default,
61066093
) -> Series | None:
61076094
return super().mask(
61086095
cond,

pandas/core/strings/accessor.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
F,
2222
Scalar,
2323
)
24-
from pandas.util._decorators import (
25-
Appender,
26-
deprecate_nonkeyword_arguments,
27-
)
24+
from pandas.util._decorators import Appender
2825
from pandas.util._exceptions import find_stack_level
2926

3027
from pandas.core.dtypes.common import (
@@ -840,14 +837,13 @@ def cat(
840837
""",
841838
}
842839
)
843-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
844840
@forbid_nonstring_types(["bytes"])
845841
def split(
846842
self,
847843
pat: str | re.Pattern | None = None,
844+
*,
848845
n=-1,
849846
expand: bool = False,
850-
*,
851847
regex: bool | None = None,
852848
):
853849
if regex is False and is_re(pat):
@@ -872,9 +868,8 @@ def split(
872868
"regex_examples": "",
873869
}
874870
)
875-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "pat"])
876871
@forbid_nonstring_types(["bytes"])
877-
def rsplit(self, pat=None, n=-1, expand: bool = False):
872+
def rsplit(self, pat=None, *, n=-1, expand: bool = False):
878873
result = self._data.array._str_rsplit(pat, n=n)
879874
return self._wrap_result(result, expand=expand, returns_string=expand)
880875

pandas/io/html.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
AbstractMethodError,
2828
EmptyDataError,
2929
)
30-
from pandas.util._decorators import deprecate_nonkeyword_arguments
3130

3231
from pandas.core.dtypes.common import is_list_like
3332

@@ -1026,9 +1025,9 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, extract_links, **
10261025
return ret
10271026

10281027

1029-
@deprecate_nonkeyword_arguments(version="2.0")
10301028
def read_html(
10311029
io: FilePath | ReadBuffer[str],
1030+
*,
10321031
match: str | Pattern = ".+",
10331032
flavor: str | None = None,
10341033
header: int | Sequence[int] | None = None,

pandas/tests/frame/indexing/test_where.py

-14
Original file line numberDiff line numberDiff line change
@@ -1009,20 +1009,6 @@ def test_where_dt64_2d():
10091009
_check_where_equivalences(df, mask, other, expected)
10101010

10111011

1012-
def test_where_mask_deprecated(frame_or_series):
1013-
# GH 47728
1014-
obj = DataFrame(np.random.randn(4, 3))
1015-
obj = tm.get_obj(obj, frame_or_series)
1016-
1017-
mask = obj > 0
1018-
1019-
with tm.assert_produces_warning(FutureWarning):
1020-
obj.where(mask, -1, errors="raise")
1021-
1022-
with tm.assert_produces_warning(FutureWarning):
1023-
obj.mask(mask, -1, errors="raise")
1024-
1025-
10261012
def test_where_producing_ea_cond_for_np_dtype():
10271013
# GH#44014
10281014
df = DataFrame({"a": Series([1, pd.NA, 2], dtype="Int64"), "b": [1, 2, 3]})

pandas/tests/io/test_html.py

-26
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,6 @@ def test_to_html_compat(self):
132132
res = self.read_html(out, attrs={"class": "dataframe"}, index_col=0)[0]
133133
tm.assert_frame_equal(res, df)
134134

135-
@pytest.mark.network
136-
@tm.network(
137-
url=(
138-
"https://www.fdic.gov/resources/resolutions/"
139-
"bank-failures/failed-bank-list/index.html"
140-
),
141-
check_before_test=True,
142-
)
143-
def test_banklist_url_positional_match(self):
144-
url = "https://www.fdic.gov/resources/resolutions/bank-failures/failed-bank-list/index.html" # noqa E501
145-
# Passing match argument as positional should cause a FutureWarning.
146-
with tm.assert_produces_warning(FutureWarning):
147-
df1 = self.read_html(
148-
# lxml cannot find attrs leave out for now
149-
url,
150-
"First Federal Bank of Florida", # attrs={"class": "dataTable"}
151-
)
152-
with tm.assert_produces_warning(FutureWarning):
153-
# lxml cannot find attrs leave out for now
154-
df2 = self.read_html(
155-
url,
156-
"Metcalf Bank",
157-
) # attrs={"class": "dataTable"})
158-
159-
assert_framelist_equal(df1, df2)
160-
161135
@pytest.mark.network
162136
@tm.network(
163137
url=(

0 commit comments

Comments
 (0)