Skip to content

Commit 4ff0d61

Browse files
ihsansecerjreback
authored andcommitted
CLN: Unify Window._apply_window and Rolling._apply functions (#27403)
1 parent 9000c39 commit 4ff0d61

File tree

2 files changed

+190
-169
lines changed

2 files changed

+190
-169
lines changed

pandas/_libs/window.pyx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1675,9 +1675,22 @@ def roll_generic(object obj,
16751675
return output
16761676

16771677

1678-
def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
1679-
ndarray[float64_t, ndim=1, cast=True] weights,
1680-
int minp, bint avg=True):
1678+
# ----------------------------------------------------------------------
1679+
# Rolling sum and mean for weighted window
1680+
1681+
1682+
def roll_weighted_sum(float64_t[:] values, float64_t[:] weights,
1683+
int minp):
1684+
return _roll_weighted_sum_mean(values, weights, minp, avg=0)
1685+
1686+
1687+
def roll_weighted_mean(float64_t[:] values, float64_t[:] weights,
1688+
int minp):
1689+
return _roll_weighted_sum_mean(values, weights, minp, avg=1)
1690+
1691+
1692+
def _roll_weighted_sum_mean(float64_t[:] values, float64_t[:] weights,
1693+
int minp, bint avg):
16811694
"""
16821695
Assume len(weights) << len(values)
16831696
"""
@@ -1688,6 +1701,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
16881701

16891702
in_n = len(values)
16901703
win_n = len(weights)
1704+
16911705
output = np.zeros(in_n, dtype=float)
16921706
counts = np.zeros(in_n, dtype=float)
16931707
if avg:
@@ -1739,6 +1753,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
17391753

17401754
return output
17411755

1756+
17421757
# ----------------------------------------------------------------------
17431758
# Exponentially weighted moving average
17441759

0 commit comments

Comments
 (0)