Skip to content

Commit bf046d2

Browse files
jbrockmendelnoatamir
authored andcommitted
DEPR: non-keyword arguments (pandas-dev#49359)
* DEPR: non-keyword arguments * fix asv
1 parent 42af38c commit bf046d2

24 files changed

+41
-220
lines changed

asv_bench/benchmarks/reshape.py

+1-1
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

+10
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

+2-6
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

+2-4
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

+7-6
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

+3-7
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

+1-1
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

+4-5
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

+1-3
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

+1-2
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,

pandas/core/series.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,10 @@ def reset_index(
14091409
) -> None:
14101410
...
14111411

1412-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
14131412
def reset_index(
14141413
self,
14151414
level: IndexLabel = None,
1415+
*,
14161416
drop: bool = False,
14171417
name: Level = lib.no_default,
14181418
inplace: bool = False,
@@ -2186,23 +2186,22 @@ def unique(self) -> ArrayLike:
21862186

21872187
@overload
21882188
def drop_duplicates(
2189-
self, keep: DropKeep = ..., *, inplace: Literal[False] = ...
2189+
self, *, keep: DropKeep = ..., inplace: Literal[False] = ...
21902190
) -> Series:
21912191
...
21922192

21932193
@overload
2194-
def drop_duplicates(self, keep: DropKeep = ..., *, inplace: Literal[True]) -> None:
2194+
def drop_duplicates(self, *, keep: DropKeep = ..., inplace: Literal[True]) -> None:
21952195
...
21962196

21972197
@overload
21982198
def drop_duplicates(
2199-
self, keep: DropKeep = ..., *, inplace: bool = ...
2199+
self, *, keep: DropKeep = ..., inplace: bool = ...
22002200
) -> Series | None:
22012201
...
22022202

2203-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
22042203
def drop_duplicates(
2205-
self, keep: DropKeep = "first", inplace: bool = False
2204+
self, *, keep: DropKeep = "first", inplace: bool = False
22062205
) -> Series | None:
22072206
"""
22082207
Return Series with duplicate values removed.
@@ -5687,9 +5686,9 @@ def dropna(
56875686
) -> None:
56885687
...
56895688

5690-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
56915689
def dropna(
56925690
self,
5691+
*,
56935692
axis: Axis = 0,
56945693
inplace: bool = False,
56955694
how: AnyAll | None = None,

pandas/io/parsers/readers.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from pandas.util._decorators import (
4141
Appender,
4242
deprecate_kwarg,
43-
deprecate_nonkeyword_arguments,
4443
)
4544
from pandas.util._exceptions import find_stack_level
4645
from pandas.util._validators import validate_bool_kwarg
@@ -864,7 +863,6 @@ def read_csv(
864863

865864

866865
@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
867-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
868866
@Appender(
869867
_doc_read_csv_and_table.format(
870868
func_name="read_csv",
@@ -877,6 +875,7 @@ def read_csv(
877875
)
878876
def read_csv(
879877
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
878+
*,
880879
sep: str | None | lib.NoDefault = lib.no_default,
881880
delimiter: str | None | lib.NoDefault = None,
882881
# Column and Index Locations and Names
@@ -1208,7 +1207,6 @@ def read_table(
12081207

12091208

12101209
@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
1211-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
12121210
@Appender(
12131211
_doc_read_csv_and_table.format(
12141212
func_name="read_table",
@@ -1221,6 +1219,7 @@ def read_table(
12211219
)
12221220
def read_table(
12231221
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
1222+
*,
12241223
sep: str | None | lib.NoDefault = lib.no_default,
12251224
delimiter: str | None | lib.NoDefault = None,
12261225
# Column and Index Locations and Names
@@ -1307,9 +1306,9 @@ def read_table(
13071306
return _read(filepath_or_buffer, kwds)
13081307

13091308

1310-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
13111309
def read_fwf(
13121310
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
1311+
*,
13131312
colspecs: Sequence[tuple[int, int]] | str | None = "infer",
13141313
widths: Sequence[int] | None = None,
13151314
infer_nrows: int = 100,

pandas/tests/frame/methods/test_drop.py

-12
Original file line numberDiff line numberDiff line change
@@ -510,18 +510,6 @@ def test_drop_with_duplicate_columns2(self):
510510
result = df2.drop("C", axis=1)
511511
tm.assert_frame_equal(result, expected)
512512

513-
def test_drop_pos_args_deprecation(self):
514-
# https://github.com/pandas-dev/pandas/issues/41485
515-
df = DataFrame({"a": [1, 2, 3]})
516-
msg = (
517-
r"In a future version of pandas all arguments of DataFrame\.drop "
518-
r"except for the argument 'labels' will be keyword-only"
519-
)
520-
with tm.assert_produces_warning(FutureWarning, match=msg):
521-
result = df.drop("a", 1)
522-
expected = DataFrame(index=[0, 1, 2])
523-
tm.assert_frame_equal(result, expected)
524-
525513
def test_drop_inplace_no_leftover_column_reference(self):
526514
# GH 13934
527515
df = DataFrame({"a": [1, 2, 3]})

pandas/tests/frame/methods/test_dropna.py

-12
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ def test_dropna_with_duplicate_columns(self):
231231
result = df.dropna(subset=["A", "C"], how="all")
232232
tm.assert_frame_equal(result, expected)
233233

234-
def test_dropna_pos_args_deprecation(self):
235-
# https://github.com/pandas-dev/pandas/issues/41485
236-
df = DataFrame({"a": [1, 2, 3]})
237-
msg = (
238-
r"In a future version of pandas all arguments of DataFrame\.dropna "
239-
r"will be keyword-only"
240-
)
241-
with tm.assert_produces_warning(FutureWarning, match=msg):
242-
result = df.dropna(1)
243-
expected = DataFrame({"a": [1, 2, 3]})
244-
tm.assert_frame_equal(result, expected)
245-
246234
def test_set_single_column_subset(self):
247235
# GH 41021
248236
df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]})

0 commit comments

Comments
 (0)