Skip to content

Commit

Permalink
DEPR: non-keyword args, errors arg (#49415)
Browse files Browse the repository at this point in the history
* DEPR: non-keyword args, errors arg

* Update doc/source/whatsnew/v2.0.0.rst

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
jbrockmendel and mroeschke authored Nov 1, 2022
1 parent 76923d7 commit 6122c7d
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 125 deletions.
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 @@ -208,7 +208,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 @@ -225,6 +227,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 @@ -11772,7 +11771,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> DataFrame:
...

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

Expand All @@ -11798,21 +11795,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 @@ -11831,7 +11824,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> DataFrame:
...

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

Expand All @@ -11857,21 +11848,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 @@ -9724,7 +9724,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> NDFrameT:
...

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

Expand All @@ -9750,11 +9748,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 @@ -9770,7 +9766,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 @@ -9799,15 +9794,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 @@ -9930,7 +9916,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> NDFrameT:
...

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

Expand All @@ -9956,11 +9940,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 @@ -9977,7 +9959,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 @@ -6003,7 +6002,6 @@ def where(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> Series:
...

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

Expand All @@ -6029,21 +6026,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 @@ -6062,7 +6055,6 @@ def mask(
inplace: Literal[False] = ...,
axis: Axis | None = ...,
level: Level = ...,
errors: IgnoreRaise | lib.NoDefault = ...,
) -> Series:
...

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

Expand All @@ -6088,21 +6079,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 @@ -132,32 +132,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

0 comments on commit 6122c7d

Please sign in to comment.