Skip to content

Commit b55d357

Browse files
audersonauderson
authored and
auderson
committed
use MAXfloat64 MINfloat64 for inf; reformat code
1 parent 89113c5 commit b55d357

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

pandas/_libs/window/aggregations.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ cdef inline void add_var(float64_t val, float64_t *nobs, float64_t *mean_x,
310310
nobs[0] = nobs[0] + 1
311311

312312
# GH#42064, record num of same values to remove floating point artifacts
313-
if val == prev_value[0] and val != np.inf and val != np.NINF:
313+
if val == prev_value[0] and val != MAXfloat64 and val != MINfloat64:
314314
num_consecutive_same_value[0] += 1
315315
else:
316316
num_consecutive_same_value[0] = 1 # reset to 1 (include current value itself)

pandas/core/_numba/kernels/var_.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616

1717
@numba.jit(nopython=True, nogil=True, parallel=False)
1818
def add_var(
19-
val: float, nobs: int, mean_x: float, ssqdm_x: float, compensation: float,
20-
num_consecutive_same_value: int, prev_value: float
19+
val: float,
20+
nobs: int,
21+
mean_x: float,
22+
ssqdm_x: float,
23+
compensation: float,
24+
num_consecutive_same_value: int,
25+
prev_value: float
2126
) -> tuple[int, float, float, float, int, float]:
2227
if not np.isnan(val):
2328

@@ -93,11 +98,22 @@ def sliding_var(
9398

9499
for j in range(s, e):
95100
val = values[j]
96-
nobs, mean_x, ssqdm_x, compensation_add, \
97-
num_consecutive_same_value, prev_value = add_var(
98-
val, nobs, mean_x, ssqdm_x, compensation_add,
99-
num_consecutive_same_value, prev_value
100-
)
101+
(
102+
nobs,
103+
mean_x,
104+
ssqdm_x,
105+
compensation_add,
106+
num_consecutive_same_value,
107+
prev_value,
108+
) = add_var(
109+
val,
110+
nobs,
111+
mean_x,
112+
ssqdm_x,
113+
compensation_add,
114+
num_consecutive_same_value,
115+
prev_value,
116+
)
101117
else:
102118
for j in range(start[i - 1], s):
103119
val = values[j]
@@ -107,11 +123,22 @@ def sliding_var(
107123

108124
for j in range(end[i - 1], e):
109125
val = values[j]
110-
nobs, mean_x, ssqdm_x, compensation_add, \
111-
num_consecutive_same_value, prev_value = add_var(
112-
val, nobs, mean_x, ssqdm_x, compensation_add,
113-
num_consecutive_same_value, prev_value
114-
)
126+
(
127+
nobs,
128+
mean_x,
129+
ssqdm_x,
130+
compensation_add,
131+
num_consecutive_same_value,
132+
prev_value,
133+
) = add_var(
134+
val,
135+
nobs,
136+
mean_x,
137+
ssqdm_x,
138+
compensation_add,
139+
num_consecutive_same_value,
140+
prev_value,
141+
)
115142

116143
if nobs >= min_periods and nobs > ddof:
117144
if nobs == 1 or num_consecutive_same_value >= nobs:

0 commit comments

Comments
 (0)