Skip to content

Commit 2305a32

Browse files
committed
try hack fix
1 parent 9592b6d commit 2305a32

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pandas/_libs/window.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,16 +653,21 @@ cdef inline void add_var(double val, double *nobs, double *mean_x,
653653
double *ssqdm_x) nogil:
654654
""" add a value from the var calc """
655655
cdef double delta
656-
656+
nobs[0] = nobs[0] + 1
657657
# Not NaN
658658
if val == val:
659-
nobs[0] = nobs[0] + 1
660-
661659
# a part of Welford's method for the online variance-calculation
662660
# https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
663661
delta = val - mean_x[0]
664662
mean_x[0] = mean_x[0] + delta / nobs[0]
665663
ssqdm_x[0] = ssqdm_x[0] + ((nobs[0] - 1) * delta ** 2) / nobs[0]
664+
else:
665+
# XXX
666+
# `nobs[0] = nobs[0] + 1` should be in the if branch
667+
# but something goes wrong with MSVC 2017 causing the whole
668+
# path to optimize out, uncoditionally adding and
669+
# backing out as a hack to fix
670+
nobs[0] = nobs[0] - 1
666671

667672

668673
cdef inline void remove_var(double val, double *nobs, double *mean_x,
@@ -683,7 +688,6 @@ cdef inline void remove_var(double val, double *nobs, double *mean_x,
683688
mean_x[0] = 0
684689
ssqdm_x[0] = 0
685690

686-
687691
def roll_var(ndarray[double_t] input, int64_t win, int64_t minp,
688692
object index, object closed, int ddof=1):
689693
"""

0 commit comments

Comments
 (0)