Skip to content

Commit 2fbea3f

Browse files
authored
DEPR: Enforce deprecation of args/kwargs in Window (#50338)
1 parent 608f49a commit 2fbea3f

File tree

13 files changed

+37
-512
lines changed

13 files changed

+37
-512
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ Removal of prior version deprecations/changes
721721
- 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`)
722722
- Removed deprecated methods :meth:`ExcelWriter.write_cells`, :meth:`ExcelWriter.save`, :meth:`ExcelWriter.cur_sheet`, :meth:`ExcelWriter.handles`, :meth:`ExcelWriter.path` (:issue:`45795`)
723723
- The :class:`ExcelWriter` attribute ``book`` can no longer be set; it is still available to be accessed and mutated (:issue:`48943`)
724+
- Removed unused ``*args`` and ``**kwargs`` in :class:`Rolling`, :class:`Expanding`, and :class:`ExponentialMovingWindow` ops (:issue:`47851`)
724725
-
725726

726727
.. ---------------------------------------------------------------------------

pandas/compat/numpy/function.py

-45
Original file line numberDiff line numberDiff line change
@@ -335,51 +335,6 @@ def validate_take_with_convert(convert: ndarray | bool | None, args, kwargs) ->
335335
)
336336

337337

338-
def validate_window_func(name, args, kwargs) -> None:
339-
numpy_args = ("axis", "dtype", "out")
340-
msg = (
341-
f"numpy operations are not valid with window objects. "
342-
f"Use .{name}() directly instead "
343-
)
344-
345-
if len(args) > 0:
346-
raise UnsupportedFunctionCall(msg)
347-
348-
for arg in numpy_args:
349-
if arg in kwargs:
350-
raise UnsupportedFunctionCall(msg)
351-
352-
353-
def validate_rolling_func(name, args, kwargs) -> None:
354-
numpy_args = ("axis", "dtype", "out")
355-
msg = (
356-
f"numpy operations are not valid with window objects. "
357-
f"Use .rolling(...).{name}() instead "
358-
)
359-
360-
if len(args) > 0:
361-
raise UnsupportedFunctionCall(msg)
362-
363-
for arg in numpy_args:
364-
if arg in kwargs:
365-
raise UnsupportedFunctionCall(msg)
366-
367-
368-
def validate_expanding_func(name, args, kwargs) -> None:
369-
numpy_args = ("axis", "dtype", "out")
370-
msg = (
371-
f"numpy operations are not valid with window objects. "
372-
f"Use .expanding(...).{name}() instead "
373-
)
374-
375-
if len(args) > 0:
376-
raise UnsupportedFunctionCall(msg)
377-
378-
for arg in numpy_args:
379-
if arg in kwargs:
380-
raise UnsupportedFunctionCall(msg)
381-
382-
383338
def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
384339
"""
385340
'args' and 'kwargs' should be empty, except for allowed kwargs because all

pandas/core/window/common.py

-38
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
from collections import defaultdict
55
from typing import cast
6-
import warnings
76

87
import numpy as np
98

10-
from pandas.util._exceptions import find_stack_level
11-
129
from pandas.core.dtypes.generic import (
1310
ABCDataFrame,
1411
ABCSeries,
@@ -172,38 +169,3 @@ def prep_binary(arg1, arg2):
172169
X = arg1 + 0 * arg2
173170
Y = arg2 + 0 * arg1
174171
return X, Y
175-
176-
177-
def maybe_warn_args_and_kwargs(cls, kernel: str, args, kwargs) -> None:
178-
"""
179-
Warn for deprecation of args and kwargs in rolling/expanding functions.
180-
181-
Parameters
182-
----------
183-
cls : type
184-
Class to warn about.
185-
kernel : str
186-
Operation name.
187-
args : tuple or None
188-
args passed by user. Will be None if and only if kernel does not have args.
189-
kwargs : dict or None
190-
kwargs passed by user. Will be None if and only if kernel does not have kwargs.
191-
"""
192-
warn_args = args is not None and len(args) > 0
193-
warn_kwargs = kwargs is not None and len(kwargs) > 0
194-
if warn_args and warn_kwargs:
195-
msg = "args and kwargs"
196-
elif warn_args:
197-
msg = "args"
198-
elif warn_kwargs:
199-
msg = "kwargs"
200-
else:
201-
msg = ""
202-
if msg != "":
203-
warnings.warn(
204-
f"Passing additional {msg} to {cls.__name__}.{kernel} has "
205-
"no impact on the result and is deprecated. This will "
206-
"raise a TypeError in a future version of pandas.",
207-
category=FutureWarning,
208-
stacklevel=find_stack_level(),
209-
)

pandas/core/window/doc.py

-18
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,6 @@ def create_section_header(header: str) -> str:
4040
"""
4141
).replace("\n", "", 1)
4242

43-
args_compat = dedent(
44-
"""
45-
*args
46-
For NumPy compatibility and will not have an effect on the result.
47-
48-
.. deprecated:: 1.5.0\n
49-
"""
50-
).replace("\n", "", 1)
51-
52-
kwargs_compat = dedent(
53-
"""
54-
**kwargs
55-
For NumPy compatibility and will not have an effect on the result.
56-
57-
.. deprecated:: 1.5.0\n
58-
"""
59-
).replace("\n", "", 1)
60-
6143
kwargs_scipy = dedent(
6244
"""
6345
**kwargs

pandas/core/window/ewm.py

+5-39
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from pandas import DataFrame, Series
1919
from pandas.core.generic import NDFrame
2020

21-
from pandas.compat.numpy import function as nv
2221
from pandas.util._decorators import doc
2322

2423
from pandas.core.dtypes.common import (
@@ -37,15 +36,10 @@
3736
get_jit_arguments,
3837
maybe_use_numba,
3938
)
40-
from pandas.core.window.common import (
41-
maybe_warn_args_and_kwargs,
42-
zsqrt,
43-
)
39+
from pandas.core.window.common import zsqrt
4440
from pandas.core.window.doc import (
4541
_shared_docs,
46-
args_compat,
4742
create_section_header,
48-
kwargs_compat,
4943
kwargs_numeric_only,
5044
numba_notes,
5145
template_header,
@@ -503,9 +497,7 @@ def aggregate(self, func, *args, **kwargs):
503497
template_header,
504498
create_section_header("Parameters"),
505499
kwargs_numeric_only,
506-
args_compat,
507500
window_agg_numba_parameters(),
508-
kwargs_compat,
509501
create_section_header("Returns"),
510502
template_returns,
511503
create_section_header("See Also"),
@@ -519,12 +511,9 @@ def aggregate(self, func, *args, **kwargs):
519511
def mean(
520512
self,
521513
numeric_only: bool = False,
522-
*args,
523514
engine=None,
524515
engine_kwargs=None,
525-
**kwargs,
526516
):
527-
maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
528517
if maybe_use_numba(engine):
529518
if self.method == "single":
530519
func = generate_numba_ewm_func
@@ -542,7 +531,6 @@ def mean(
542531
elif engine in ("cython", None):
543532
if engine_kwargs is not None:
544533
raise ValueError("cython engine does not accept engine_kwargs")
545-
nv.validate_window_func("mean", args, kwargs)
546534

547535
deltas = None if self.times is None else self._deltas
548536
window_func = partial(
@@ -561,9 +549,7 @@ def mean(
561549
template_header,
562550
create_section_header("Parameters"),
563551
kwargs_numeric_only,
564-
args_compat,
565552
window_agg_numba_parameters(),
566-
kwargs_compat,
567553
create_section_header("Returns"),
568554
template_returns,
569555
create_section_header("See Also"),
@@ -577,12 +563,9 @@ def mean(
577563
def sum(
578564
self,
579565
numeric_only: bool = False,
580-
*args,
581566
engine=None,
582567
engine_kwargs=None,
583-
**kwargs,
584568
):
585-
maybe_warn_args_and_kwargs(type(self), "sum", args, kwargs)
586569
if not self.adjust:
587570
raise NotImplementedError("sum is not implemented with adjust=False")
588571
if maybe_use_numba(engine):
@@ -602,7 +585,6 @@ def sum(
602585
elif engine in ("cython", None):
603586
if engine_kwargs is not None:
604587
raise ValueError("cython engine does not accept engine_kwargs")
605-
nv.validate_window_func("sum", args, kwargs)
606588

607589
deltas = None if self.times is None else self._deltas
608590
window_func = partial(
@@ -627,8 +609,6 @@ def sum(
627609
"""
628610
).replace("\n", "", 1),
629611
kwargs_numeric_only,
630-
args_compat,
631-
kwargs_compat,
632612
create_section_header("Returns"),
633613
template_returns,
634614
create_section_header("See Also"),
@@ -637,9 +617,7 @@ def sum(
637617
aggregation_description="(exponential weighted moment) standard deviation",
638618
agg_method="std",
639619
)
640-
def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
641-
maybe_warn_args_and_kwargs(type(self), "std", args, kwargs)
642-
nv.validate_window_func("std", args, kwargs)
620+
def std(self, bias: bool = False, numeric_only: bool = False):
643621
if (
644622
numeric_only
645623
and self._selected_obj.ndim == 1
@@ -649,7 +627,7 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
649627
raise NotImplementedError(
650628
f"{type(self).__name__}.std does not implement numeric_only"
651629
)
652-
return zsqrt(self.var(bias=bias, numeric_only=numeric_only, **kwargs))
630+
return zsqrt(self.var(bias=bias, numeric_only=numeric_only))
653631

654632
@doc(
655633
template_header,
@@ -661,8 +639,6 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
661639
"""
662640
).replace("\n", "", 1),
663641
kwargs_numeric_only,
664-
args_compat,
665-
kwargs_compat,
666642
create_section_header("Returns"),
667643
template_returns,
668644
create_section_header("See Also"),
@@ -671,9 +647,7 @@ def std(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
671647
aggregation_description="(exponential weighted moment) variance",
672648
agg_method="var",
673649
)
674-
def var(self, bias: bool = False, numeric_only: bool = False, *args, **kwargs):
675-
maybe_warn_args_and_kwargs(type(self), "var", args, kwargs)
676-
nv.validate_window_func("var", args, kwargs)
650+
def var(self, bias: bool = False, numeric_only: bool = False):
677651
window_func = window_aggregations.ewmcov
678652
wfunc = partial(
679653
window_func,
@@ -708,7 +682,6 @@ def var_func(values, begin, end, min_periods):
708682
"""
709683
).replace("\n", "", 1),
710684
kwargs_numeric_only,
711-
kwargs_compat,
712685
create_section_header("Returns"),
713686
template_returns,
714687
create_section_header("See Also"),
@@ -723,11 +696,9 @@ def cov(
723696
pairwise: bool | None = None,
724697
bias: bool = False,
725698
numeric_only: bool = False,
726-
**kwargs,
727699
):
728700
from pandas import Series
729701

730-
maybe_warn_args_and_kwargs(type(self), "cov", None, kwargs)
731702
self._validate_numeric_only("cov", numeric_only)
732703

733704
def cov_func(x, y):
@@ -783,7 +754,6 @@ def cov_func(x, y):
783754
"""
784755
).replace("\n", "", 1),
785756
kwargs_numeric_only,
786-
kwargs_compat,
787757
create_section_header("Returns"),
788758
template_returns,
789759
create_section_header("See Also"),
@@ -797,11 +767,9 @@ def corr(
797767
other: DataFrame | Series | None = None,
798768
pairwise: bool | None = None,
799769
numeric_only: bool = False,
800-
**kwargs,
801770
):
802771
from pandas import Series
803772

804-
maybe_warn_args_and_kwargs(type(self), "corr", None, kwargs)
805773
self._validate_numeric_only("corr", numeric_only)
806774

807775
def cov_func(x, y):
@@ -940,7 +908,6 @@ def corr(
940908
other: DataFrame | Series | None = None,
941909
pairwise: bool | None = None,
942910
numeric_only: bool = False,
943-
**kwargs,
944911
):
945912
raise NotImplementedError("corr is not implemented.")
946913

@@ -950,11 +917,10 @@ def cov(
950917
pairwise: bool | None = None,
951918
bias: bool = False,
952919
numeric_only: bool = False,
953-
**kwargs,
954920
):
955921
raise NotImplementedError("cov is not implemented.")
956922

957-
def var(self, bias: bool = False, *args, **kwargs):
923+
def var(self, bias: bool = False, numeric_only: bool = False):
958924
raise NotImplementedError("var is not implemented.")
959925

960926
def mean(self, *args, update=None, update_times=None, **kwargs):

0 commit comments

Comments
 (0)