Skip to content

Commit 17e0e06

Browse files
authored
DEPR: non-keyword arguments (#49359)
* DEPR: non-keyword arguments * fix asv
1 parent 1506ed5 commit 17e0e06

File tree

24 files changed

+41
-220
lines changed

24 files changed

+41
-220
lines changed

asv_bench/benchmarks/reshape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def setup(self):
3636
self.df = DataFrame(data)
3737

3838
def time_reshape_pivot_time_series(self):
39-
self.df.pivot("date", "variable", "value")
39+
self.df.pivot(index="date", columns="variable", values="value")
4040

4141

4242
class SimpleReshape:

doc/source/whatsnew/v2.0.0.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ 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.set_index` except ``keys`` (:issue:`41495`)
201+
- Disallow passing non-keyword arguments to :meth:`Resampler.interpolate` except ``method`` (:issue:`41699`)
202+
- Disallow passing non-keyword arguments to :meth:`DataFrame.reset_index` and :meth:`Series.reset_index` except ``level`` (:issue:`41496`)
203+
- Disallow passing non-keyword arguments to :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41504`)
204+
- Disallow passing non-keyword arguments to :meth:`ExtensionArray.argsort` (:issue:`46134`)
205+
- Disallow passing non-keyword arguments to :meth:`Categorical.sort_values` (:issue:`47618`)
206+
- Disallow passing non-keyword arguments to :meth:`Index.drop_duplicates` and :meth:`Series.drop_duplicates` (:issue:`41485`)
200207
- Disallow passing non-keyword arguments to :meth:`DataFrame.drop_duplicates` except for ``subset`` (:issue:`41485`)
201208
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41506`)
202209
- Disallow passing non-keyword arguments to :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` except for ``method`` (:issue:`41510`)
@@ -209,6 +216,9 @@ Removal of prior version deprecations/changes
209216
- Disallow passing non-keyword arguments to :func:`read_json` except for ``path_or_buf`` (:issue:`27573`)
210217
- Disallow passing non-keyword arguments to :func:`read_sas` except for ``filepath_or_buffer`` (:issue:`47154`)
211218
- Disallow passing non-keyword arguments to :func:`read_stata` except for ``filepath_or_buffer`` (:issue:`48128`)
219+
- Disallow passing non-keyword arguments to :func:`read_csv` except ``filepath_or_buffer`` (:issue:`41485`)
220+
- Disallow passing non-keyword arguments to :func:`read_table` except ``filepath_or_buffer`` (:issue:`41485`)
221+
- Disallow passing non-keyword arguments to :func:`read_fwf` except ``filepath_or_buffer`` (:issue:`44710`)
212222
- Disallow passing non-keyword arguments to :func:`read_xml` except for ``path_or_buffer`` (:issue:`45133`)
213223
- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`)
214224
- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`)

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
pa_version_under6p0,
2121
pa_version_under7p0,
2222
)
23-
from pandas.util._decorators import (
24-
deprecate_nonkeyword_arguments,
25-
doc,
26-
)
23+
from pandas.util._decorators import doc
2724

