Skip to content

Commit df2d07a

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

File tree

5 files changed

+433
-314
lines changed

5 files changed

+433
-314
lines changed

doc/source/whatsnew/v0.17.0.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ Performance Improvements
5858
Bug Fixes
5959
~~~~~~~~~
6060

61+
6162
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)
63+
64+
65+
66+
- Bug in time-series plot causes memory leak (:issue:`9003`)
67+

pandas/tests/test_graphics.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,35 @@ def test_sharey_and_ax(self):
34023402
self.assertTrue(ax.yaxis.get_label().get_visible(),
34033403
"y label is invisible but shouldn't")
34043404

3405+
def test_memory_leak(self):
3406+
""" Check that every plot type gets properly collected. """
3407+
import weakref
3408+
import gc
3409+
3410+
results = {}
3411+
for kind in plotting._plot_klass.keys():
3412+
args = {}
3413+
if kind in ['hexbin', 'scatter', 'pie']:
3414+
df = self.hexbin_df
3415+
args = {'x': 'A', 'y': 'B'}
3416+
elif kind == 'area':
3417+
df = self.tdf.abs()
3418+
else:
3419+
df = self.tdf
3420+
3421+
# Use a weakref so we can see if the object gets collected without
3422+
# also preventing it from being collected
3423+
results[kind] = weakref.proxy(df.plot(kind=kind, **args))
3424+
3425+
# have matplotlib delete all the figures
3426+
tm.close()
3427+
# force a garbage collection
3428+
gc.collect()
3429+
for key in results:
3430+
# check that every plot was collected
3431+
with tm.assertRaises(ReferenceError):
3432+
# need to actually access something to get an error
3433+
results[key].lines
34053434

34063435

34073436
@tm.mplskip

0 commit comments

Comments
 (0)