Skip to content
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

DEPR: Enforce deprecation of args/kwargs in Window #50338

Merged
merged 1 commit into from
Dec 19, 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ Removal of prior version deprecations/changes
- When providing a list of columns of length one to :meth:`DataFrame.groupby`, the keys that are returned by iterating over the resulting :class:`DataFrameGroupBy` object will now be tuples of length one (:issue:`47761`)
- Removed deprecated methods :meth:`ExcelWriter.write_cells`, :meth:`ExcelWriter.save`, :meth:`ExcelWriter.cur_sheet`, :meth:`ExcelWriter.handles`, :meth:`ExcelWriter.path` (:issue:`45795`)
- The :class:`ExcelWriter` attribute ``book`` can no longer be set; it is still available to be accessed and mutated (:issue:`48943`)
- Removed unused ``*args`` and ``**kwargs`` in :class:`Rolling`, :class:`Expanding`, and :class:`ExponentialMovingWindow` ops (:issue:`47851`)
-

.. ---------------------------------------------------------------------------
Expand Down
45 changes: 0 additions & 45 deletions pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,51 +335,6 @@ def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) ->
)


def validate_window_func(name, args, kwargs) -> None:
numpy_args = ("axis", "dtype", "out")
msg = (
f"numpy operations are not valid with window objects. "
f"Use .{name}() directly instead "
)

if len(args) > 0:
raise UnsupportedFunctionCall(msg)

for arg in numpy_args:
if arg in kwargs:
raise UnsupportedFunctionCall(msg)


def validate_rolling_func(name, args, kwargs) -> None:
numpy_args = ("axis", "dtype", "out")
msg = (
f"numpy operations are not valid with window objects. "
f"Use .rolling(...).{name}() instead "
)

if len(args) > 0:
raise UnsupportedFunctionCall(msg)

for arg in numpy_args:
if arg in kwargs:
raise UnsupportedFunctionCall(msg)


def validate_expanding_func(name, args, kwargs) -> None:
numpy_args = ("axis", "dtype", "out")
msg = (
f"numpy operations are not valid with window objects. "
f"Use .expanding(...).{name}() instead "
)

if len(args) > 0:
raise UnsupportedFunctionCall(msg)

for arg in numpy_args:
if arg in kwargs:
raise UnsupportedFunctionCall(msg)


def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
"""
'args' and 'kwargs' should be empty, except for allowed kwargs because all
Expand Down
38 changes: 0 additions & 38 deletions pandas/core/window/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

from collections import defaultdict
from typing import cast
import warnings

import numpy as np

from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.generic import (
ABCDataFrame,
ABCSeries,
Expand Down Expand Up @@ -172,38 +169,3 @@ def prep_binary(arg1, arg2):
X = arg1 + 0 * arg2
Y = arg2 + 0 * arg1
return X, Y


def maybe_warn_args_and_kwargs(cls, kernel: str, args, kwargs) -> None:
"""
Warn for deprecation of args and kwargs in rolling/expanding functions.

Parameters
----------
cls : type
Class to warn about.
kernel : str
Operation name.
args : tuple or None
args passed by user. Will be None if and only if kernel does not have args.
kwargs : dict or None
kwargs passed by user. Will be None if and only if kernel does not have kwargs.
"""
warn_args = args is not None and len(args) > 0
warn_kwargs = kwargs is not None and len(kwargs) > 0
if warn_args and warn_kwargs:
msg = "args and kwargs"
elif warn_args:
msg = "args"
elif warn_kwargs:
msg = "kwargs"
else:
msg = ""
if msg != "":
warnings.warn(
f"Passing additional {msg} to {cls.__name__}.{kernel} has "
"no impact on the result and is deprecated. This will "
"raise a TypeError in a future version of pandas.",
category=FutureWarning,
stacklevel=find_stack_level(),
)
18 changes: 0 additions & 18 deletions pandas/core/window/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ def create_section_header(header: str) -> str:
"""
).replace("\n", "", 1)

args_compat = dedent(
"""
*args
For NumPy compatibility and will not have an effect on the result.

.. deprecated:: 1.5.0\n
"""
).replace("\n", "", 1)

kwargs_compat = dedent(
"""
**kwargs
For NumPy compatibility and will not have an effect on the result.

.. deprecated:: 1.5.0\n
"""
).replace("\n", "", 1)

