Skip to content

Commit cd914aa

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

File tree

5 files changed

+408
-321
lines changed

5 files changed

+408
-321
lines changed

doc/source/whatsnew/v0.16.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Bug Fixes
6666

6767
- Bug in ``scatter_matrix`` draws unexpected axis ticklabels (:issue:`5662`)
6868

69-
69+
- Bug in time-series plot causes memory leak (:issue:`9003`)
7070

7171

7272
- 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
@@ -3354,6 +3354,35 @@ def test_sharey_and_ax(self):
33543354
self.assertTrue(ax.yaxis.get_label().get_visible(),
33553355
"y label is invisible but shouldn't")
33563356

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

33583387

33593388
@tm.mplskip

0 commit comments

Comments
 (0)