Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1675,9 +1675,22 @@ def roll_generic(object obj,
return output


def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
ndarray[float64_t, ndim=1, cast=True] weights,
int minp, bint avg=True):
# ----------------------------------------------------------------------
# Rolling sum and mean for weighted window


def roll_weighted_sum(float64_t[:] values, float64_t[:] weights,
int minp):
return _roll_weighted_sum_mean(values, weights, minp, avg=0)


def roll_weighted_mean(float64_t[:] values, float64_t[:] weights,
int minp):
return _roll_weighted_sum_mean(values, weights, minp, avg=1)


def _roll_weighted_sum_mean(float64_t[:] values, float64_t[:] weights,
int minp, bint avg):
"""
Assume len(weights) << len(values)
"""
Expand All @@ -1688,6 +1701,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,

in_n = len(values)
win_n = len(weights)

output = np.zeros(in_n, dtype=float)
counts = np.zeros(in_n, dtype=float)
if avg:
Expand Down Expand Up @@ -1739,6 +1753,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,

return output


# ----------------------------------------------------------------------
# Exponentially weighted moving average

Expand Down
Loading