Skip to content

Commit e083e01

Browse files
committed
BUG: Repeated time-series plot causes memory leak
1 parent f0ac930 commit e083e01

File tree

5 files changed

+408
-320
lines changed

5 files changed

+408
-320
lines changed

doc/source/whatsnew/v0.16.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Bug Fixes
9696
- Bug in ``scatter_matrix`` draws unexpected axis ticklabels (:issue:`5662`)
9797

9898
- Fixed bug in ``StataWriter`` resulting in changes to input ``DataFrame`` upon save (:issue:`9795`).
99+
- Bug in time-series plot causes memory leak (:issue:`9003`)
99100

100101

101102
- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)

pandas/tests/test_graphics.py

+29
Original file line numberDiff line numberDiff line change
@@ -3366,6 +3366,35 @@ def test_sharey_and_ax(self):
33663366
self.assertTrue(ax.yaxis.get_label().get_visible(),
33673367
"y label is invisible but shouldn't")
33683368

3369+
def test_memory_leak(self):
3370+
""" Check that every plot type gets properly collected. """
3371+
import weakref
3372+
import gc
3373+
3374+
results = {}
3375+
for kind in plotting._plot_klass.keys():
3376+
args = {}
3377+
if kind in ['hexbin', 'scatter', 'pie']:
3378+
df = self.hexbin_df
3379+
args = {'x': 'A', 'y': 'B'}
3380+
elif kind == 'area':
3381+
df = self.tdf.abs()
3382+
else:
3383+
df = self.tdf
3384+
3385+
# Use a weakref so we can see if the object gets collected without
3386+
# also preventing it from being collected
3387+
results[kind] = weakref.proxy(df.plot(kind=kind, **args))
3388+
3389+
# have matplotlib delete all the figures
3390+
tm.close()
3391+
# force a garbage collection
3392+
gc.collect()
3393+
for key in results:
3394+
# check that every plot was collected
3395+
with tm.assertRaises(ReferenceError):
3396+
# need to actually access something to get an error
3397+
results[key].lines
33693398

33703399

33713400
@tm.mplskip

0 commit comments

Comments
 (0)