Skip to content

CLN: Unify Window._apply_window and Rolling._apply functions #27403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 31, 2019
Merged
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