kwargs_scipy = dedent(
"""
**kwargs
Expand Down
44 changes: 5 additions & 39 deletions pandas/core/window/ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pandas import DataFrame, Series
from pandas.core.generic import NDFrame

from pandas.compat.numpy import function as nv
from pandas.util._decorators import doc

from pandas.core.dtypes.common import (
Expand All @@ -37,15 +36,10 @@
get_jit_arguments,
maybe_use_numba,
)
from pandas.core.window.common import (
maybe_warn_args_and_kwargs,
zsqrt,
)
from pandas.core.window.common import zsqrt
from pandas.core.window.doc import (
_shared_docs,
args_compat,
create_section_header,
kwargs_compat,
kwargs_numeric_only,
numba_notes,
template_header,
Expand Down Expand Up @@ -503,9 +497,7 @@ def aggregate(self, func, *args, **kwargs):
template_header,
create_section_header("Parameters"),
kwargs_numeric_only,
args_compat,
window_agg_numba_parameters(),
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -519,12 +511,9 @@ def aggregate(self, func, *args, **kwargs):
def mean(
self,
numeric_only: bool = False,
*args,
engine=None,
engine_kwargs=None,
**kwargs,
):
maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
if maybe_use_numba(engine):
if self.method == "single":
func = generate_numba_ewm_func
Expand All @@ -542,7 +531,6 @@ def mean(
elif engine in ("cython", None):
if engine_kwargs is not None:
raise ValueError("cython engine does not accept engine_kwargs")
nv.validate_window_func("mean", args, kwargs)

deltas = None if self.times is None else self._deltas
window_func = partial(
Expand All @@ -561,9 +549,7 @@ def mean(
template_header,
create_section_header("Parameters"),
kwargs_numeric_only,
args_compat,
window_agg_numba_parameters(),
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -577,12 +563,9 @@ def mean(
def sum(
self,
numeric_only: bool = False,
*args,
engine=None,
engine_kwargs=None,
**kwargs,
):
maybe_warn_args_and_kwargs(type(self), "sum", args, kwargs)
if not self.adjust:
raise NotImplementedError("sum is not implemented with adjust=False")
if maybe_use_numba(engine):
Expand All @@ -602,7 +585,6 @@ def sum(
elif engine in ("cython", None):
if engine_kwargs is not None:
raise ValueError("cython engine does not accept engine_kwargs")
nv.validate_window_func("sum", args, kwargs)

deltas = None if self.times is None else self._deltas
window_func = partial(
Expand All @@ -627,8 +609,6 @@ def sum(
"""
).replace("\n", "", 1),
kwargs_numeric_only,
args_compat,
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -637,9 +617,7 @@ def sum(
aggregation_description="(exponential weighted moment) standard deviation",
agg_method="std",
)
def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
maybe_warn_args_and_kwargs(type(self), "std", args, kwargs)
nv.validate_window_func("std", args, kwargs)
def std(self, bias: bool = False, numeric_only: bool = False):
if (
numeric_only
and self._selected_obj.ndim == 1
Expand All @@ -649,7 +627,7 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
raise NotImplementedError(
f"{type(self).__name__}.std does not implement numeric_only"
)
return zsqrt(self.var(bias=bias, numeric_only=numeric_only, **kwargs))
return zsqrt(self.var(bias=bias, numeric_only=numeric_only))

@doc(
template_header,
Expand All @@ -661,8 +639,6 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
"""
).replace("\n", "", 1),
kwargs_numeric_only,
args_compat,
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -671,9 +647,7 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
aggregation_description="(exponential weighted moment) variance",
agg_method="var",
)
def var(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
maybe_warn_args_and_kwargs(type(self), "var", args, kwargs)
nv.validate_window_func("var", args, kwargs)
def var(self, bias: bool = False, numeric_only: bool = False):
window_func = window_aggregations.ewmcov
wfunc = partial(
window_func,
Expand Down Expand Up @@ -708,7 +682,6 @@ def var_func(values, begin, end, min_periods):
"""
).replace("\n", "", 1),
kwargs_numeric_only,
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -723,11 +696,9 @@ def cov(
pairwise: bool | None = None,
bias: bool = False,
numeric_only: bool = False,
**kwargs,
):
from pandas import Series

maybe_warn_args_and_kwargs(type(self), "cov", None, kwargs)
self._validate_numeric_only("cov", numeric_only)

def cov_func(x, y):
Expand Down Expand Up @@ -783,7 +754,6 @@ def cov_func(x, y):
"""
).replace("\n", "", 1),
kwargs_numeric_only,
kwargs_compat,
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
Expand All @@ -797,11 +767,9 @@ def corr(
other: DataFrame | Series | None = None,
pairwise: bool | None = None,
numeric_only: bool = False,
**kwargs,
):
from pandas import Series

maybe_warn_args_and_kwargs(type(self), "corr", None, kwargs)
self._validate_numeric_only("corr", numeric_only)

def cov_func(x, y):
Expand Down Expand Up @@ -940,7 +908,6 @@ def corr(
other: DataFrame | Series | None = None,
pairwise: bool | None = None,
numeric_only: bool = False,
**kwargs,
):
raise NotImplementedError("corr is not implemented.")

Expand All @@ -950,11 +917,10 @@ def cov(
pairwise: bool | None = None,
bias: bool = False,
numeric_only: bool = False,
**kwargs,
):
raise NotImplementedError("cov is not implemented.")

def var(self, bias: bool = False, *args, **kwargs):
def var(self, bias: bool = False, numeric_only: bool = False):
raise NotImplementedError("var is not implemented.")

def mean(self, *args, update=None, update_times=None, **kwargs):
Expand Down
Loading