Skip to content

Commit 7fddb30

Browse files
DEPR: non-keyword arguments (#49302)
* DEPR: non-keyword arguments * Update doc/source/whatsnew/v2.0.0.rst Co-authored-by: Matthew Roeschke <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 032316f commit 7fddb30

24 files changed

+71
-221
lines changed

doc/source/whatsnew/v2.0.0.rst

+13
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ Removal of prior version deprecations/changes
197197
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
198198
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
199199
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
200+
- Disallow passing non-keyword arguments to :meth:`DataFrame.drop_duplicates` except for ``subset`` (:issue:`41485`)
201+
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41506`)
202+
- Disallow passing non-keyword arguments to :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` except for ``method`` (:issue:`41510`)
203+
- Disallow passing non-keyword arguments to :meth:`DataFrame.any` and :meth:`Series.any` (:issue:`44896`)
204+
- Disallow passing non-keyword arguments to :meth:`Index.set_names` except for ``names`` (:issue:`41551`)
205+
- Disallow passing non-keyword arguments to :meth:`Index.join` except for ``other`` (:issue:`46518`)
206+
- Disallow passing non-keyword arguments to :func:`concat` except for ``objs`` (:issue:`41485`)
207+
- Disallow passing non-keyword arguments to :func:`pivot` except for ``data`` (:issue:`48301`)
208+
- Disallow passing non-keyword arguments to :meth:`DataFrame.pivot` (:issue:`48301`)
209+
- Disallow passing non-keyword arguments to :func:`read_json` except for ``path_or_buf`` (:issue:`27573`)
210+
- Disallow passing non-keyword arguments to :func:`read_sas` except for ``filepath_or_buffer`` (:issue:`47154`)
211+
- Disallow passing non-keyword arguments to :func:`read_stata` except for ``filepath_or_buffer`` (:issue:`48128`)
212+
- Disallow passing non-keyword arguments to :func:`read_xml` except for ``path_or_buffer`` (:issue:`45133`)
200213
- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`)
201214
- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`)
202215
- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523`)

pandas/core/frame.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -6538,10 +6538,10 @@ def dropna(
65386538
self._update_inplace(result)
65396539
return None
65406540

6541-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "subset"])
65426541
def drop_duplicates(
65436542
self,
65446543
subset: Hashable | Sequence[Hashable] | None = None,
6544+
*,
65456545
keep: DropKeep = "first",
65466546
inplace: bool = False,
65476547
ignore_index: bool = False,
@@ -6946,10 +6946,9 @@ def sort_index(
69466946
) -> DataFrame | None:
69476947
...
69486948

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

11779-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
1178011778
def interpolate(
1178111779
self: DataFrame,
1178211780
method: str = "linear",
11781+
*,
1178311782
axis: Axis = 0,
1178411783
limit: int | None = None,
1178511784
inplace: bool = False,
@@ -11789,13 +11788,13 @@ def interpolate(
1178911788
**kwargs,
1179011789
) -> DataFrame | None:
1179111790
return super().interpolate(
11792-
method,
11793-
axis,
11794-
limit,
11795-
inplace,
11796-
limit_direction,
11797-
limit_area,
11798-
downcast,
11791+
method=method,
11792+
axis=axis,
11793+
limit=limit,
11794+
inplace=inplace,
11795+
limit_direction=limit_direction,
11796+
limit_area=limit_area,
11797+
downcast=downcast,
1179911798
**kwargs,
1180011799
)
1180111800

pandas/core/generic.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,7 @@ def sort_index(
50005000

50015001
def sort_index(
50025002
self: NDFrameT,
5003+
*,
50035004
axis: Axis = 0,
50045005
level: IndexLabel = None,
50055006
ascending: bool_t | Sequence[bool_t] = True,
@@ -7312,6 +7313,7 @@ def replace(
73127313
def interpolate(
73137314
self: NDFrameT,
73147315
method: str = "linear",
7316+
*,
73157317
axis: Axis = 0,
73167318
limit: int | None = None,
73177319
inplace: bool_t = False,
@@ -11429,11 +11431,6 @@ def _add_numeric_operations(cls) -> None:
1142911431
"""
1143011432
axis_descr, name1, name2 = _doc_params(cls)
1143111433

11432-
@deprecate_nonkeyword_arguments(
11433-
version=None,
11434-
allowed_args=["self"],
11435-
name="DataFrame.any and Series.any",
11436-
)
1143711434
@doc(
1143811435
_bool_doc,
1143911436
desc=_any_desc,
@@ -11446,13 +11443,21 @@ def _add_numeric_operations(cls) -> None:
1144611443
)
1144711444
def any(
1144811445
self,
11446+
*,
1144911447
axis: Axis = 0,
1145011448
bool_only=None,
1145111449
skipna: bool_t = True,
1145211450
level=None,
1145311451
**kwargs,
1145411452
):
11455-
return NDFrame.any(self, axis, bool_only, skipna, level, **kwargs)
11453+
return NDFrame.any(
11454+
self,
11455+
axis=axis,
11456+
bool_only=bool_only,
11457+
skipna=skipna,
11458+
level=level,
11459+
**kwargs,
11460+
)
1145611461

1145711462
setattr(cls, "any", any)
1145811463

pandas/core/indexes/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def _maybe_return_indexers(meth: F) -> F:
218218
@functools.wraps(meth)
219219
def join(
220220
self,
221-
other,
221+
other: Index,
222+
*,
222223
how: str_t = "left",
223224
level=None,
224225
return_indexers: bool = False,
@@ -1760,9 +1761,8 @@ def set_names(
17601761
) -> _IndexT | None:
17611762
...
17621763

1763-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "names"])
17641764
def set_names(
1765-
self: _IndexT, names, level=None, inplace: bool = False
1765+
self: _IndexT, names, *, level=None, inplace: bool = False
17661766
) -> _IndexT | None:
17671767
"""
17681768
Set Index or MultiIndex name.
@@ -4494,11 +4494,11 @@ def join(
44944494
...
44954495

44964496
@final
4497-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "other"])
44984497
@_maybe_return_indexers
44994498
def join(
45004499
self,
45014500
other: Index,
4501+
*,
45024502
how: str_t = "left",
45034503
level: Level = None,
45044504
return_indexers: bool = False,

pandas/core/indexes/multi.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
from pandas.util._decorators import (
5151
Appender,
5252
cache_readonly,
53-
deprecate_nonkeyword_arguments,
5453
doc,
5554
)
5655
from pandas.util._exceptions import find_stack_level
@@ -3786,10 +3785,8 @@ def set_names(self, names, *, level=..., inplace: Literal[True]) -> None:
37863785
def set_names(self, names, *, level=..., inplace: bool = ...) -> MultiIndex | None:
37873786
...
37883787

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

pandas/core/reshape/concat.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
AxisInt,
2424
HashableT,
2525
)
26-
from pandas.util._decorators import (
27-
cache_readonly,
28-
deprecate_nonkeyword_arguments,
29-
)
26+
from pandas.util._decorators import cache_readonly
3027
from pandas.util._exceptions import find_stack_level
3128

3229
from pandas.core.dtypes.concat import concat_compat
@@ -67,6 +64,7 @@
6764
@overload
6865
def concat(
6966
objs: Iterable[DataFrame] | Mapping[HashableT, DataFrame],
67+
*,
7068
axis: Literal[0, "index"] = ...,
7169
join: str = ...,
7270
ignore_index: bool = ...,
@@ -83,6 +81,7 @@ def concat(
8381
@overload
8482
def concat(
8583
objs: Iterable[Series] | Mapping[HashableT, Series],
84+
*,
8685
axis: Literal[0, "index"] = ...,
8786
join: str = ...,
8887
ignore_index: bool = ...,
@@ -99,6 +98,7 @@ def concat(
9998
@overload
10099
def concat(
101100
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
101+
*,
102102
axis: Literal[0, "index"] = ...,
103103
join: str = ...,
104104
ignore_index: bool = ...,
@@ -115,6 +115,7 @@ def concat(
115115
@overload
116116
def concat(
117117
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
118+
*,
118119
axis: Literal[1, "columns"],
119120
join: str = ...,
120121
ignore_index: bool = ...,
@@ -131,6 +132,7 @@ def concat(
131132
@overload
132133
def concat(
133134
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
135+
*,
134136
axis: Axis = ...,
135137
join: str = ...,
136138
ignore_index: bool = ...,
@@ -144,9 +146,9 @@ def concat(
144146
...
145147

146148

147-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"])
148149
def concat(
149150
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
151+
*,
150152
axis: Axis = 0,
151153
join: str = "outer",
152154
ignore_index: bool = False,

pandas/core/reshape/pivot.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from pandas.util._decorators import (
2121
Appender,
2222
Substitution,
23-
deprecate_nonkeyword_arguments,
2423
)
2524

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

494493
@Substitution("\ndata : DataFrame")
495494
@Appender(_shared_docs["pivot"], indents=1)
496-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["data"])
497495
def pivot(
498496
data: DataFrame,
497+
*,
499498
index: IndexLabel | lib.NoDefault = lib.NoDefault,
500499
columns: IndexLabel | lib.NoDefault = lib.NoDefault,
501500
values: IndexLabel | lib.NoDefault = lib.NoDefault,

pandas/core/series.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -3767,10 +3767,9 @@ def sort_index(
37673767
) -> Series | None:
37683768
...
37693769

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

5996-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
59975995
def interpolate(
59985996
self: Series,
59995997
method: str = "linear",
5998+
*,
60005999
axis: Axis = 0,
60016000
limit: int | None = None,
60026001
inplace: bool = False,
@@ -6006,13 +6005,13 @@ def interpolate(
60066005
**kwargs,
60076006
) -> Series | None:
60086007
return super().interpolate(
6009-
method,
6010-
axis,
6011-
limit,
6012-
inplace,
6013-
limit_direction,
6014-
limit_area,
6015-
downcast,
6008+
method=method,
6009+
axis=axis,
6010+
limit=limit,
6011+
inplace=inplace,
6012+
limit_direction=limit_direction,
6013+
limit_area=limit_area,
6014+
downcast=downcast,
60166015
**kwargs,
60176016
)
60186017

pandas/io/json/_json.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
WriteBuffer,
3535
)
3636
from pandas.errors import AbstractMethodError
37-
from pandas.util._decorators import (
38-
deprecate_nonkeyword_arguments,
39-
doc,
40-
)
37+
from pandas.util._decorators import doc
4138

4239
from pandas.core.dtypes.common import (
4340
ensure_str,
@@ -452,6 +449,7 @@ def read_json(
452449
@overload
453450
def read_json(
454451
path_or_buf: FilePath | ReadBuffer[str] | ReadBuffer[bytes],
452+
*,
455453
orient: str | None = ...,
456454
typ: Literal["frame"] = ...,
457455
dtype: DtypeArg | None = ...,
@@ -475,9 +473,9 @@ def read_json(
475473
storage_options=_shared_docs["storage_options"],
476474
decompression_options=_shared_docs["decompression_options"] % "path_or_buf",
477475
)
478-
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["path_or_buf"])
479476
def read_json(
480477
path_or_buf: FilePath | ReadBuffer[str] | ReadBuffer[bytes],
478+
*,
481479
orient: str | None = None,
482480
typ: Literal["frame", "series"] = "frame",
483481
dtype: DtypeArg | None = None,

pandas/io/sas/sasreader.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
FilePath,
2020
ReadBuffer,
2121
)
22-
from pandas.util._decorators import (
23-
deprecate_nonkeyword_arguments,
24-
doc,
25-
)
22+
from pandas.util._decorators import doc
2623

2724
from pandas.core.shared_docs import _shared_docs
2825

@@ -61,6 +58,7 @@ def __exit__(
6158
@overload
6259
def read_sas(
6360
filepath_or_buffer: FilePath | ReadBuffer[bytes],
61+
*,
6462
format: str | None = ...,
6563
index: Hashable | None = ...,
6664
encoding: str | None = ...,
@@ -74,6 +72,7 @@ def read_sas(
7472
@overload
7573
def read_sas(
7674
filepath_or_buffer: FilePath | ReadBuffer[bytes],
75+
*,
7776
format: str | None = ...,
7877
index: Hashable | None = ...,
7978
encoding: str | None = ...,
@@ -84,10 +83,10 @@ def read_sas(
8483
...
8584

8685

87-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
8886
@doc(decompression_options=_shared_docs["decompression_options"] % "filepath_or_buffer")
8987
def read_sas(
9088
filepath_or_buffer: FilePath | ReadBuffer[bytes],
89+
*,
9190
format: str | None = None,
9291
index: Hashable | None = None,
9392
encoding: str | None = None,

0 commit comments

Comments
 (0)