Skip to content

Commit 00c119c

Browse files
ArtificialQualiajreback
authored andcommitted
BUG: Fix memory leak in Rolling.min and Rolling.max (#25893) (#25926)
1 parent c7c4c94 commit 00c119c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

asv_bench/benchmarks/rolling.py

+16
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,20 @@ def time_quantile(self, constructor, window, dtype, percentile,
113113
self.roll.quantile(percentile, interpolation=interpolation)
114114

115115

116+
class PeakMemFixed(object):
117+
118+
def setup(self):
119+
N = 10
120+
arr = 100 * np.random.random(N)
121+
self.roll = pd.Series(arr).rolling(10)
122+
123+
def peakmem_fixed(self):
124+
# GH 25926
125+
# This is to detect memory leaks in rolling operations.
126+
# To save time this is only ran on one method.
127+
# 6000 iterations is enough for most types of leaks to be detected
128+
for x in range(6000):
129+
self.roll.max()
130+
131+
116132
from .pandas_vb_common import setup # noqa: F401

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ Groupby/Resample/Rolling
374374
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` where timezone information would be dropped (:issue:`21603`)
375375
- Bug in :func:`Series.groupby` where using ``groupby`` with a :class:`MultiIndex` Series with a list of labels equal to the length of the series caused incorrect grouping (:issue:`25704`)
376376
- Ensured that ordering of outputs in ``groupby`` aggregation functions is consistent across all versions of Python (:issue:`25692`)
377+
- Bug in :meth:`pandas.core.window.Rolling.min` and :meth:`pandas.core.window.Rolling.max` that caused a memory leak (:issue:`25893`)
377378
- Bug in :func:`idxmax` and :func:`idxmin` on :meth:`DataFrame.groupby` with datetime column would return incorrect dtype (:issue:`25444`, :issue:`15306`)
378379

379380

pandas/_libs/window.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ cdef _roll_min_max(ndarray[numeric] values, int64_t win, int64_t minp,
12631263
return _roll_min_max_variable(values, starti, endi, N, win, minp,
12641264
is_max)
12651265
else:
1266-
return _roll_min_max_fixed(values, starti, endi, N, win, minp, is_max)
1266+
return _roll_min_max_fixed(values, N, win, minp, is_max)
12671267

12681268

12691269
cdef _roll_min_max_variable(ndarray[numeric] values,
@@ -1349,8 +1349,6 @@ cdef _roll_min_max_variable(ndarray[numeric] values,
13491349

13501350

13511351
cdef _roll_min_max_fixed(ndarray[numeric] values,
1352-
ndarray[int64_t] starti,
1353-
ndarray[int64_t] endi,
13541352
int64_t N,
13551353
int64_t win,
13561354
int64_t minp,

0 commit comments

Comments
 (0)