Skip to content

Commit fa1447a

Browse files
committed
re-calculate alpha each iteration for irregular-spaced time series
1 parent 5992c3e commit fa1447a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/_libs/window/aggregations.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,9 @@ def ewm(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
18131813
if normalize:
18141814
# avoid numerical errors on constant series
18151815
if weighted != cur:
1816+
if not adjust and com == 1:
1817+
# update alpha "on the fly" for irregular-interval time series
1818+
new_wt = 1. - old_wt
18161819
weighted = old_wt * weighted + new_wt * cur
18171820
weighted /= (old_wt + new_wt)
18181821
if adjust:

pandas/core/window/numba_.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def ewm(
149149
# note that len(deltas) = len(vals) - 1 and deltas[i]
150150
# is to be used in conjunction with vals[i+1]
151151
old_wt *= old_wt_factor ** deltas[start + j - 1]
152+
if not adjust and com == 1:
153+
# update alpha "on the fly" for irregular-interval time series
154+
new_wt = 1. - old_wt
152155
else:
153156
weighted = old_wt_factor * weighted
154157
if is_observation:
@@ -324,6 +327,9 @@ def ewm_table(
324327
# note that len(deltas) = len(vals) - 1 and deltas[i]
325328
# is to be used in conjunction with vals[i+1]
326329
old_wt[j] *= old_wt_factor ** deltas[i - 1]
330+
if not adjust and com == 1:
331+
# update alpha "on the fly" for irregular-interval time series
332+
new_wt = 1. - old_wt[j]
327333
else:
328334
weighted[j] = old_wt_factor * weighted[j]
329335
if is_observations[j]:

0 commit comments

Comments
 (0)