Skip to content
Prev Previous commit
Next Next commit
re-calculate alpha each iteration for irregular-spaced time series
  • Loading branch information
tserrao committed Jun 28, 2024
commit fa1447aa40a0b31d6bbf50ff87f80679cd908b68
3 changes: 3 additions & 0 deletions pandas/_libs/window/aggregations.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,9 @@ def ewm(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
if normalize:
# avoid numerical errors on constant series
if weighted != cur:
if not adjust and com == 1:
# update alpha "on the fly" for irregular-interval time series
new_wt = 1. - old_wt
weighted = old_wt * weighted + new_wt * cur
weighted /= (old_wt + new_wt)
if adjust:
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/window/numba_.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def ewm(
# note that len(deltas) = len(vals) - 1 and deltas[i]
# is to be used in conjunction with vals[i+1]
old_wt *= old_wt_factor ** deltas[start + j - 1]
if not adjust and com == 1:
# update alpha "on the fly" for irregular-interval time series
new_wt = 1. - old_wt
else:
weighted = old_wt_factor * weighted
if is_observation:
Expand Down Expand Up @@ -324,6 +327,9 @@ def ewm_table(
# note that len(deltas) = len(vals) - 1 and deltas[i]
# is to be used in conjunction with vals[i+1]
old_wt[j] *= old_wt_factor ** deltas[i - 1]
if not adjust and com == 1:
# update alpha "on the fly" for irregular-interval time series
new_wt = 1. - old_wt[j]
else:
weighted[j] = old_wt_factor * weighted[j]
if is_observations[j]:
Expand Down