@@ -141,7 +141,7 @@ def rolling_count(arg, window, freq=None, center=False, time_rule=None):
141141 center : boolean, default False
142142 Whether the label should correspond with center of window
143143 time_rule : Legacy alias for freq
144-
144+
145145 Returns
146146 -------
147147 rolling_count : type of caller
@@ -255,8 +255,8 @@ def rolling_corr_pairwise(df, window, min_periods=None):
255255 return Panel .from_dict (all_results ).swapaxes ('items' , 'major' )
256256
257257
258- def _rolling_moment (arg , window , func , minp , axis = 0 , freq = None ,
259- center = False , time_rule = None , ** kwargs ):
258+ def _rolling_moment (arg , window , func , minp , axis = 0 , freq = None , center = False ,
259+ time_rule = None , args = (), kwargs = {}, ** kwds ):
260260 """
261261 Rolling statistical measure using supplied function. Designed to be
262262 used with passed-in Cython array-based functions.
@@ -274,13 +274,18 @@ def _rolling_moment(arg, window, func, minp, axis=0, freq=None,
274274 center : boolean, default False
275275 Whether the label should correspond with center of window
276276 time_rule : Legacy alias for freq
277-
277+ args : tuple
278+ Passed on to func
279+ kwargs : dict
280+ Passed on to func
281+
278282 Returns
279283 -------
280284 y : type of input
281285 """
282286 arg = _conv_timerule (arg , freq , time_rule )
283- calc = lambda x : func (x , window , minp = minp , ** kwargs )
287+ calc = lambda x : func (x , window , minp = minp , args = args , kwargs = kwargs ,
288+ ** kwds )
284289 return_hook , values = _process_data_structure (arg )
285290 # actually calculate the moment. Faster way to do this?
286291 if values .ndim > 1 :
@@ -509,7 +514,7 @@ def _rolling_func(func, desc, check_minp=_use_window):
509514 @wraps (func )
510515 def f (arg , window , min_periods = None , freq = None , center = False ,
511516 time_rule = None , ** kwargs ):
512- def call_cython (arg , window , minp , ** kwds ):
517+ def call_cython (arg , window , minp , args = (), kwargs = {}, ** kwds ):
513518 minp = check_minp (minp , window )
514519 return func (arg , window , minp , ** kwds )
515520 return _rolling_moment (arg , window , call_cython , min_periods ,
@@ -551,21 +556,21 @@ def rolling_quantile(arg, window, quantile, min_periods=None, freq=None,
551556 center : boolean, default False
552557 Whether the label should correspond with center of window
553558 time_rule : Legacy alias for freq
554-
559+
555560 Returns
556561 -------
557562 y : type of input argument
558563 """
559564
560- def call_cython (arg , window , minp ):
565+ def call_cython (arg , window , minp , args = (), kwargs = {} ):
561566 minp = _use_window (minp , window )
562567 return algos .roll_quantile (arg , window , minp , quantile )
563568 return _rolling_moment (arg , window , call_cython , min_periods ,
564569 freq = freq , center = center , time_rule = time_rule )
565570
566571
567572def rolling_apply (arg , window , func , min_periods = None , freq = None ,
568- center = False , time_rule = None ):
573+ center = False , time_rule = None , args = (), kwargs = {} ):
569574 """Generic moving function application
570575
571576 Parameters
@@ -581,16 +586,21 @@ def rolling_apply(arg, window, func, min_periods=None, freq=None,
581586 center : boolean, default False
582587 Whether the label should correspond with center of window
583588 time_rule : Legacy alias for freq
584-
589+ args : tuple
590+ Passed on to func
591+ kwargs : dict
592+ Passed on to func
593+
585594 Returns
586595 -------
587596 y : type of input argument
588597 """
589- def call_cython (arg , window , minp ):
598+ def call_cython (arg , window , minp , args , kwargs ):
590599 minp = _use_window (minp , window )
591- return algos .roll_generic (arg , window , minp , func )
600+ return algos .roll_generic (arg , window , minp , func , args , kwargs )
592601 return _rolling_moment (arg , window , call_cython , min_periods ,
593- freq = freq , center = center , time_rule = time_rule )
602+ freq = freq , center = center , time_rule = time_rule ,
603+ args = args , kwargs = kwargs )
594604
595605
596606def rolling_window (arg , window = None , win_type = None , min_periods = None ,
@@ -618,7 +628,7 @@ def rolling_window(arg, window=None, win_type=None, min_periods=None,
618628 If True computes weighted mean, else weighted sum
619629 time_rule : Legacy alias for freq
620630 axis : {0, 1}, default 0
621-
631+
622632 Returns
623633 -------
624634 y : type of input argument
@@ -703,7 +713,7 @@ def f(arg, min_periods=1, freq=None, center=False, time_rule=None,
703713 ** kwargs ):
704714 window = len (arg )
705715
706- def call_cython (arg , window , minp , ** kwds ):
716+ def call_cython (arg , window , minp , args = (), kwargs = {}, ** kwds ):
707717 minp = check_minp (minp , window )
708718 return func (arg , window , minp , ** kwds )
709719 return _rolling_moment (arg , window , call_cython , min_periods ,
@@ -744,7 +754,7 @@ def expanding_count(arg, freq=None, center=False, time_rule=None):
744754 center : boolean, default False
745755 Whether the label should correspond with center of window
746756 time_rule : Legacy alias for freq
747-
757+
748758 Returns
749759 -------
750760 expanding_count : type of caller
@@ -768,7 +778,7 @@ def expanding_quantile(arg, quantile, min_periods=1, freq=None,
768778 center : boolean, default False
769779 Whether the label should correspond with center of window
770780 time_rule : Legacy alias for freq
771-
781+
772782 Returns
773783 -------
774784 y : type of input argument
@@ -818,7 +828,7 @@ def expanding_corr_pairwise(df, min_periods=1):
818828
819829
820830def expanding_apply (arg , func , min_periods = 1 , freq = None , center = False ,
821- time_rule = None ):
831+ time_rule = None , args = (), kwargs = {} ):
822832 """Generic expanding function application
823833
824834 Parameters
@@ -833,11 +843,16 @@ def expanding_apply(arg, func, min_periods=1, freq=None, center=False,
833843 center : boolean, default False
834844 Whether the label should correspond with center of window
835845 time_rule : Legacy alias for freq
836-
846+ args : tuple
847+ Passed on to func
848+ kwargs : dict
849+ Passed on to func
850+
837851 Returns
838852 -------
839853 y : type of input argument
840854 """
841855 window = len (arg )
842856 return rolling_apply (arg , window , func , min_periods = min_periods , freq = freq ,
843- center = center , time_rule = time_rule )
857+ center = center , time_rule = time_rule , args = args ,
858+ kwargs = kwargs )
0 commit comments