Skip to content

DEPR: non-keyword args, errors arg #49415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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`)
Expand Down
17 changes: 2 additions & 15 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
rewrite_axis_style_signature,
Expand Down Expand Up @@ -11782,7 +11781,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> DataFrame:
...

Expand All @@ -11795,7 +11793,6 @@ def where(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -11808,21 +11805,17 @@ 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,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
errors: IgnoreRaise | lib.NoDefault = "raise",
) -> DataFrame | None:
return super().where(
cond,
Expand All @@ -11841,7 +11834,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> DataFrame:
...

Expand All @@ -11854,7 +11846,6 @@ def mask(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -11867,21 +11858,17 @@ 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,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
errors: IgnoreRaise | lib.NoDefault = "raise",
) -> DataFrame | None:
return super().mask(
cond,
Expand Down
19 changes: 0 additions & 19 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9727,7 +9727,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> NDFrameT:
...

Expand All @@ -9740,7 +9739,6 @@ def where(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -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",
Expand All @@ -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}.
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -9933,7 +9919,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> NDFrameT:
...

Expand All @@ -9946,7 +9931,6 @@ def mask(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -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"],
Expand All @@ -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")
Expand Down
17 changes: 2 additions & 15 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
)
Expand Down Expand Up @@ -6019,7 +6018,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> Series:
...

Expand All @@ -6032,7 +6030,6 @@ def where(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -6045,21 +6042,17 @@ 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,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
errors: IgnoreRaise | lib.NoDefault = lib.no_default,
) -> Series | None:
return super().where(
cond,
Expand All @@ -6078,7 +6071,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> Series:
...

Expand All @@ -6091,7 +6083,6 @@ def mask(
inplace: Literal[True],
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> None:
...

Expand All @@ -6104,21 +6095,17 @@ 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,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
errors: IgnoreRaise | lib.NoDefault = lib.no_default,
) -> Series | None:
return super().mask(
cond,
Expand Down
11 changes: 3 additions & 8 deletions pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
AbstractMethodError,
EmptyDataError,
)
from pandas.util._decorators import deprecate_nonkeyword_arguments

from pandas.core.dtypes.common import is_list_like

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down
26 changes: 0 additions & 26 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand Down
Loading