Skip to content

Commit 6c7dad3

Browse files
authored
DEPR: disallow non-keyword arguments (#49259)
* DEPR: non-keyword args in mask, to_stata * DEPR: non-keyword args in set_axis, where * DEPR: non-keyword args in rename_axis, clip * DEPR: non-keyword arguments in ffill, bfill * DEPR: non-keyword arguments in replace, sort_values * typo fixup * fix asv * troubleshoot asvs * update asv
1 parent 86c3d42 commit 6c7dad3

File tree

15 files changed

+48
-221
lines changed

15 files changed

+48
-221
lines changed

asv_bench/benchmarks/io/stata.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def setup(self, convert_dates):
3838
)
3939
self.df["float32_"] = np.array(np.random.randn(N), dtype=np.float32)
4040
self.convert_dates = {"index": convert_dates}
41-
self.df.to_stata(self.fname, self.convert_dates)
41+
self.df.to_stata(self.fname, convert_dates=self.convert_dates)
4242

4343
def time_read_stata(self, convert_dates):
4444
read_stata(self.fname)
4545

4646
def time_write_stata(self, convert_dates):
47-
self.df.to_stata(self.fname, self.convert_dates)
47+
self.df.to_stata(self.fname, convert_dates=self.convert_dates)
4848

4949

5050
class StataMissing(Stata):
@@ -54,7 +54,7 @@ def setup(self, convert_dates):
5454
missing_data = np.random.randn(self.N)
5555
missing_data[missing_data < 0] = np.nan
5656
self.df[f"missing_{i}"] = missing_data
57-
self.df.to_stata(self.fname, self.convert_dates)
57+
self.df.to_stata(self.fname, convert_dates=self.convert_dates)
5858

5959

6060
from ..pandas_vb_common import setup # noqa: F401 isort:skip

doc/source/whatsnew/v2.0.0.rst

+10
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ Removal of prior version deprecations/changes
186186
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
187187
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
188188
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
189+
- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`)
190+
- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`)
191+
- Disallow passing non-keyword arguments to :meth:`DataFrame.where` and :meth:`Series.where` except for ``cond`` and ``other`` (:issue:`41523`)
192+
- Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`)
193+
- Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`)
194+
- Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`)
195+
- Disallow passing non-keyword arguments to :meth:`Series.bfill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill` and :meth:`DataFrame.ffill` (:issue:`41508`)
196+
- Disallow passing non-keyword arguments to :meth:`DataFrame.replace`, :meth:`Series.replace` except for ``to_replace`` and ``value`` (:issue:`47587`)
197+
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_values` except for ``by`` (:issue:`41505`)
198+
- Disallow passing non-keyword arguments to :meth:`Series.sort_values` (:issue:`41505`)
189199
- Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`)
190200
- Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
191201
- Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`)

pandas/core/frame.py

