Skip to content

Commit d421a7a

Browse files
committed
BUG: Fix memory issues in rolling.min/max
This fixes at least the reproducible part of pandas-dev#30726, however, I am not totally sure what is going on here. Tests have shown that there are two solutions that avoid growing memory usage: - pass memoryviews (float64_t[:]) instead of ndarray[float64_t] - remove starti and endi as arguments to _roll_min_max_fixed This commit implements both.
1 parent 837daf1 commit d421a7a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

pandas/_libs/window/aggregations.pyx

+7-9
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ cdef inline numeric calc_mm(int64_t minp, Py_ssize_t nobs,
971971
return result
972972

973973

974-
def roll_max_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
975-
ndarray[int64_t] end, int64_t minp, int64_t win):
974+
def roll_max_fixed(float64_t[:] values, int64_t[:] start,
975+
int64_t[:] end, int64_t minp, int64_t win):
976976
"""
977977
Moving max of 1d array of any numeric type along axis=0 ignoring NaNs.
978978
@@ -988,7 +988,7 @@ def roll_max_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
988988
make the interval closed on the right, left,
989989
both or neither endpoints
990990
"""
991-
return _roll_min_max_fixed(values, start, end, minp, win, is_max=1)
991+
return _roll_min_max_fixed(values, minp, win, is_max=1)
992992

993993

994994
def roll_max_variable(ndarray[float64_t] values, ndarray[int64_t] start,
@@ -1011,8 +1011,8 @@ def roll_max_variable(ndarray[float64_t] values, ndarray[int64_t] start,
10111011
return _roll_min_max_variable(values, start, end, minp, is_max=1)
10121012

10131013

1014-
def roll_min_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
1015-
ndarray[int64_t] end, int64_t minp, int64_t win):
1014+
def roll_min_fixed(float64_t[:] values, int64_t[:] start,
1015+
int64_t[:] end, int64_t minp, int64_t win):
10161016
"""
10171017
Moving min of 1d array of any numeric type along axis=0 ignoring NaNs.
10181018
@@ -1025,7 +1025,7 @@ def roll_min_fixed(ndarray[float64_t] values, ndarray[int64_t] start,
10251025
index : ndarray, optional
10261026
index for window computation
10271027
"""
1028-
return _roll_min_max_fixed(values, start, end, minp, win, is_max=0)
1028+
return _roll_min_max_fixed(values, minp, win, is_max=0)
10291029

10301030

10311031
def roll_min_variable(ndarray[float64_t] values, ndarray[int64_t] start,
@@ -1112,9 +1112,7 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
11121112
return output
11131113

11141114

1115-
cdef _roll_min_max_fixed(ndarray[numeric] values,
1116-
ndarray[int64_t] starti,
1117-
ndarray[int64_t] endi,
1115+
cdef _roll_min_max_fixed(numeric[:] values,
11181116
int64_t minp,
11191117
int64_t win,
11201118
bint is_max):

0 commit comments

Comments
 (0)