2
2
3
3
import cython
4
4
5
- from libc.math cimport round
5
+ from libc.math cimport (
6
+ round ,
7
+ signbit,
8
+ sqrt,
9
+ )
6
10
from libcpp.deque cimport deque
7
11
8
12
from pandas._libs.algos cimport TiebreakEnumType
@@ -19,14 +23,8 @@ from numpy cimport (
19
23
20
24
cnp.import_array()
21
25
22
-
23
- cdef extern from " ../src/headers/cmath" namespace " std" :
24
- bint isnan(float64_t) nogil
25
- bint notnan(float64_t) nogil
26
- int signbit(float64_t) nogil
27
- float64_t sqrt(float64_t x) nogil
28
-
29
26
from pandas._libs.algos import is_monotonic
27
+
30
28
from pandas._libs.dtypes cimport numeric_t
31
29
32
30
@@ -94,7 +92,7 @@ cdef inline void add_sum(float64_t val, int64_t *nobs, float64_t *sum_x,
94
92
float64_t y, t
95
93
96
94
# Not NaN
97
- if notnan( val) :
95
+ if val == val :
98
96
nobs[0 ] = nobs[0 ] + 1
99
97
y = val - compensation[0 ]
100
98
t = sum_x[0 ] + y
@@ -110,7 +108,7 @@ cdef inline void remove_sum(float64_t val, int64_t *nobs, float64_t *sum_x,
110
108
float64_t y, t
111
109
112
110
# Not NaN
113
- if notnan( val) :
111
+ if val == val :
114
112
nobs[0 ] = nobs[0 ] - 1
115
113
y = - val - compensation[0 ]
116
114
t = sum_x[0 ] + y
@@ -199,7 +197,7 @@ cdef inline void add_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
199
197
float64_t y, t
200
198
201
199
# Not NaN
202
- if notnan( val) :
200
+ if val == val :
203
201
nobs[0 ] = nobs[0 ] + 1
204
202
y = val - compensation[0 ]
205
203
t = sum_x[0 ] + y
@@ -215,7 +213,7 @@ cdef inline void remove_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
215
213
cdef:
216
214
float64_t y, t
217
215
218
- if notnan( val) :
216
+ if val == val :
219
217
nobs[0 ] = nobs[0 ] - 1
220
218
y = - val - compensation[0 ]
221
219
t = sum_x[0 ] + y
@@ -304,8 +302,8 @@ cdef inline void add_var(float64_t val, float64_t *nobs, float64_t *mean_x,
304
302
cdef:
305
303
float64_t delta, prev_mean, y, t
306
304
307
- # `isnan` instead of equality as fix for GH-21813, msvc 2017 bug
308
- if isnan( val) :
305
+ # GH#21813, if msvc 2017 bug is resolved, we should be OK with != instead of `isnan`
306
+ if val ! = val :
309
307
return
310
308
311
309
nobs[0 ] = nobs[0 ] + 1
@@ -329,7 +327,7 @@ cdef inline void remove_var(float64_t val, float64_t *nobs, float64_t *mean_x,
329
327
""" remove a value from the var calc """
330
328
cdef:
331
329
float64_t delta, prev_mean, y, t
332
- if notnan( val) :
330
+ if val == val :
333
331
nobs[0 ] = nobs[0 ] - 1
334
332
if nobs[0 ]:
335
333
# Welford's method for the online variance-calculation
@@ -455,7 +453,7 @@ cdef inline void add_skew(float64_t val, int64_t *nobs,
455
453
float64_t y, t
456
454
457
455
# Not NaN
458
- if notnan( val) :
456
+ if val == val :
459
457
nobs[0 ] = nobs[0 ] + 1
460
458
461
459
y = val - compensation_x[0 ]
@@ -483,7 +481,7 @@ cdef inline void remove_skew(float64_t val, int64_t *nobs,
483
481
float64_t y, t
484
482
485
483
# Not NaN
486
- if notnan( val) :
484
+ if val == val :
487
485
nobs[0 ] = nobs[0 ] - 1
488
486
489
487
y = - val - compensation_x[0 ]
@@ -525,7 +523,7 @@ def roll_skew(ndarray[float64_t] values, ndarray[int64_t] start,
525
523
with nogil:
526
524
for i in range(0, V ):
527
525
val = values_copy[i]
528
- if notnan( val) :
526
+ if val == val :
529
527
nobs_mean += 1
530
528
sum_val += val
531
529
mean_val = sum_val / nobs_mean
@@ -633,7 +631,7 @@ cdef inline void add_kurt(float64_t val, int64_t *nobs,
633
631
float64_t y, t
634
632
635
633
# Not NaN
636
- if notnan( val) :
634
+ if val == val :
637
635
nobs[0 ] = nobs[0 ] + 1
638
636
639
637
y = val - compensation_x[0 ]
@@ -666,7 +664,7 @@ cdef inline void remove_kurt(float64_t val, int64_t *nobs,
666
664
float64_t y, t
667
665
668
666
# Not NaN
669
- if notnan( val) :
667
+ if val == val :
670
668
nobs[0 ] = nobs[0 ] - 1
671
669
672
670
y = - val - compensation_x[0 ]
@@ -712,7 +710,7 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
712
710
with nogil:
713
711
for i in range(0, V ):
714
712
val = values_copy[i]
715
- if notnan( val) :
713
+ if val == val :
716
714
nobs_mean += 1
717
715
sum_val += val
718
716
mean_val = sum_val / nobs_mean
@@ -816,7 +814,7 @@ def roll_median_c(const float64_t[:] values, ndarray[int64_t] start,
816
814
# setup
817
815
for j in range (s, e):
818
816
val = values[j]
819
- if notnan( val) :
817
+ if val == val :
820
818
nobs += 1
821
819
err = skiplist_insert(sl, val) == - 1
822
820
if err:
@@ -827,7 +825,7 @@ def roll_median_c(const float64_t[:] values, ndarray[int64_t] start,
827
825
# calculate adds
828
826
for j in range (end[i - 1 ], e):
829
827
val = values[j]
830
- if notnan( val) :
828
+ if val == val :
831
829
nobs += 1
832
830
err = skiplist_insert(sl, val) == - 1
833
831
if err:
@@ -836,7 +834,7 @@ def roll_median_c(const float64_t[:] values, ndarray[int64_t] start,
836
834
# calculate deletes
837
835
for j in range (start[i - 1 ], s):
838
836
val = values[j]
839
- if notnan( val) :
837
+ if val == val :
840
838
skiplist_remove(sl, val)
841
839
nobs -= 1
842
840
if nobs >= minp:
@@ -1097,22 +1095,22 @@ def roll_quantile(const float64_t[:] values, ndarray[int64_t] start,
1097
1095
# setup
1098
1096
for j in range (s, e):
1099
1097
val = values[j]
1100
- if notnan( val) :
1098
+ if val == val :
1101
1099
nobs += 1
1102
1100
skiplist_insert(skiplist, val)
1103
1101
1104
1102
else :
1105
1103
# calculate adds
1106
1104
for j in range (end[i - 1 ], e):
1107
1105
val = values[j]
1108
- if notnan( val) :
1106
+ if val == val :
1109
1107
nobs += 1
1110
1108
skiplist_insert(skiplist, val)
1111
1109
1112
1110
# calculate deletes
1113
1111
for j in range (start[i - 1 ], s):
1114
1112
val = values[j]
1115
- if notnan( val) :
1113
+ if val == val :
1116
1114
skiplist_remove(skiplist, val)
1117
1115
nobs -= 1
1118
1116
if nobs >= minp:
@@ -1222,7 +1220,7 @@ def roll_rank(const float64_t[:] values, ndarray[int64_t] start,
1222
1220
# setup
1223
1221
for j in range (s, e):
1224
1222
val = values[j] if ascending else - values[j]
1225
- if notnan( val) :
1223
+ if val == val :
1226
1224
nobs += 1
1227
1225
rank = skiplist_insert(skiplist, val)
1228
1226
if rank == - 1 :
@@ -1249,14 +1247,14 @@ def roll_rank(const float64_t[:] values, ndarray[int64_t] start,
1249
1247
# calculate deletes
1250
1248
for j in range (start[i - 1 ], s):
1251
1249
val = values[j] if ascending else - values[j]
1252
- if notnan( val) :
1250
+ if val == val :
1253
1251
skiplist_remove(skiplist, val)
1254
1252
nobs -= 1
1255
1253
1256
1254
# calculate adds
1257
1255
for j in range (end[i - 1 ], e):
1258
1256
val = values[j] if ascending else - values[j]
1259
- if notnan( val) :
1257
+ if val == val :
1260
1258
nobs += 1
1261
1259
rank = skiplist_insert(skiplist, val)
1262
1260
if rank == - 1 :
@@ -1492,7 +1490,7 @@ cdef inline void add_weighted_var(float64_t val,
1492
1490
cdef:
1493
1491
float64_t temp, q, r
1494
1492
1495
- if isnan( val) :
1493
+ if val ! = val :
1496
1494
return
1497
1495
1498
1496
nobs[0 ] = nobs[0 ] + 1
@@ -1538,7 +1536,7 @@ cdef inline void remove_weighted_var(float64_t val,
1538
1536
cdef:
1539
1537
float64_t temp, q, r
1540
1538
1541
- if notnan( val) :
1539
+ if val == val :
1542
1540
nobs[0 ] = nobs[0 ] - 1
1543
1541
1544
1542
if nobs[0 ]:
@@ -1608,7 +1606,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights,
1608
1606
w = weights[i % win_n]
1609
1607
pre_w = weights[(i - win_n) % win_n]
1610
1608
1611
- if notnan( val) :
1609
+ if val == val :
1612
1610
if pre_val == pre_val:
1613
1611
remove_weighted_var(pre_val, pre_w, & t,
1614
1612
& sum_w, & mean, & nobs)
0 commit comments