Skip to content

Commit 269b2e6

Browse files
committed
CLN: remove cmath, closes pandas-dev#23209
1 parent 3b58f48 commit 269b2e6

File tree

2 files changed

+23
-63
lines changed

2 files changed

+23
-63
lines changed

pandas/_libs/src/headers/cmath

-36
This file was deleted.

pandas/_libs/window.pyx

+23-27
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ from libc.stdlib cimport malloc, free
99
import numpy as np
1010
cimport numpy as cnp
1111
from numpy cimport ndarray, int64_t, float64_t, float32_t
12+
from numpy.math cimport signbit, isnan, sqrtl as sqrt
13+
# sqrtl is square root specialized to "long double"
1214
cnp.import_array()
1315

1416

15-
cdef extern from "src/headers/cmath" namespace "std":
16-
bint isnan(float64_t) nogil
17-
bint notnan(float64_t) nogil
18-
int signbit(float64_t) nogil
19-
float64_t sqrt(float64_t x) nogil
20-
2117
cimport pandas._libs.util as util
2218
from pandas._libs.util cimport numeric
2319

@@ -384,21 +380,21 @@ def roll_count(ndarray[float64_t] values, int64_t win, int64_t minp,
384380
count_x = 0.0
385381
for j in range(s, e):
386382
val = values[j]
387-
if notnan(val):
383+
if not isnan(val):
388384
count_x += 1.0
389385

390386
else:
391387

392388
# calculate deletes
393389
for j in range(start[i - 1], s):
394390
val = values[j]
395-
if notnan(val):
391+
if not isnan(val):
396392
count_x -= 1.0
397393

398394
# calculate adds
399395
for j in range(end[i - 1], e):
400396
val = values[j]
401-
if notnan(val):
397+
if not isnan(val):
402398
count_x += 1.0
403399

404400
if count_x >= minp:
@@ -429,15 +425,15 @@ cdef inline void add_sum(float64_t val, int64_t *nobs, float64_t *sum_x) nogil:
429425
""" add a value from the sum calc """
430426

431427
# Not NaN
432-
if notnan(val):
428+
if not isnan(val):
433429
nobs[0] = nobs[0] + 1
434430
sum_x[0] = sum_x[0] + val
435431

436432

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

440-
if notnan(val):
436+
if not isnan(val):
441437
nobs[0] = nobs[0] - 1
442438
sum_x[0] = sum_x[0] - val
443439

@@ -545,7 +541,7 @@ cdef inline void add_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
545541
""" add a value from the mean calc """
546542

547543
# Not NaN
548-
if notnan(val):
544+
if not isnan(val):
549545
nobs[0] = nobs[0] + 1
550546
sum_x[0] = sum_x[0] + val
551547
if signbit(val):
@@ -556,7 +552,7 @@ cdef inline void remove_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
556552
Py_ssize_t *neg_ct) nogil:
557553
""" remove a value from the mean calc """
558554

