@@ -316,26 +316,6 @@ def _insert_on_column(self, result: "DataFrame", obj: "DataFrame"):
316
316
# insert at the end
317
317
result [name ] = extra_col
318
318
319
- def _get_roll_func (self , func_name : str ) -> Callable [..., Any ]:
320
- """
321
- Wrap rolling function to check values passed.
322
-
323
- Parameters
324
- ----------
325
- func_name : str
326
- Cython function used to calculate rolling statistics
327
-
328
- Returns
329
- -------
330
- func : callable
331
- """
332
- window_func = getattr (window_aggregations , func_name , None )
333
- if window_func is None :
334
- raise ValueError (
335
- f"we do not support this function in window_aggregations.{ func_name } "
336
- )
337
- return window_func
338
-
339
319
@property
340
320
def _index_array (self ):
341
321
# TODO: why do we get here with e.g. MultiIndex?
@@ -1153,21 +1133,21 @@ def aggregate(self, func, *args, **kwargs):
1153
1133
@Appender (_shared_docs ["sum" ])
1154
1134
def sum (self , * args , ** kwargs ):
1155
1135
nv .validate_window_func ("sum" , args , kwargs )
1156
- window_func = self . _get_roll_func ( " roll_weighted_sum" )
1136
+ window_func = window_aggregations . roll_weighted_sum
1157
1137
return self ._apply (window_func , name = "sum" , ** kwargs )
1158
1138
1159
1139
@Substitution (name = "window" )
1160
1140
@Appender (_shared_docs ["mean" ])
1161
1141
def mean (self , * args , ** kwargs ):
1162
1142
nv .validate_window_func ("mean" , args , kwargs )
1163
- window_func = self . _get_roll_func ( " roll_weighted_mean" )
1143
+ window_func = window_aggregations . roll_weighted_mean
1164
1144
return self ._apply (window_func , name = "mean" , ** kwargs )
1165
1145
1166
1146
@Substitution (name = "window" , versionadded = "\n .. versionadded:: 1.0.0\n " )
1167
1147
@Appender (_shared_docs ["var" ])
1168
1148
def var (self , ddof : int = 1 , * args , ** kwargs ):
1169
1149
nv .validate_window_func ("var" , args , kwargs )
1170
- window_func = partial (self . _get_roll_func ( " roll_weighted_var" ) , ddof = ddof )
1150
+ window_func = partial (window_aggregations . roll_weighted_var , ddof = ddof )
1171
1151
kwargs .pop ("name" , None )
1172
1152
return self ._apply (window_func , name = "var" , ** kwargs )
1173
1153
@@ -1221,7 +1201,7 @@ class RollingAndExpandingMixin(BaseWindow):
1221
1201
)
1222
1202
1223
1203
def count (self ):
1224
- window_func = self . _get_roll_func ( " roll_sum" )
1204
+ window_func = window_aggregations . roll_sum
1225
1205
return self ._apply (window_func , name = "count" )
1226
1206
1227
1207
_shared_docs ["apply" ] = dedent (
@@ -1331,7 +1311,7 @@ def _generate_cython_apply_func(
1331
1311
from pandas import Series
1332
1312
1333
1313
window_func = partial (
1334
- self . _get_roll_func ( " roll_apply" ) ,
1314
+ window_aggregations . roll_apply ,
1335
1315
args = args ,
1336
1316
kwargs = kwargs ,
1337
1317
raw = raw ,
@@ -1347,7 +1327,7 @@ def apply_func(values, begin, end, min_periods, raw=raw):
1347
1327
1348
1328
def sum (self , * args , ** kwargs ):
1349
1329
nv .validate_window_func ("sum" , args , kwargs )
1350
- window_func = self . _get_roll_func ( " roll_sum" )
1330
+ window_func = window_aggregations . roll_sum
1351
1331
return self ._apply (window_func , name = "sum" , ** kwargs )
1352
1332
1353
1333
_shared_docs ["max" ] = dedent (
@@ -1363,7 +1343,7 @@ def sum(self, *args, **kwargs):
1363
1343
1364
1344
def max (self , * args , ** kwargs ):
1365
1345
nv .validate_window_func ("max" , args , kwargs )
1366
- window_func = self . _get_roll_func ( " roll_max" )
1346
+ window_func = window_aggregations . roll_max
1367
1347
return self ._apply (window_func , name = "max" , ** kwargs )
1368
1348
1369
1349
_shared_docs ["min" ] = dedent (
@@ -1405,12 +1385,12 @@ def max(self, *args, **kwargs):
1405
1385
1406
1386
def min (self , * args , ** kwargs ):
1407
1387
nv .validate_window_func ("min" , args , kwargs )
1408
- window_func = self . _get_roll_func ( " roll_min" )
1388
+ window_func = window_aggregations . roll_min
1409
1389
return self ._apply (window_func , name = "min" , ** kwargs )
1410
1390
1411
1391
def mean (self , * args , ** kwargs ):
1412
1392
nv .validate_window_func ("mean" , args , kwargs )
1413
- window_func = self . _get_roll_func ( " roll_mean" )
1393
+ window_func = window_aggregations . roll_mean
1414
1394
return self ._apply (window_func , name = "mean" , ** kwargs )
1415
1395
1416
1396
_shared_docs ["median" ] = dedent (
@@ -1451,14 +1431,14 @@ def mean(self, *args, **kwargs):
1451
1431
)
1452
1432
1453
1433
def median (self , ** kwargs ):
1454
- window_func = self . _get_roll_func ( " roll_median_c" )
1434
+ window_func = window_aggregations . roll_median_c
1455
1435
# GH 32865. Move max window size calculation to
1456
1436
# the median function implementation
1457
1437
return self ._apply (window_func , name = "median" , ** kwargs )
1458
1438
1459
1439
def std (self , ddof : int = 1 , * args , ** kwargs ):
1460
1440
nv .validate_window_func ("std" , args , kwargs )
1461
- window_func = self . _get_roll_func ( " roll_var" )
1441
+ window_func = window_aggregations . roll_var
1462
1442
1463
1443
def zsqrt_func (values , begin , end , min_periods ):
1464
1444
return zsqrt (window_func (values , begin , end , min_periods , ddof = ddof ))
@@ -1471,7 +1451,7 @@ def zsqrt_func(values, begin, end, min_periods):
1471
1451
1472
1452
def var (self , ddof : int = 1 , * args , ** kwargs ):
1473
1453
nv .validate_window_func ("var" , args , kwargs )
1474
- window_func = partial (self . _get_roll_func ( " roll_var" ) , ddof = ddof )
1454
+ window_func = partial (window_aggregations . roll_var , ddof = ddof )
1475
1455
return self ._apply (
1476
1456
window_func ,
1477
1457
name = "var" ,
@@ -1490,7 +1470,7 @@ def var(self, ddof: int = 1, *args, **kwargs):
1490
1470
"""
1491
1471
1492
1472
def skew (self , ** kwargs ):
1493
- window_func = self . _get_roll_func ( " roll_skew" )
1473
+ window_func = window_aggregations . roll_skew
1494
1474
return self ._apply (
1495
1475
window_func ,
1496
1476
name = "skew" ,
@@ -1583,7 +1563,7 @@ def sem(self, ddof: int = 1, *args, **kwargs):
1583
1563
)
1584
1564
1585
1565
def kurt (self , ** kwargs ):
1586
- window_func = self . _get_roll_func ( " roll_kurt" )
1566
+ window_func = window_aggregations . roll_kurt
1587
1567
return self ._apply (
1588
1568
window_func ,
1589
1569
name = "kurt" ,
@@ -1646,12 +1626,12 @@ def kurt(self, **kwargs):
1646
1626
1647
1627
def quantile (self , quantile : float , interpolation : str = "linear" , ** kwargs ):
1648
1628
if quantile == 1.0 :
1649
- window_func = self . _get_roll_func ( " roll_max" )
1629
+ window_func = window_aggregations . roll_max
1650
1630
elif quantile == 0.0 :
1651
- window_func = self . _get_roll_func ( " roll_min" )
1631
+ window_func = window_aggregations . roll_min
1652
1632
else :
1653
1633
window_func = partial (
1654
- self . _get_roll_func ( " roll_quantile" ) ,
1634
+ window_aggregations . roll_quantile ,
1655
1635
quantile = quantile ,
1656
1636
interpolation = interpolation ,
1657
1637
)
0 commit comments