Skip to content

Commit

Permalink
DEPR: non-keyword arguments (#49302)
Browse files Browse the repository at this point in the history
* DEPR: non-keyword arguments

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

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
jbrockmendel and mroeschke committed Oct 26, 2022
1 parent 032316f commit 7fddb30
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 221 deletions.
13 changes: 13 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Expand Up @@ -197,6 +197,19 @@ Removal of prior version deprecations/changes
- 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`)
- 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_duplicates` except for ``subset`` (:issue:`41485`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41506`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` except for ``method`` (:issue:`41510`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44896`)
- Disallow passing non-keyword arguments to :meth:`Index.set_names` except for ``names`` (:issue:`41551`)
- Disallow passing non-keyword arguments to :meth:`Index.join` except for ``other`` (:issue:`46518`)
- 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_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`)
- Disallow passing non-keyword arguments to :func:`read_xml` except for ``path_or_buffer`` (:issue:`45133`)
- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523`)
Expand Down
23 changes: 11 additions & 12 deletions pandas/core/frame.py
Expand Up @@ -6538,10 +6538,10 @@ def dropna(
self._update_inplace(result)
return None

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "subset"])
def drop_duplicates(
self,
subset: Hashable | Sequence[Hashable] | None = None,
*,
keep: DropKeep = "first",
inplace: bool = False,
ignore_index: bool = False,
Expand Down Expand Up @@ -6946,10 +6946,9 @@ def sort_index(
) -> DataFrame | None:
...

# error: Signature of "sort_index" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def sort_index( # type: ignore[override]
def sort_index(
self,
*,
axis: Axis = 0,
level: IndexLabel = None,
ascending: bool | Sequence[bool] = True,
Expand Down Expand Up @@ -11776,10 +11775,10 @@ def clip(
) -> DataFrame | None:
return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
def interpolate(
self: DataFrame,
method: str = "linear",
*,
axis: Axis = 0,
limit: int | None = None,
inplace: bool = False,
Expand All @@ -11789,13 +11788,13 @@ def interpolate(
**kwargs,
) -> DataFrame | None:
return super().interpolate(
method,
axis,
limit,
inplace,
limit_direction,
limit_area,
downcast,
method=method,
axis=axis,
limit=limit,
inplace=inplace,
limit_direction=limit_direction,
limit_area=limit_area,
downcast=downcast,
**kwargs,
)

Expand Down
17 changes: 11 additions & 6 deletions pandas/core/generic.py
Expand Up @@ -5000,6 +5000,7 @@ def sort_index(

def sort_index(
self: NDFrameT,
*,
axis: Axis = 0,
level: IndexLabel = None,
ascending: bool_t | Sequence[bool_t] = True,
Expand Down Expand Up @@ -7312,6 +7313,7 @@ def replace(
def interpolate(
self: NDFrameT,
method: str = "linear",
*,
axis: Axis = 0,
limit: int | None = None,
inplace: bool_t = False,
Expand Down Expand Up @@ -11429,11 +11431,6 @@ def _add_numeric_operations(cls) -> None:
"""
axis_descr, name1, name2 = _doc_params(cls)

@deprecate_nonkeyword_arguments(
version=None,
allowed_args=["self"],
name="DataFrame.any and Series.any",
)
@doc(
_bool_doc,
desc=_any_desc,
Expand All @@ -11446,13 +11443,21 @@ def _add_numeric_operations(cls) -> None:
)
def any(
self,
*,
axis: Axis = 0,
bool_only=None,
skipna: bool_t = True,
level=None,
**kwargs,
):
return NDFrame.any(self, axis, bool_only, skipna, level, **kwargs)
return NDFrame.any(
self,
axis=axis,
bool_only=bool_only,
skipna=skipna,
level=level,
**kwargs,
)

setattr(cls, "any", any)

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/base.py
Expand Up @@ -218,7 +218,8 @@ def _maybe_return_indexers(meth: F) -> F:
@functools.wraps(meth)
def join(
self,
other,
other: Index,
*,
how: str_t = "left",
level=None,
return_indexers: bool = False,
Expand Down Expand Up @@ -1760,9 +1761,8 @@ def set_names(
) -> _IndexT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"])
def set_names(
self: _IndexT, names, level=None, inplace: bool = False
self: _IndexT, names, *, level=None, inplace: bool = False
) -> _IndexT | None:
"""
Set Index or MultiIndex name.
Expand Down Expand Up @@ -4494,11 +4494,11 @@ def join(
...

@final
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "other"])
@_maybe_return_indexers
def join(
self,
other: Index,
*,
how: str_t = "left",
level: Level = None,
return_indexers: bool = False,
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/indexes/multi.py
Expand Up @@ -50,7 +50,6 @@
from pandas.util._decorators import (
Appender,
cache_readonly,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -3786,10 +3785,8 @@ def set_names(self, names, *, level=..., inplace: Literal[True]) -> None:
def set_names(self, names, *, level=..., inplace: bool = ...) -> MultiIndex | None:
...

# error: Signature of "set_names" incompatible with supertype "Index"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"])
def set_names( # type: ignore[override]
self, names, level=None, inplace: bool = False
def set_names(
self, names, *, level=None, inplace: bool = False
) -> MultiIndex | None:
return super().set_names(names=names, level=level, inplace=inplace)

Expand Down
12 changes: 7 additions & 5 deletions pandas/core/reshape/concat.py
Expand Up @@ -23,10 +23,7 @@
AxisInt,
HashableT,
)
from pandas.util._decorators import (
cache_readonly,
deprecate_nonkeyword_arguments,
)
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.concat import concat_compat
Expand Down Expand Up @@ -67,6 +64,7 @@
@overload
def concat(
objs: Iterable[DataFrame] | Mapping[HashableT, DataFrame],
*,
axis: Literal[0, "index"] = ...,
join: str = ...,
ignore_index: bool = ...,
Expand All @@ -83,6 +81,7 @@ def concat(
@overload
def concat(
objs: Iterable[Series] | Mapping[HashableT, Series],
*,
axis: Literal[0, "index"] = ...,
join: str = ...,
ignore_index: bool = ...,
Expand All @@ -99,6 +98,7 @@ def concat(
@overload
def concat(
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
*,
axis: Literal[0, "index"] = ...,
join: str = ...,
ignore_index: bool = ...,
Expand All @@ -115,6 +115,7 @@ def concat(
@overload
def concat(
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
*,
axis: Literal[1, "columns"],
join: str = ...,
ignore_index: bool = ...,
Expand All @@ -131,6 +132,7 @@ def concat(
@overload
def concat(
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
*,
axis: Axis = ...,
join: str = ...,
ignore_index: bool = ...,
Expand All @@ -144,9 +146,9 @@ def concat(
...


@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"])
def concat(
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
*,
axis: Axis = 0,
join: str = "outer",
ignore_index: bool = False,
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/reshape/pivot.py
Expand Up @@ -20,7 +20,6 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
)

from pandas.core.dtypes.cast import maybe_downcast_to_dtype
Expand Down Expand Up @@ -493,9 +492,9 @@ def _convert_by(by):

@Substitution("\ndata : DataFrame")
@Appender(_shared_docs["pivot"], indents=1)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["data"])
def pivot(
data: DataFrame,
*,
index: IndexLabel | lib.NoDefault = lib.NoDefault,
columns: IndexLabel | lib.NoDefault = lib.NoDefault,
values: IndexLabel | lib.NoDefault = lib.NoDefault,
Expand Down
21 changes: 10 additions & 11 deletions pandas/core/series.py
Expand Up @@ -3767,10 +3767,9 @@ def sort_index(
) -> Series | None:
...

# error: Signature of "sort_index" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def sort_index( # type: ignore[override]
def sort_index(
self,
*,
axis: Axis = 0,
level: IndexLabel = None,
ascending: bool | Sequence[bool] = True,
Expand Down Expand Up @@ -5993,10 +5992,10 @@ def clip(
) -> Series | None:
return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
def interpolate(
self: Series,
method: str = "linear",
*,
axis: Axis = 0,
limit: int | None = None,
inplace: bool = False,
Expand All @@ -6006,13 +6005,13 @@ def interpolate(
**kwargs,
) -> Series | None:
return super().interpolate(
method,
axis,
limit,
inplace,
limit_direction,
limit_area,
downcast,
method=method,
axis=axis,
limit=limit,
inplace=inplace,
limit_direction=limit_direction,
limit_area=limit_area,
downcast=downcast,
**kwargs,
)

Expand Down
8 changes: 3 additions & 5 deletions pandas/io/json/_json.py
Expand Up @@ -34,10 +34,7 @@
WriteBuffer,
)
from pandas.errors import AbstractMethodError
from pandas.util._decorators import (
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._decorators import doc

from pandas.core.dtypes.common import (
ensure_str,
Expand Down Expand Up @@ -452,6 +449,7 @@ def read_json(
@overload
def read_json(
path_or_buf: FilePath | ReadBuffer[str] | ReadBuffer[bytes],
*,
orient: str | None = ...,
typ: Literal["frame"] = ...,
dtype: DtypeArg | None = ...,
Expand All @@ -475,9 +473,9 @@ def read_json(
storage_options=_shared_docs["storage_options"],
decompression_options=_shared_docs["decompression_options"] % "path_or_buf",
)
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["path_or_buf"])
def read_json(
path_or_buf: FilePath | ReadBuffer[str] | ReadBuffer[bytes],
*,
orient: str | None = None,
typ: Literal["frame", "series"] = "frame",
dtype: DtypeArg | None = None,
Expand Down
9 changes: 4 additions & 5 deletions pandas/io/sas/sasreader.py
Expand Up @@ -19,10 +19,7 @@
FilePath,
ReadBuffer,
)
from pandas.util._decorators import (
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._decorators import doc

from pandas.core.shared_docs import _shared_docs

Expand Down Expand Up @@ -61,6 +58,7 @@ def __exit__(
@overload
def read_sas(
filepath_or_buffer: FilePath | ReadBuffer[bytes],
*,
format: str | None = ...,
index: Hashable | None = ...,
encoding: str | None = ...,
Expand All @@ -74,6 +72,7 @@ def read_sas(
@overload
def read_sas(
filepath_or_buffer: FilePath | ReadBuffer[bytes],
*,
format: str | None = ...,
index: Hashable | None = ...,
encoding: str | None = ...,
Expand All @@ -84,10 +83,10 @@ def read_sas(
...


@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
@doc(decompression_options=_shared_docs["decompression_options"] % "filepath_or_buffer")
def read_sas(
filepath_or_buffer: FilePath | ReadBuffer[bytes],
*,
format: str | None = None,
index: Hashable | None = None,
encoding: str | None = None,
Expand Down

0 comments on commit 7fddb30

Please sign in to comment.