559-
if notnan(val):
555+
if not isnan(val):
560556
nobs[0] = nobs[0] - 1
561557
sum_x[0] = sum_x[0] - val
562558
if signbit(val):
@@ -683,7 +679,7 @@ cdef inline void remove_var(float64_t val, float64_t *nobs, float64_t *mean_x,
683679
cdef:
684680
float64_t delta
685681

686-
if notnan(val):
682+
if not isnan(val):
687683
nobs[0] = nobs[0] - 1
688684
if nobs[0]:
689685
# a part of Welford's method for the online variance-calculation
@@ -772,7 +768,7 @@ def roll_var(ndarray[float64_t] values, int64_t win, int64_t minp,
772768
val = values[i]
773769
prev = values[i - win]
774770

775-
if notnan(val):
771+
if not isnan(val):
776772
if prev == prev:
777773

778774
# Adding one observation and removing another one
@@ -837,7 +833,7 @@ cdef inline void add_skew(float64_t val, int64_t *nobs,
837833
""" add a value from the skew calc """
838834

839835
# Not NaN
840-
if notnan(val):
836+
if not isnan(val):
841837
nobs[0] = nobs[0] + 1
842838

843839
# seriously don't ask me why this is faster
@@ -852,7 +848,7 @@ cdef inline void remove_skew(float64_t val, int64_t *nobs,
852848
""" remove a value from the skew calc """
853849

854850
# Not NaN
855-
if notnan(val):
851+
if not isnan(val):
856852
nobs[0] = nobs[0] - 1
857853

858854
# seriously don't ask me why this is faster
@@ -979,7 +975,7 @@ cdef inline void add_kurt(float64_t val, int64_t *nobs,
979975
""" add a value from the kurotic calc """
980976

981977
# Not NaN
982-
if notnan(val):
978+
if not isnan(val):
983979
nobs[0] = nobs[0] + 1
984980

985981
# seriously don't ask me why this is faster
@@ -995,7 +991,7 @@ cdef inline void remove_kurt(float64_t val, int64_t *nobs,
995991
""" remove a value from the kurotic calc """
996992

997993
# Not NaN
998-
if notnan(val):
994+
if not isnan(val):
999995
nobs[0] = nobs[0] - 1
1000996

1001997
# seriously don't ask me why this is faster
@@ -1116,7 +1112,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
11161112
# setup
11171113
for j in range(s, e):
11181114
val = values[j]
1119-
if notnan(val):
1115+
if not isnan(val):
11201116
nobs += 1
11211117
err = skiplist_insert(sl, val) != 1
11221118
if err:
@@ -1127,7 +1123,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
11271123
# calculate adds
11281124
for j in range(end[i - 1], e):
11291125
val = values[j]
1130-
if notnan(val):
1126+
if not isnan(val):
11311127
nobs += 1
11321128
err = skiplist_insert(sl, val) != 1
11331129
if err:
@@ -1136,7 +1132,7 @@ def roll_median_c(ndarray[float64_t] values, int64_t win, int64_t minp,
11361132
# calculate deletes
11371133
for j in range(start[i - 1], s):
11381134
val = values[j]
1139-
if notnan(val):
1135+
if not isnan(val):
11401136
skiplist_remove(sl, val)
11411137
nobs -= 1
11421138

@@ -1510,7 +1506,7 @@ def roll_quantile(ndarray[float64_t, cast=True] values, int64_t win,
15101506
# setup
15111507
for j in range(s, e):
15121508
val = values[j]
1513-
if notnan(val):
1509+
if not isnan(val):
15141510
nobs += 1
15151511
skiplist_insert(skiplist, val)
15161512

@@ -1519,14 +1515,14 @@ def roll_quantile(ndarray[float64_t, cast=True] values, int64_t win,
15191515
# calculate adds
15201516
for j in range(end[i - 1], e):
15211517
val = values[j]
1522-
if notnan(val):
1518+
if not isnan(val):
15231519
nobs += 1
15241520
skiplist_insert(skiplist, val)
15251521

15261522
# calculate deletes
15271523
for j in range(start[i - 1], s):
15281524
val = values[j]
1529-
if notnan(val):
1525+
if not isnan(val):
15301526
skiplist_remove(skiplist, val)
15311527
nobs -= 1
15321528

@@ -1885,7 +1881,7 @@ cdef inline void remove_weighted_var(float64_t val,
18851881
cdef:
18861882
float64_t temp, q, r
18871883

1888-
if notnan(val):
1884+
if not isnan(val):
18891885
nobs[0] = nobs[0] - 1
18901886

18911887
if nobs[0]:
@@ -1955,7 +1951,7 @@ def roll_weighted_var(float64_t[:] values, float64_t[:] weights,
19551951
w = weights[i % win_n]
19561952
pre_w = weights[(i - win_n) % win_n]
19571953

1958-
if notnan(val):
1954+
if not isnan(val):
19591955
if pre_val == pre_val:
19601956
remove_weighted_var(pre_val, pre_w, &t,
19611957
&sum_w, &mean, &nobs)

0 commit comments

Comments
 (0)