Skip to content

Commit f89a4a0

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 38e1b9b commit f89a4a0

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
@@ -970,8 +970,8 @@ cdef inline numeric calc_mm(int64_t minp, Py_ssize_t nobs,
970970
return result
971971

972972

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

992992

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

10121012

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

10291029

10301030
def roll_min_variable(ndarray[float64_t] values, ndarray[int64_t] start,
@@ -1111,9 +1111,7 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
11111111
return output
11121112

11131113

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

0 commit comments

Comments
 (0)