@@ -73,9 +73,7 @@ cdef inline float64_t calc_sum(int64_t minp, int64_t nobs, float64_t sum_x) nogi
73
73
cdef:
74
74
float64_t result
75
75
76
- if nobs == 0 == minp:
77
- result = 0
78
- elif nobs >= minp:
76
+ if nobs >= minp:
79
77
result = sum_x
80
78
else :
81
79
result = NaN
@@ -116,7 +114,7 @@ cdef inline void remove_sum(float64_t val, int64_t *nobs, float64_t *sum_x,
116
114
117
115
118
116
def roll_sum (const float64_t[:] values , ndarray[int64_t] start ,
119
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
117
+ ndarray[int64_t] end , int64_t minp ):
120
118
cdef:
121
119
Py_ssize_t i, j
122
120
float64_t sum_x = 0 , compensation_add = 0 , compensation_remove = 0
@@ -128,7 +126,7 @@ def roll_sum(const float64_t[:] values, ndarray[int64_t] start,
128
126
is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
129
127
start, end
130
128
)
131
- output = np.empty(N, dtype = np.float64 )
129
+ output = np.empty(N, dtype = float )
132
130
133
131
with nogil:
134
132
@@ -172,7 +170,7 @@ cdef inline float64_t calc_mean(int64_t minp, Py_ssize_t nobs,
172
170
cdef:
173
171
float64_t result
174
172
175
- if nobs >= minp and nobs > 0 :
173
+ if nobs >= minp:
176
174
result = sum_x / < float64_t> nobs
177
175
if neg_ct == 0 and result < 0 :
178
176
# all positive
@@ -221,7 +219,7 @@ cdef inline void remove_mean(float64_t val, Py_ssize_t *nobs, float64_t *sum_x,
221
219
222
220
223
221
def roll_mean (const float64_t[:] values , ndarray[int64_t] start ,
224
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
222
+ ndarray[int64_t] end , int64_t minp ):
225
223
cdef:
226
224
float64_t val, compensation_add = 0 , compensation_remove = 0 , sum_x = 0
227
225
int64_t s, e
@@ -232,7 +230,7 @@ def roll_mean(const float64_t[:] values, ndarray[int64_t] start,
232
230
is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
233
231
start, end
234
232
)
235
- output = np.empty(N, dtype = np.float64 )
233
+ output = np.empty(N, dtype = float )
236
234
237
235
with nogil:
238
236
@@ -338,7 +336,7 @@ cdef inline void remove_var(float64_t val, float64_t *nobs, float64_t *mean_x,
338
336
339
337
340
338
def roll_var (const float64_t[:] values , ndarray[int64_t] start ,
341
- ndarray[int64_t] end , int64_t minp , int ddof = 1 ) -> np.ndarray :
339
+ ndarray[int64_t] end , int64_t minp , int ddof = 1 ):
342
340
"""
343
341
Numerically stable implementation using Welford's method.
344
342
"""
@@ -355,7 +353,7 @@ def roll_var(const float64_t[:] values, ndarray[int64_t] start,
355
353
is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
356
354
start, end
357
355
)
358
- output = np.empty(N, dtype = np.float64 )
356
+ output = np.empty(N, dtype = float )
359
357
360
358
with nogil:
361
359
@@ -490,7 +488,7 @@ cdef inline void remove_skew(float64_t val, int64_t *nobs,
490
488
491
489
492
490
def roll_skew (ndarray[float64_t] values , ndarray[int64_t] start ,
493
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
491
+ ndarray[int64_t] end , int64_t minp ):
494
492
cdef:
495
493
Py_ssize_t i, j
496
494
float64_t val, prev, min_val, mean_val, sum_val = 0
@@ -507,7 +505,7 @@ def roll_skew(ndarray[float64_t] values, ndarray[int64_t] start,
507
505
is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
508
506
start, end
509
507
)
510
- output = np.empty(N, dtype = np.float64 )
508
+ output = np.empty(N, dtype = float )
511
509
min_val = np.nanmin(values)
512
510
values_copy = np.copy(values)
513
511
@@ -672,7 +670,7 @@ cdef inline void remove_kurt(float64_t val, int64_t *nobs,
672
670
673
671
674
672
def roll_kurt (ndarray[float64_t] values , ndarray[int64_t] start ,
675
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
673
+ ndarray[int64_t] end , int64_t minp ):
676
674
cdef:
677
675
Py_ssize_t i, j
678
676
float64_t val, prev, mean_val, min_val, sum_val = 0
@@ -689,7 +687,7 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
689
687
is_monotonic_increasing_bounds = is_monotonic_increasing_start_end_bounds(
690
688
start, end
691
689
)
692
- output = np.empty(N, dtype = np.float64 )
690
+ output = np.empty(N, dtype = float )
693
691
values_copy = np.copy(values)
694
692
min_val = np.nanmin(values)
695
693
@@ -753,7 +751,7 @@ def roll_kurt(ndarray[float64_t] values, ndarray[int64_t] start,
753
751
754
752
755
753
def roll_median_c (const float64_t[:] values , ndarray[int64_t] start ,
756
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
754
+ ndarray[int64_t] end , int64_t minp ):
757
755
cdef:
758
756
Py_ssize_t i, j
759
757
bint err = False , is_monotonic_increasing_bounds
@@ -769,7 +767,7 @@ def roll_median_c(const float64_t[:] values, ndarray[int64_t] start,
769
767
770
768
# we use the Fixed/Variable Indexer here as the
771
769
# actual skiplist ops outweigh any window computation costs
772
- output = np.empty(N, dtype = np.float64 )
770
+ output = np.empty(N, dtype = float )
773
771
774
772
if (end - start).max() == 0 :
775
773
output[:] = NaN
@@ -889,7 +887,7 @@ cdef inline numeric calc_mm(int64_t minp, Py_ssize_t nobs,
889
887
890
888
891
889
def roll_max (ndarray[float64_t] values , ndarray[int64_t] start ,
892
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
890
+ ndarray[int64_t] end , int64_t minp ):
893
891
"""
894
892
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs.
895
893
@@ -904,16 +902,12 @@ def roll_max(ndarray[float64_t] values, ndarray[int64_t] start,
904
902
closed : 'right', 'left', 'both', 'neither'
905
903
make the interval closed on the right, left,
906
904
both or neither endpoints
907
-
908
- Returns
909
- -------
910
- np.ndarray[float]
911
905
"""
912
906
return _roll_min_max(values, start, end, minp, is_max = 1 )
913
907
914
908
915
909
def roll_min (ndarray[float64_t] values , ndarray[int64_t] start ,
916
- ndarray[int64_t] end , int64_t minp ) -> np.ndarray :
910
+ ndarray[int64_t] end , int64_t minp ):
917
911
"""
918
912
Moving min of 1d array of any numeric type along axis=0 ignoring NaNs.
919
913
@@ -925,10 +919,6 @@ def roll_min(ndarray[float64_t] values, ndarray[int64_t] start,
925
919
is below this, output a NaN
926
920
index : ndarray, optional
927
921
index for window computation
928
-
929
- Returns
930
- -------
931
- np.ndarray[float]
932
922
"""
933
923
return _roll_min_max(values, start, end, minp, is_max = 0 )
934
924
@@ -946,7 +936,7 @@ cdef _roll_min_max(ndarray[numeric] values,
946
936
deque W[int64_t] # track the whole window for nobs compute
947
937
ndarray[float64_t, ndim= 1 ] output
948
938
949
- output = np.empty(N, dtype = np.float64 )
939
+ output = np.empty(N, dtype = float )
950
940
Q = deque[int64_t]()
951
941
W = deque[int64_t]()
952
942
@@ -1019,7 +1009,7 @@ interpolation_types = {
1019
1009
1020
1010
def roll_quantile (const float64_t[:] values , ndarray[int64_t] start ,
1021
1011
ndarray[int64_t] end , int64_t minp ,
1022
- float64_t quantile , str interpolation ) -> np.ndarray :
1012
+ float64_t quantile , str interpolation ):
1023
1013
"""
1024
1014
O(N log(window)) implementation using skip list
1025
1015
"""
@@ -1046,7 +1036,7 @@ def roll_quantile(const float64_t[:] values, ndarray[int64_t] start,
1046
1036
)
1047
1037
# we use the Fixed/Variable Indexer here as the
1048
1038
# actual skiplist ops outweigh any window computation costs
1049
- output = np.empty(N, dtype = np.float64 )
1039
+ output = np.empty(N, dtype = float )
1050
1040
1051
1041
win = (end - start).max()
1052
1042
if win == 0 :
@@ -1140,7 +1130,7 @@ def roll_apply(object obj,
1140
1130
ndarray[int64_t] start , ndarray[int64_t] end ,
1141
1131
int64_t minp ,
1142
1132
object function , bint raw ,
1143
- tuple args , dict kwargs ) -> np.ndarray :
1133
+ tuple args , dict kwargs ):
1144
1134
cdef:
1145
1135
ndarray[float64_t] output, counts
1146
1136
ndarray[float64_t, cast= True ] arr
@@ -1157,7 +1147,7 @@ def roll_apply(object obj,
1157
1147
1158
1148
counts = roll_sum(np.isfinite(arr).astype(float ), start, end, minp)
1159
1149
1160
- output = np.empty(N, dtype = np.float64 )
1150
+ output = np.empty(N, dtype = float )
1161
1151
1162
1152
for i in range (N):
1163
1153
@@ -1179,15 +1169,11 @@ def roll_apply(object obj,
1179
1169
# Rolling sum and mean for weighted window
1180
1170
1181
1171
1182
- def roll_weighted_sum (
1183
- const float64_t[:] values , const float64_t[:] weights , int minp
1184
- ) -> np.ndaray:
1172
+ def roll_weighted_sum (const float64_t[:] values , const float64_t[:] weights , int minp ):
1185
1173
return _roll_weighted_sum_mean(values, weights, minp, avg = 0 )
1186
1174
1187
1175
1188
- def roll_weighted_mean(
1189
- const float64_t[:] values , const float64_t[:] weights , int minp
1190
- ) -> np.ndaray:
1176
+ def roll_weighted_mean (const float64_t[:] values , const float64_t[:] weights , int minp ):
1191
1177
return _roll_weighted_sum_mean(values, weights, minp, avg = 1 )
1192
1178
1193
1179
@@ -1446,7 +1432,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights,
1446
1432
1447
1433
n = len (values)
1448
1434
win_n = len (weights)
1449
- output = np.empty(n, dtype = np.float64 )
1435
+ output = np.empty(n, dtype = float )
1450
1436
1451
1437
with nogil:
1452
1438
@@ -1486,7 +1472,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights,
1486
1472
1487
1473
def ewma (const float64_t[:] vals , const int64_t[:] start , const int64_t[:] end ,
1488
1474
int minp , float64_t com , bint adjust , bint ignore_na ,
1489
- const float64_t[:] deltas ) -> np.ndarray :
1475
+ const float64_t[:] deltas ):
1490
1476
"""
1491
1477
Compute exponentially-weighted moving average using center-of-mass.
1492
1478
@@ -1503,13 +1489,13 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1503
1489
1504
1490
Returns
1505
1491
-------
1506
- np. ndarray[float64_t]
1492
+ ndarray
1507
1493
"""
1508
1494
1509
1495
cdef:
1510
1496
Py_ssize_t i, j, s, e, nobs, win_size, N = len (vals), M = len (start)
1511
1497
const float64_t[:] sub_deltas, sub_vals
1512
- ndarray[float64_t] sub_output , output = np.empty(N, dtype = np.float64 )
1498
+ ndarray[float64_t] sub_output, output = np.empty(N, dtype = float )
1513
1499
float64_t alpha, old_wt_factor, new_wt, weighted_avg, old_wt, cur
1514
1500
bint is_observation
1515
1501
@@ -1528,7 +1514,7 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1528
1514
# conjunction with vals[i+1]
1529
1515
sub_deltas = deltas[s:e - 1 ]
1530
1516
win_size = len (sub_vals)
1531
- sub_output = np.empty(win_size, dtype = np.float64 )
1517
+ sub_output = np.empty(win_size, dtype = float )
1532
1518
1533
1519
weighted_avg = sub_vals[0 ]
1534
1520
is_observation = weighted_avg == weighted_avg
@@ -1571,7 +1557,7 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1571
1557
1572
1558
def ewmcov (const float64_t[:] input_x , const int64_t[:] start , const int64_t[:] end ,
1573
1559
int minp , const float64_t[:] input_y , float64_t com , bint adjust ,
1574
- bint ignore_na , bint bias ) -> np.ndarray :
1560
+ bint ignore_na , bint bias ):
1575
1561
"""
1576
1562
Compute exponentially-weighted moving variance using center-of-mass.
1577
1563
@@ -1589,7 +1575,7 @@ def ewmcov(const float64_t[:] input_x, const int64_t[:] start, const int64_t[:]
1589
1575
1590
1576
Returns
1591
1577
-------
1592
- np. ndarray[float64_t]
1578
+ ndarray
1593
1579
"""
1594
1580
1595
1581
cdef:
@@ -1599,7 +1585,7 @@ def ewmcov(const float64_t[:] input_x, const int64_t[:] start, const int64_t[:]
1599
1585
float64_t sum_wt, sum_wt2, old_wt, cur_x, cur_y, old_mean_x, old_mean_y
1600
1586
float64_t numerator, denominator
1601
1587
const float64_t[:] sub_x_vals, sub_y_vals
1602
- ndarray[float64_t] sub_out , output = np.empty(N, dtype = np.float64 )
1588
+ ndarray[float64_t] sub_out, output = np.empty(N, dtype = float )
1603
1589
bint is_observation
1604
1590
1605
1591
if M != N:
@@ -1618,7 +1604,7 @@ def ewmcov(const float64_t[:] input_x, const int64_t[:] start, const int64_t[:]
1618
1604
sub_x_vals = input_x[s:e]
1619
1605
sub_y_vals = input_y[s:e]
1620
1606
win_size = len (sub_x_vals)
1621
- sub_out = np.empty(win_size, dtype = np.float64 )
1607
+ sub_out = np.empty(win_size, dtype = float )
1622
1608
1623
1609
mean_x = sub_x_vals[0 ]
1624
1610
mean_y = sub_y_vals[0 ]
0 commit comments