2825
from pandas.core.dtypes.common import (
2926
is_array_like,
@@ -452,13 +449,12 @@ def isna(self) -> npt.NDArray[np.bool_]:
452449
"""
453450
return self._data.is_null().to_numpy()
454451

455-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
456452
def argsort(
457453
self,
454+
*,
458455
ascending: bool = True,
459456
kind: SortKind = "quicksort",
460457
na_position: str = "last",
461-
*args,
462458
**kwargs,
463459
) -> np.ndarray:
464460
order = "ascending" if ascending else "descending"

pandas/core/arrays/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
Appender,
4949
Substitution,
5050
cache_readonly,
51-
deprecate_nonkeyword_arguments,
5251
)
5352
from pandas.util._exceptions import find_stack_level
5453
from pandas.util._validators import (
@@ -662,13 +661,12 @@ def _values_for_argsort(self) -> np.ndarray:
662661
# Note: this is used in `ExtensionArray.argsort/argmin/argmax`.
663662
return np.array(self)
664663

665-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
666664
def argsort(
667665
self,
666+
*,
668667
ascending: bool = True,
669668
kind: SortKind = "quicksort",
670669
na_position: str = "last",
671-
*args,
672670
**kwargs,
673671
) -> np.ndarray:
674672
"""
@@ -699,7 +697,7 @@ def argsort(
699697
# 1. _values_for_argsort : construct the values passed to np.argsort
700698
# 2. argsort : total control over sorting. In case of overriding this,
701699
# it is recommended to also override argmax/argmin
702-
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
700+
ascending = nv.validate_argsort_with_ascending(ascending, (), kwargs)
703701

704702
values = self._values_for_argsort()
705703
return nargsort(

pandas/core/arrays/categorical.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,10 +1802,8 @@ def check_for_ordered(self, op) -> None:
18021802
"Categorical to an ordered one\n"
18031803
)
18041804

1805-
# error: Signature of "argsort" incompatible with supertype "ExtensionArray"
1806-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
1807-
def argsort( # type: ignore[override]
1808-
self, ascending: bool = True, kind: SortKind = "quicksort", **kwargs
1805+
def argsort(
1806+
self, *, ascending: bool = True, kind: SortKind = "quicksort", **kwargs
18091807
):
18101808
"""
18111809
Return the indices that would sort the Categorical.
@@ -1875,9 +1873,12 @@ def sort_values(
18751873
) -> None:
18761874
...
18771875

1878-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
18791876
def sort_values(
1880-
self, inplace: bool = False, ascending: bool = True, na_position: str = "last"
1877+
self,
1878+
*,
1879+
inplace: bool = False,
1880+
ascending: bool = True,
1881+
na_position: str = "last",
18811882
) -> Categorical | None:
18821883
"""
18831884
Sort the Categorical by category value returning a new

pandas/core/arrays/interval.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@
4343
)
4444
from pandas.compat.numpy import function as nv
4545
from pandas.errors import IntCastingNaNError
46-
from pandas.util._decorators import (
47-
Appender,
48-
deprecate_nonkeyword_arguments,
49-
)
46+
from pandas.util._decorators import Appender
5047

5148
from pandas.core.dtypes.cast import LossySetitemError
5249
from pandas.core.dtypes.common import (
@@ -796,16 +793,15 @@ def __lt__(self, other):
796793
def __le__(self, other):
797794
return self._cmp_method(other, operator.le)
798795

799-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
800796
def argsort(
801797
self,
798+
*,
802799
ascending: bool = True,
803800
kind: SortKind = "quicksort",
804801
na_position: str = "last",
805-
*args,
806802
**kwargs,
807803
) -> np.ndarray:
808-
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
804+
ascending = nv.validate_argsort_with_ascending(ascending, (), kwargs)
809805

810806
if ascending and kind == "quicksort" and na_position == "last":
811807
return np.lexsort((self.right, self.left))

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def searchsorted(
13041304
sorter=sorter,
13051305
)
13061306

1307-
def drop_duplicates(self, keep: DropKeep = "first"):
1307+
def drop_duplicates(self, *, keep: DropKeep = "first"):
13081308
duplicated = self._duplicated(keep=keep)
13091309
# error: Value of type "IndexOpsMixin" is not indexable
13101310
return self[~duplicated] # type: ignore[index]

pandas/core/frame.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5835,10 +5835,10 @@ def set_index(
58355835
) -> None:
58365836
...
58375837

5838-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "keys"])
58395838
def set_index(
58405839
self,
58415840
keys,
5841+
*,
58425842
drop: bool = True,
58435843
append: bool = False,
58445844
inplace: bool = False,
@@ -6080,10 +6080,10 @@ def reset_index(
60806080
) -> DataFrame | None:
60816081
...
60826082

6083-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
60846083
def reset_index(
60856084
self,
60866085
level: IndexLabel = None,
6086+
*,
60876087
drop: bool = False,
60886088
inplace: bool = False,
60896089
col_level: Hashable = 0,
@@ -6376,9 +6376,9 @@ def dropna(
63766376
) -> None:
63776377
...
63786378

6379-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
63806379
def dropna(
63816380
self,
6381+
*,
63826382
axis: Axis = 0,
63836383
how: AnyAll | NoDefault = no_default,
63846384
thresh: int | NoDefault = no_default,
@@ -8500,9 +8500,8 @@ def groupby(
85008500

85018501
@Substitution("")
85028502
@Appender(_shared_docs["pivot"])
8503-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
85048503
def pivot(
8505-
self, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
8504+
self, *, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
85068505
) -> DataFrame:
85078506
from pandas.core.reshape.pivot import pivot
85088507

pandas/core/indexes/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
from pandas.util._decorators import (
6868
Appender,
6969
cache_readonly,
70-
deprecate_nonkeyword_arguments,
7170
doc,
7271
)
7372
from pandas.util._exceptions import (
@@ -2894,8 +2893,7 @@ def unique(self: _IndexT, level: Hashable | None = None) -> _IndexT:
28942893
result = super().unique()
28952894
return self._shallow_copy(result)
28962895

2897-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
2898-
def drop_duplicates(self: _IndexT, keep: DropKeep = "first") -> _IndexT:
2896+
def drop_duplicates(self: _IndexT, *, keep: DropKeep = "first") -> _IndexT:
28992897
"""
29002898
Return Index with duplicate values removed.
29012899

pandas/core/resample.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from pandas.util._decorators import (
4747
Appender,
4848
Substitution,
49-
deprecate_nonkeyword_arguments,
5049
doc,
5150
)
5251

@@ -881,11 +880,11 @@ def fillna(self, method, limit=None):
881880
"""
882881
return self._upsample(method, limit=limit)
883882

884-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
885883
@doc(NDFrame.interpolate, **_shared_docs_kwargs)
886884
def interpolate(
887885
self,
888886
method: QuantileInterpolation = "linear",
887+
*,
889888
axis: Axis = 0,
890889
limit=None,
891890
inplace: bool = False,

0 commit comments

Comments
 (0)