Skip to content

Commit c8d79f0

Browse files
committed
FIX: fix the min-max calculation algorithm
1 parent 722710d commit c8d79f0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pandas/_libs/window/aggregations.pyx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
10511051
bint is_max):
10521052
cdef:
10531053
numeric ai
1054-
int64_t i, close_offset, curr_win_size
1054+
int64_t i, k, close_offset, curr_win_size
10551055
Py_ssize_t nobs = 0, N = len(values)
10561056
deque Q[int64_t] # min/max always the front
10571057
deque W[int64_t] # track the whole window for nobs compute
@@ -1088,12 +1088,14 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
10881088
# first window's size
10891089
curr_win_size = endi[0] - starti[0]
10901090

1091+
k = 0
10911092
for i in range(endi[0], endi[N-1]):
10921093
if not Q.empty() and curr_win_size > 0:
1093-
output[i-1+close_offset] = calc_mm(
1094+
output[k] = calc_mm(
10941095
minp, nobs, values[Q.front()])
10951096
else:
1096-
output[i-1+close_offset] = NaN
1097+
output[k] = NaN
1098+
k += 1
10971099

10981100
ai = init_mm(values[i], &nobs, is_max)
10991101

@@ -1119,9 +1121,9 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
11191121
W.push_back(i)
11201122

11211123
if not Q.empty() and curr_win_size > 0:
1122-
output[N-1] = calc_mm(minp, nobs, values[Q.front()])
1124+
output[k] = calc_mm(minp, nobs, values[Q.front()])
11231125
else:
1124-
output[N-1] = NaN
1126+
output[k] = NaN
11251127

11261128
return output
11271129

0 commit comments

Comments
 (0)