Closed
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Problem description
According to docstring of Rolling.apply
arguments args
and kwargs
allow to pass to a custom function positional and keyword arguments enumerated in kwargs
. However, Rolling.apply
passes both of them as keyword arguments. In other word, it passes keyword args
consisting of "positional" arguments. This is definitely buggy behaviour.
The reason is that a closure function is built in a wrong way. The issue states for cython
backend as well as numba
backend. The possible should looks like the following.
diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py
index a01a753e8..32360848a 100644
--- a/pandas/core/window/rolling.py
+++ b/pandas/core/window/rolling.py
@@ -1313,11 +1313,11 @@ class _Rolling_and_Expanding(_Rolling):
window_func = partial(
self._get_cython_func_type("roll_generic"),
- args=args,
- kwargs=kwargs,
+ *args,
raw=raw,
offset=offset,
func=func,
+ **kwargs,
)
def apply_func(values, begin, end, min_periods, raw=raw):