Skip to content

DEPR: disallow non-keyword arguments #49259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def setup(self, convert_dates):
)
self.df["float32_"] = np.array(np.random.randn(N), dtype=np.float32)
self.convert_dates = {"index": convert_dates}
self.df.to_stata(self.fname, self.convert_dates)
self.df.to_stata(self.fname, convert_dates=self.convert_dates)

def time_read_stata(self, convert_dates):
read_stata(self.fname)

def time_write_stata(self, convert_dates):
self.df.to_stata(self.fname, self.convert_dates)
self.df.to_stata(self.fname, convert_dates=self.convert_dates)


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


from ..pandas_vb_common import setup # noqa: F401 isort:skip
10 changes: 10 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ 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:`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`)
- Disallow passing non-keyword arguments to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` except for ``labels`` (:issue:`41491`)
- Disallow passing non-keyword arguments to :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` except for ``mapper`` (:issue:`47587`)
- Disallow passing non-keyword arguments to :meth:`Series.clip` and :meth:`DataFrame.clip` (:issue:`41511`)
- Disallow passing non-keyword arguments to :meth:`Series.bfill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill` and :meth:`DataFrame.ffill` (:issue:`41508`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.replace`, :meth:`Series.replace` except for ``to_replace`` and ``value`` (:issue:`47587`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_values` except for ``by`` (:issue:`41505`)
- Disallow passing non-keyword arguments to :meth:`Series.sort_values` (:issue:`41505`)
- Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`)
- Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
- Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`)
Expand Down
37 changes: 12 additions & 25 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2621,10 +2621,10 @@ def _from_arrays(
compression_options=_shared_docs["compression_options"] % "path",
)
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "path"])
def to_stata(
self,
path: FilePath | WriteBuffer[bytes],
*,
convert_dates: dict[Hashable, str] | None = None,
write_index: bool = True,
byteorder: str | None = None,
Expand All @@ -2635,7 +2635,6 @@ def to_stata(
convert_strl: Sequence[Hashable] | None = None,
compression: CompressionOptions = "infer",
storage_options: StorageOptions = None,
*,
value_labels: dict[Hashable, dict[float, str]] | None = None,
) -> None:
"""
Expand Down Expand Up @@ -5141,7 +5140,6 @@ def set_axis(
...

# error: Signature of "set_axis" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
@Appender(
"""
Examples
Expand Down Expand Up @@ -5183,9 +5181,9 @@ def set_axis(
def set_axis(
self,
labels,
*,
axis: Axis = 0,
inplace: bool | lib.NoDefault = lib.no_default,
*,
copy: bool | lib.NoDefault = lib.no_default,
):
return super().set_axis(labels, axis=axis, inplace=inplace, copy=copy)
Expand Down Expand Up @@ -5719,14 +5717,12 @@ def replace(
...

# error: Signature of "replace" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "to_replace", "value"]
)
@doc(NDFrame.replace, **_shared_doc_kwargs)
def replace( # type: ignore[override]
self,
to_replace=None,
value=lib.no_default,
*,
inplace: bool = False,
limit: int | None = None,
regex: bool = False,
Expand Down Expand Up @@ -6868,12 +6864,12 @@ def sort_values(

# TODO: Just move the sort_values doc here.
# error: Signature of "sort_values" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "by"])
@Substitution(**_shared_doc_kwargs)
@Appender(NDFrame.sort_values.__doc__)
def sort_values( # type: ignore[override]
self,
by: IndexLabel,
*,
axis: Axis = 0,
ascending: bool | list[bool] | tuple[bool, ...] = True,
inplace: bool = False,
Expand Down Expand Up @@ -11776,10 +11772,9 @@ def ffill(
) -> DataFrame | None:
...

# error: Signature of "ffill" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def ffill( # type: ignore[override]
def ffill(
self,
*,
axis: None | Axis = None,
inplace: bool = False,
limit: None | int = None,
Expand Down Expand Up @@ -11820,30 +11815,26 @@ def bfill(
) -> DataFrame | None:
...

# error: Signature of "bfill" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def bfill( # type: ignore[override]
def bfill(
self,
*,
axis: None | Axis = None,
inplace: bool = False,
limit: None | int = None,
downcast=None,
) -> DataFrame | None:
return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)

@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "lower", "upper"]
)
def clip(
self: DataFrame,
lower: float | None = None,
upper: float | None = None,
*,
axis: Axis | None = None,
inplace: bool = False,
*args,
**kwargs,
) -> DataFrame | None:
return super().clip(lower, upper, axis, inplace, *args, **kwargs)
return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
def interpolate(
Expand Down Expand Up @@ -11909,13 +11900,11 @@ def where(

# error: Signature of "where" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
def where( # type: ignore[override]
self,
cond,
other=lib.no_default,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
Expand Down Expand Up @@ -11970,13 +11959,11 @@ def mask(

# error: Signature of "mask" incompatible with supertype "NDFrame"
@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
def mask( # type: ignore[override]
self,
cond,
other=lib.no_default,
*,
inplace: bool = False,
axis: Axis | None = None,
level: Level = None,
Expand Down
27 changes: 10 additions & 17 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,12 @@ def set_axis(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
def set_axis(
self: NDFrameT,
labels,
*,
axis: Axis = 0,
inplace: bool_t | lib.NoDefault = lib.no_default,
*,
copy: bool_t | lib.NoDefault = lib.no_default,
) -> NDFrameT | None:
"""
Expand Down Expand Up @@ -1154,10 +1153,10 @@ def rename_axis(
...

@rewrite_axis_style_signature("mapper", [("copy", True)])
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "mapper"])
def rename_axis(
self: NDFrameT,
mapper: IndexLabel | lib.NoDefault = lib.no_default,
*,
inplace: bool_t = False,
**kwargs,
) -> NDFrameT | None:
Expand Down Expand Up @@ -4813,9 +4812,9 @@ def sort_values(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def sort_values(
self: NDFrameT,
*,
axis: Axis = 0,
ascending: bool_t | Sequence[bool_t] = True,
inplace: bool_t = False,
Expand Down Expand Up @@ -7007,10 +7006,10 @@ def ffill(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
@doc(klass=_shared_doc_kwargs["klass"])
def ffill(
self: NDFrameT,
*,
axis: None | Axis = None,
inplace: bool_t = False,
limit: None | int = None,
Expand Down Expand Up @@ -7063,10 +7062,10 @@ def bfill(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
@doc(klass=_shared_doc_kwargs["klass"])
def bfill(
self: NDFrameT,
*,
axis: None | Axis = None,
inplace: bool_t = False,
limit: None | int = None,
Expand Down Expand Up @@ -7125,9 +7124,6 @@ def replace(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "to_replace", "value"]
)
@doc(
_shared_docs["replace"],
klass=_shared_doc_kwargs["klass"],
Expand All @@ -7138,6 +7134,7 @@ def replace(
self: NDFrameT,
to_replace=None,
value=lib.no_default,
*,
inplace: bool_t = False,
limit: int | None = None,
regex: bool_t = False,
Expand Down Expand Up @@ -8000,9 +7997,9 @@ def clip(
self: NDFrameT,
lower=None,
upper=None,
*,
axis: Axis | None = None,
inplace: bool_t = False,
*args,
**kwargs,
) -> NDFrameT | None:
"""
Expand Down Expand Up @@ -8105,7 +8102,7 @@ def clip(
"""
inplace = validate_bool_kwarg(inplace, "inplace")

axis = nv.validate_clip_with_axis(axis, args, kwargs)
axis = nv.validate_clip_with_axis(axis, (), kwargs)
if axis is not None:
axis = self._get_axis_number(axis)

Expand Down Expand Up @@ -9827,9 +9824,6 @@ def where(
...

@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
@doc(
klass=_shared_doc_kwargs["klass"],
cond="True",
Expand All @@ -9841,6 +9835,7 @@ def where(
self: NDFrameT,
cond,
other=np.nan,
*,
inplace: bool_t = False,
axis: Axis | None = None,
level: Level = None,
Expand Down Expand Up @@ -10035,9 +10030,6 @@ def mask(
...

@deprecate_kwarg(old_arg_name="errors", new_arg_name=None)
@deprecate_nonkeyword_arguments(
version=None, allowed_args=["self", "cond", "other"]
)
@doc(
where,
klass=_shared_doc_kwargs["klass"],
Expand All @@ -10050,6 +10042,7 @@ def mask(
self: NDFrameT,
cond,
other=lib.no_default,
*,
inplace: bool_t = False,
axis: Axis | None = None,
level: Level = None,
Expand Down
Loading