Skip to content

BUG: Fix memory leak in Rolling.min and Rolling.max (#25893) #25926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions asv_bench/benchmarks/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,20 @@ def time_quantile(self, constructor, window, dtype, percentile,
self.roll.quantile(percentile, interpolation=interpolation)


class PeakMemFixed(object):

def setup(self):
N = 10
arr = 100 * np.random.random(N)
self.roll = pd.Series(arr).rolling(10)

def peakmem_fixed(self):
# GH 25926
# This is to detect memory leaks in rolling operations.
# To save time this is only ran on one method.
# 6000 iterations is enough for most types of leaks to be detected
for x in range(6000):
self.roll.max()


from .pandas_vb_common import setup # noqa: F401
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Groupby/Resample/Rolling
- Bug in :func:`pandas.core.groupby.GroupBy.agg` when applying a aggregation function to timezone aware data (:issue:`23683`)
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` where timezone information would be dropped (:issue:`21603`)
- Ensured that ordering of outputs in ``groupby`` aggregation functions is consistent across all versions of Python (:issue:`25692`)
- Bug in :meth:`pandas.core.window.Rolling.min` and :meth:`pandas.core.window.Rolling.max` that caused a memory leak (:issue:`25893`)
- Bug in :func:`idxmax` and :func:`idxmin` on :meth:`DataFrame.groupby` with datetime column would return incorrect dtype (:issue:`25444`, :issue:`15306`)


Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ cdef _roll_min_max(ndarray[numeric] values, int64_t win, int64_t minp,
return _roll_min_max_variable(values, starti, endi, N, win, minp,
is_max)
else:
return _roll_min_max_fixed(values, starti, endi, N, win, minp, is_max)
return _roll_min_max_fixed(values, N, win, minp, is_max)


cdef _roll_min_max_variable(ndarray[numeric] values,
Expand Down Expand Up @@ -1349,8 +1349,6 @@ cdef _roll_min_max_variable(ndarray[numeric] values,


cdef _roll_min_max_fixed(ndarray[numeric] values,
ndarray[int64_t] starti,
ndarray[int64_t] endi,
int64_t N,
int64_t win,
int64_t minp,
Expand Down