@@ -141,7 +141,7 @@ def rolling_count(arg, window, freq=None, center=False, time_rule=None):
141
141
center : boolean, default False
142
142
Whether the label should correspond with center of window
143
143
time_rule : Legacy alias for freq
144
-
144
+
145
145
Returns
146
146
-------
147
147
rolling_count : type of caller
@@ -255,8 +255,8 @@ def rolling_corr_pairwise(df, window, min_periods=None):
255
255
return Panel .from_dict (all_results ).swapaxes ('items' , 'major' )
256
256
257
257
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 ):
260
260
"""
261
261
Rolling statistical measure using supplied function. Designed to be
262
262
used with passed-in Cython array-based functions.
@@ -274,13 +274,18 @@ def _rolling_moment(arg, window, func, minp, axis=0, freq=None,
274
274
center : boolean, default False
275
275
Whether the label should correspond with center of window
276
276
time_rule : Legacy alias for freq
277
-
277
+ args : tuple
278
+ Passed on to func
279
+ kwargs : dict
280
+ Passed on to func
281
+
278
282
Returns
279
283
-------
280
284
y : type of input
281
285
"""
282
286
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 )
284
289
return_hook , values = _process_data_structure (arg )
285
290
# actually calculate the moment. Faster way to do this?
286
291
if values .ndim > 1 :
@@ -509,7 +514,7 @@ def _rolling_func(func, desc, check_minp=_use_window):
509
514
@wraps (func )
510
515
def f (arg , window , min_periods = None , freq = None , center = False ,
511
516
time_rule = None , ** kwargs ):
512
- def call_cython (arg , window , minp , ** kwds ):
517
+ def call_cython (arg , window , minp , args = (), kwargs = {}, ** kwds ):
513
518
minp = check_minp (minp , window )
514
519
return func (arg , window , minp , ** kwds )
515
520
return _rolling_moment (arg , window , call_cython , min_periods ,
@@ -551,21 +556,21 @@ def rolling_quantile(arg, window, quantile, min_periods=None, freq=None,
551
556
center : boolean, default False
552
557
Whether the label should correspond with center of window
553
558
time_rule : Legacy alias for freq
554
-
559
+
555
560
Returns
556
561
-------
557
562
y : type of input argument
558
563
"""
559
564
560
- def call_cython (arg , window , minp ):
565
+ def call_cython (arg , window , minp , args = (), kwargs = {} ):
561
566
minp = _use_window (minp , window )
562
567
return algos .roll_quantile (arg , window , minp , quantile )
563
568
return _rolling_moment (arg , window , call_cython , min_periods ,
564
569
freq = freq , center = center , time_rule = time_rule )
565
570
566
571
567
572
def rolling_apply (arg , window , func , min_periods = None , freq = None ,
568
- center = False , time_rule = None ):
573
+ center = False , time_rule = None , args = (), kwargs = {} ):
569
574
"""Generic moving function application
570
575
571
576
Parameters
@@ -581,16 +586,21 @@ def rolling_apply(arg, window, func, min_periods=None, freq=None,
581
586
center : boolean, default False
582
587
Whether the label should correspond with center of window
583
588
time_rule : Legacy alias for freq
584
-
589
+ args : tuple
590
+ Passed on to func
591
+ kwargs : dict
592
+ Passed on to func
593
+
585
594
Returns
586
595
-------
587
596
y : type of input argument
588
597
"""
589
- def call_cython (arg , window , minp ):
598
+ def call_cython (arg , window , minp , args , kwargs ):
590
599
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 )
592
601
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 )
594
604
595
605
596
606
def 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,
618
628
If True computes weighted mean, else weighted sum
619
629
time_rule : Legacy alias for freq
620
630
axis : {0, 1}, default 0
621
-
631
+
622
632
Returns
623
633
-------
624
634
y : type of input argument
@@ -703,7 +713,7 @@ def f(arg, min_periods=1, freq=None, center=False, time_rule=None,
703
713
** kwargs ):
704
714
window = len (arg )
705
715
706
- def call_cython (arg , window , minp , ** kwds ):
716
+ def call_cython (arg , window , minp , args = (), kwargs = {}, ** kwds ):
707
717
minp = check_minp (minp , window )
708
718
return func (arg , window , minp , ** kwds )
709
719
return _rolling_moment (arg , window , call_cython , min_periods ,
@@ -744,7 +754,7 @@ def expanding_count(arg, freq=None, center=False, time_rule=None):
744
754
center : boolean, default False
745
755
Whether the label should correspond with center of window
746
756
time_rule : Legacy alias for freq
747
-
757
+
748
758
Returns
749
759
-------
750
760
expanding_count : type of caller
@@ -768,7 +778,7 @@ def expanding_quantile(arg, quantile, min_periods=1, freq=None,
768
778
center : boolean, default False
769
779
Whether the label should correspond with center of window
770
780
time_rule : Legacy alias for freq
771
-
781
+
772
782
Returns
773
783
-------
774
784
y : type of input argument
@@ -818,7 +828,7 @@ def expanding_corr_pairwise(df, min_periods=1):
818
828
819
829
820
830
def expanding_apply (arg , func , min_periods = 1 , freq = None , center = False ,
821
- time_rule = None ):
831
+ time_rule = None , args = (), kwargs = {} ):
822
832
"""Generic expanding function application
823
833
824
834
Parameters
@@ -833,11 +843,16 @@ def expanding_apply(arg, func, min_periods=1, freq=None, center=False,
833
843
center : boolean, default False
834
844
Whether the label should correspond with center of window
835
845
time_rule : Legacy alias for freq
836
-
846
+ args : tuple
847
+ Passed on to func
848
+ kwargs : dict
849
+ Passed on to func
850
+
837
851
Returns
838
852
-------
839
853
y : type of input argument
840
854
"""
841
855
window = len (arg )
842
856
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