Skip to content

Commit c512f42

Browse files
committed
test isnan
1 parent 7ef69bd commit c512f42

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

pandas/_libs/window.pyx

+19-20
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,21 @@ def roll_count(ndarray[double_t] input, int64_t win, int64_t minp,
381381
count_x = 0.0
382382
for j in range(s, e):
383383
val = input[j]
384-
if val == val:
384+
if not isnan(val):
385385
count_x += 1.0
386386

387387
else:
388388

389389
# calculate deletes
390390
for j in range(start[i - 1], s):
391391
val = input[j]
392-
if val == val:
392+
if not isnan(val):
393393
count_x -= 1.0
394394

395395
# calculate adds
396396
for j in range(end[i - 1], e):
397397
val = input[j]
398-
if val == val:
398+
if not isnan(val):
399399
count_x += 1.0
400400

401401
if count_x >= minp:
@@ -424,15 +424,15 @@ cdef inline void add_sum(double val, int64_t *nobs, double *sum_x) nogil:
424424
""" add a value from the sum calc """
425425

426426
# Not NaN
427-
if val == val:
427+
if not isnan(val):
428428
nobs[0] = nobs[0] + 1
429429
sum_x[0] = sum_x[0] + val
430430

431431

432432
cdef inline void remove_sum(double val, int64_t *nobs, double *sum_x) nogil:
433433
""" remove a value from the sum calc """
434434

435-
if val == val:
435+
if not isnan(val):
436436
nobs[0] = nobs[0] - 1
437437
sum_x[0] = sum_x[0] - val
438438

@@ -538,7 +538,7 @@ cdef inline void add_mean(double val, Py_ssize_t *nobs, double *sum_x,
538538
""" add a value from the mean calc """
539539

540540
# Not NaN
541-
if val == val:
541+
if not isnan(val):
542542
nobs[0] = nobs[0] + 1
543543
sum_x[0] = sum_x[0] + val
544544
if signbit(val):
@@ -549,7 +549,7 @@ cdef inline void remove_mean(double val, Py_ssize_t *nobs, double *sum_x,
549549
Py_ssize_t *neg_ct) nogil:
550550
""" remove a value from the mean calc """
551551

552-
if val == val:
552+
if not isnan(val):
553553
nobs[0] = nobs[0] - 1
554554
sum_x[0] = sum_x[0] - val
555555
if signbit(val):
@@ -671,8 +671,7 @@ cdef inline void remove_var(double val, double *nobs, double *mean_x,
671671
""" remove a value from the var calc """
672672
cdef double delta
673673

674-
# Not NaN
675-
if val == val:
674+
if not isnan(val):
676675
nobs[0] = nobs[0] - 1
677676
if nobs[0]:
678677
# a part of Welford's method for the online variance-calculation
@@ -760,7 +759,7 @@ def roll_var(ndarray[double_t] input, int64_t win, int64_t minp,
760759
val = input[i]
761760
prev = input[i - win]
762761

763-
if val == val:
762+
if not isnan(val):
764763
if prev == prev:
765764

766765
# Adding one observation and removing another one
@@ -822,7 +821,7 @@ cdef inline void add_skew(double val, int64_t *nobs, double *x, double *xx,
822821
""" add a value from the skew calc """
823822

824823
# Not NaN
825-
if val == val:
824+
if not isnan(val):
826825
nobs[0] = nobs[0] + 1
827826

828827
# seriously don't ask me why this is faster
@@ -836,7 +835,7 @@ cdef inline void remove_skew(double val, int64_t *nobs, double *x, double *xx,
836835
""" remove a value from the skew calc """
837836

838837
# Not NaN
839-
if val == val:
838+
if not isnan(val):
840839
nobs[0] = nobs[0] - 1
841840

842841
# seriously don't ask me why this is faster
@@ -959,7 +958,7 @@ cdef inline void add_kurt(double val, int64_t *nobs, double *x, double *xx,
959958
""" add a value from the kurotic calc """
960959

961960
# Not NaN
962-
if val == val:
961+
if not isnan(val):
963962
nobs[0] = nobs[0] + 1
964963

965964
# seriously don't ask me why this is faster
@@ -974,7 +973,7 @@ cdef inline void remove_kurt(double val, int64_t *nobs, double *x, double *xx,
974973
""" remove a value from the kurotic calc """
975974

976975
# Not NaN
977-
if val == val:
976+
if not isnan(val):
978977
nobs[0] = nobs[0] - 1
979978

980979
# seriously don't ask me why this is faster
@@ -1089,7 +1088,7 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
10891088

10901089
# setup
10911090
val = input[i]
1092-
if val == val:
1091+
if not isnan(val):
10931092
nobs += 1
10941093
err = skiplist_insert(sl, val) != 1
10951094
if err:
@@ -1100,14 +1099,14 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
11001099
# calculate deletes
11011100
for j in range(start[i - 1], s):
11021101
val = input[j]
1103-
if val == val:
1102+
if not isnan(val):
11041103
skiplist_remove(sl, val)
11051104
nobs -= 1
11061105

11071106
# calculate adds
11081107
for j in range(end[i - 1], e):
11091108
val = input[j]
1110-
if val == val:
1109+
if not isnan(val):
11111110
nobs += 1
11121111
err = skiplist_insert(sl, val) != 1
11131112
if err:
@@ -1472,7 +1471,7 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
14721471

14731472
# setup
14741473
val = input[i]
1475-
if val == val:
1474+
if not isnan(val):
14761475
nobs += 1
14771476
skiplist_insert(skiplist, val)
14781477

@@ -1481,14 +1480,14 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
14811480
# calculate deletes
14821481
for j in range(start[i - 1], s):
14831482
val = input[j]
1484-
if val == val:
1483+
if not isnan(val):
14851484
skiplist_remove(skiplist, val)
14861485
nobs -= 1
14871486

14881487
# calculate adds
14891488
for j in range(end[i - 1], e):
14901489
val = input[j]
1491-
if val == val:
1490+
if not isnan(val):
14921491
nobs += 1
14931492
skiplist_insert(skiplist, val)
14941493

0 commit comments

Comments
 (0)