+12-25
Original file line numberDiff line numberDiff line change
@@ -2621,10 +2621,10 @@ def _from_arrays(
26212621
compression_options=_shared_docs["compression_options"] % "path",
26222622
)
26232623
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
2624-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "path"])
26252624
def to_stata(
26262625
self,
26272626
path: FilePath | WriteBuffer[bytes],
2627+
*,
26282628
convert_dates: dict[Hashable, str] | None = None,
26292629
write_index: bool = True,
26302630
byteorder: str | None = None,
@@ -2635,7 +2635,6 @@ def to_stata(
26352635
convert_strl: Sequence[Hashable] | None = None,
26362636
compression: CompressionOptions = "infer",
26372637
storage_options: StorageOptions = None,
2638-
*,
26392638
value_labels: dict[Hashable, dict[float, str]] | None = None,
26402639
) -> None:
26412640
"""
@@ -5141,7 +5140,6 @@ def set_axis(
51415140
...
51425141

51435142
# error: Signature of "set_axis" incompatible with supertype "NDFrame"
5144-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
51455143
@Appender(
51465144
"""
51475145
Examples
@@ -5183,9 +5181,9 @@ def set_axis(
51835181
def set_axis(
51845182
self,
51855183
labels,
5184+
*,
51865185
axis: Axis = 0,
51875186
inplace: bool | lib.NoDefault = lib.no_default,
5188-
*,
51895187
copy: bool | lib.NoDefault = lib.no_default,
51905188
):
51915189
return super().set_axis(labels, axis=axis, inplace=inplace, copy=copy)
@@ -5719,14 +5717,12 @@ def replace(
57195717
...
57205718

57215719
# error: Signature of "replace" incompatible with supertype "NDFrame"
5722-
@deprecate_nonkeyword_arguments(
5723-
version=None, allowed_args=["self", "to_replace", "value"]
5724-
)
57255720
@doc(NDFrame.replace, **_shared_doc_kwargs)
57265721
def replace( # type: ignore[override]
57275722
self,
57285723
to_replace=None,
57295724
value=lib.no_default,
5725+
*,
57305726
inplace: bool = False,
57315727
limit: int | None = None,
57325728
regex: bool = False,
@@ -6868,12 +6864,12 @@ def sort_values(
68686864

68696865
# TODO: Just move the sort_values doc here.
68706866
# error: Signature of "sort_values" incompatible with supertype "NDFrame"
6871-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "by"])
68726867
@Substitution(**_shared_doc_kwargs)
68736868
@Appender(NDFrame.sort_values.__doc__)
68746869
def sort_values( # type: ignore[override]
68756870
self,
68766871
by: IndexLabel,
6872+
*,
68776873
axis: Axis = 0,
68786874
ascending: bool | list[bool] | tuple[bool, ...] = True,
68796875
inplace: bool = False,
@@ -11776,10 +11772,9 @@ def ffill(
1177611772
) -> DataFrame | None:
1177711773
...
1177811774

11779-
# error: Signature of "ffill" incompatible with supertype "NDFrame"
11780-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
11781-
def ffill( # type: ignore[override]
11775+
def ffill(
1178211776
self,
11777+
*,
1178311778
axis: None | Axis = None,
1178411779
inplace: bool = False,
1178511780
limit: None | int = None,
@@ -11820,30 +11815,26 @@ def bfill(
1182011815
) -> DataFrame | None:
1182111816
...
1182211817

11823-
# error: Signature of "bfill" incompatible with supertype "NDFrame"
11824-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
11825-
def bfill( # type: ignore[override]
11818+
def bfill(
1182611819
self,
11820+
*,
1182711821
axis: None | Axis = None,
1182811822
inplace: bool = False,
1182911823
limit: None | int = None,
1183011824
downcast=None,
1183111825
) -> DataFrame | None:
1183211826
return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)
1183311827

11834-
@deprecate_nonkeyword_arguments(
11835-
version=None, allowed_args=["self", "lower", "upper"]
11836-
)
1183711828
def clip(
1183811829
self: DataFrame,
1183911830
lower: float | None = None,
1184011831
upper: float | None = None,
11832+
*,
1184111833
axis: Axis | None = None,
1184211834
inplace: bool = False,
11843-
*args,
1184411835
**kwargs,
1184511836
) -> DataFrame | None:
11846-
return super().clip(lower, upper, axis, inplace, *args, **kwargs)
11837+
return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs)
1184711838

1184811839
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
1184911840
def interpolate(
@@ -11909,13 +11900,11 @@ def where(
1190911900

1191011901
# error: Signature of "where" incompatible with supertype "NDFrame"
1191111902
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
11912-
@deprecate_nonkeyword_arguments(
11913-
version=None, allowed_args=["self", "cond", "other"]
11914-
)
1191511903
def where( # type: ignore[override]
1191611904
self,
1191711905
cond,
1191811906
other=lib.no_default,
11907+
*,
1191911908
inplace: bool = False,
1192011909
axis: Axis | None = None,
1192111910
level: Level = None,
@@ -11970,13 +11959,11 @@ def mask(
1197011959

1197111960
# error: Signature of "mask" incompatible with supertype "NDFrame"
1197211961
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
11973-
@deprecate_nonkeyword_arguments(
11974-
version=None, allowed_args=["self", "cond", "other"]
11975-
)
1197611962
def mask( # type: ignore[override]
1197711963
self,
1197811964
cond,
1197911965
other=lib.no_default,
11966+
*,
1198011967
inplace: bool = False,
1198111968
axis: Axis | None = None,
1198211969
level: Level = None,

pandas/core/generic.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,12 @@ def set_axis(
750750
) -> NDFrameT | None:
751751
...
752752

753-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
754753
def set_axis(
755754
self: NDFrameT,
756755
labels,
756+
*,
757757
axis: Axis = 0,
758758
inplace: bool_t | lib.NoDefault = lib.no_default,
759-
*,
760759
copy: bool_t | lib.NoDefault = lib.no_default,
761760
) -> NDFrameT | None:
762761
"""
@@ -1154,10 +1153,10 @@ def rename_axis(
11541153
...
11551154

11561155
@rewrite_axis_style_signature("mapper", [("copy", True)])
1157-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "mapper"])
11581156
def rename_axis(
11591157
self: NDFrameT,
11601158
mapper: IndexLabel | lib.NoDefault = lib.no_default,
1159+
*,
11611160
inplace: bool_t = False,
11621161
**kwargs,
11631162
) -> NDFrameT | None:
@@ -4813,9 +4812,9 @@ def sort_values(
48134812
) -> NDFrameT | None:
48144813
...
48154814

4816-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
48174815
def sort_values(
48184816
self: NDFrameT,
4817+
*,
48194818
axis: Axis = 0,
48204819
ascending: bool_t | Sequence[bool_t] = True,
48214820
inplace: bool_t = False,
@@ -7007,10 +7006,10 @@ def ffill(
70077006
) -> NDFrameT | None:
70087007
...
70097008

7010-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
70117009
@doc(klass=_shared_doc_kwargs["klass"])
70127010
def ffill(
70137011
self: NDFrameT,
7012+
*,
70147013
axis: None | Axis = None,
70157014
inplace: bool_t = False,
70167015
limit: None | int = None,
@@ -7063,10 +7062,10 @@ def bfill(
70637062
) -> NDFrameT | None:
70647063
...
70657064

7066-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
70677065
@doc(klass=_shared_doc_kwargs["klass"])
70687066
def bfill(
70697067
self: NDFrameT,
7068+
*,
70707069
axis: None | Axis = None,
70717070
inplace: bool_t = False,
70727071
limit: None | int = None,
@@ -7125,9 +7124,6 @@ def replace(
71257124
) -> NDFrameT | None:
71267125
...
71277126

7128-
@deprecate_nonkeyword_arguments(
7129-
version=None, allowed_args=["self", "to_replace", "value"]
7130-
)
71317127
@doc(
71327128
_shared_docs["replace"],
71337129
klass=_shared_doc_kwargs["klass"],
@@ -7138,6 +7134,7 @@ def replace(
71387134
self: NDFrameT,
71397135
to_replace=None,
71407136
value=lib.no_default,
7137+
*,
71417138
inplace: bool_t = False,
71427139
limit: int | None = None,
71437140
regex: bool_t = False,
@@ -8000,9 +7997,9 @@ def clip(
80007997
self: NDFrameT,
80017998
lower=None,
80027999
upper=None,
8000+
*,
80038001
axis: Axis | None = None,
80048002
inplace: bool_t = False,
8005-
*args,
80068003
**kwargs,
80078004
) -> NDFrameT | None:
80088005
"""
@@ -8105,7 +8102,7 @@ def clip(
81058102
"""
81068103
inplace = validate_bool_kwarg(inplace, "inplace")
81078104

8108-
axis = nv.validate_clip_with_axis(axis, args, kwargs)
8105+
axis = nv.validate_clip_with_axis(axis, (), kwargs)
81098106
if axis is not None:
81108107
axis = self._get_axis_number(axis)
81118108

@@ -9827,9 +9824,6 @@ def where(
98279824
...
98289825

98299826
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
9830-
@deprecate_nonkeyword_arguments(
9831-
version=None, allowed_args=["self", "cond", "other"]
9832-
)
98339827
@doc(
98349828
klass=_shared_doc_kwargs["klass"],
98359829
cond="True",
@@ -9841,6 +9835,7 @@ def where(
98419835
self: NDFrameT,
98429836
cond,
98439837
other=np.nan,
9838+
*,
98449839
inplace: bool_t = False,
98459840
axis: Axis | None = None,
98469841
level: Level = None,
@@ -10035,9 +10030,6 @@ def mask(
1003510030
...
1003610031

1003710032
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
10038-
@deprecate_nonkeyword_arguments(
10039-
version=None, allowed_args=["self", "cond", "other"]
10040-
)
1004110033
@doc(
1004210034
where,
1004310035
klass=_shared_doc_kwargs["klass"],
@@ -10050,6 +10042,7 @@ def mask(
1005010042
self: NDFrameT,
1005110043
cond,
1005210044
other=lib.no_default,
10045+
*,
1005310046
inplace: bool_t = False,
1005410047
axis: Axis | None = None,
1005510048
level: Level = None,

0 commit comments

Comments
 (0)