Skip to content

Windows CI #23182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Try defining notnan
  • Loading branch information
TomAugspurger committed Oct 17, 2018
commit 29f392c4fdfa23ab6d16f31d824eab143e657cb4
7 changes: 6 additions & 1 deletion pandas/_libs/src/headers/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
namespace std {
__inline int isnan(double x) { return _isnan(x); }
__inline int signbit(double num) { return _copysign(1.0, num) < 0; }
__inline int notnan(double x) { return not isnan(x); }
}
#else
#include <cmath>
#endif

namespace std {
__inline int notnan(double x) { return x == x; }
}

#endif
#endif
39 changes: 20 additions & 19 deletions pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cnp.import_array()

cdef extern from "src/headers/cmath" namespace "std":
bint isnan(double) nogil
bint notnan(double) nogil
int signbit(double) nogil
double sqrt(double x) nogil

Expand Down Expand Up @@ -381,21 +382,21 @@ def roll_count(ndarray[double_t] input, int64_t win, int64_t minp,
count_x = 0.0
for j in range(s, e):
val = input[j]
if not isnan(val):
if notnan(val):
count_x += 1.0

else:

# calculate deletes
for j in range(start[i - 1], s):
val = input[j]
if not isnan(val):
if notnan(val):
count_x -= 1.0

# calculate adds
for j in range(end[i - 1], e):
val = input[j]
if not isnan(val):
if notnan(val):
count_x += 1.0

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] + 1
sum_x[0] = sum_x[0] + val


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

if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] - 1
sum_x[0] = sum_x[0] - val

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] + 1
sum_x[0] = sum_x[0] + val
if signbit(val):
Expand All @@ -549,7 +550,7 @@ cdef inline void remove_mean(double val, Py_ssize_t *nobs, double *sum_x,
Py_ssize_t *neg_ct) nogil:
""" remove a value from the mean calc """

if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] - 1
sum_x[0] = sum_x[0] - val
if signbit(val):
Expand Down Expand Up @@ -671,7 +672,7 @@ cdef inline void remove_var(double val, double *nobs, double *mean_x,
""" remove a value from the var calc """
cdef double delta

if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] - 1
if nobs[0]:
# a part of Welford's method for the online variance-calculation
Expand Down Expand Up @@ -759,7 +760,7 @@ def roll_var(ndarray[double_t] input, int64_t win, int64_t minp,
val = input[i]
prev = input[i - win]

if not isnan(val):
if notnan(val):
if prev == prev:

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] + 1

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] - 1

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] + 1

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

# Not NaN
if not isnan(val):
if notnan(val):
nobs[0] = nobs[0] - 1

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

# setup
val = input[i]
if not isnan(val):
if notnan(val):
nobs += 1
err = skiplist_insert(sl, val) != 1
if err:
Expand All @@ -1099,14 +1100,14 @@ def roll_median_c(ndarray[float64_t] input, int64_t win, int64_t minp,
# calculate deletes
for j in range(start[i - 1], s):
val = input[j]
if not isnan(val):
if notnan(val):
skiplist_remove(sl, val)
nobs -= 1

# calculate adds
for j in range(end[i - 1], e):
val = input[j]
if not isnan(val):
if notnan(val):
nobs += 1
err = skiplist_insert(sl, val) != 1
if err:
Expand Down Expand Up @@ -1471,7 +1472,7 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,

# setup
val = input[i]
if not isnan(val):
if notnan(val):
nobs += 1
skiplist_insert(skiplist, val)

Expand All @@ -1480,14 +1481,14 @@ def roll_quantile(ndarray[float64_t, cast=True] input, int64_t win,
# calculate deletes
for j in range(start[i - 1], s):
val = input[j]
if not isnan(val):
if notnan(val):
skiplist_remove(skiplist, val)
nobs -= 1

# calculate adds
for j in range(end[i - 1], e):
val = input[j]
if not isnan(val):
if notnan(val):
nobs += 1
skiplist_insert(skiplist, val)

Expand Down