Skip to content

Commit d2705f6

Browse files
committed
BUG: Repeated time-series plot causes memory leak
1 parent 845cec9 commit d2705f6

File tree

5 files changed

+406
-314
lines changed

5 files changed

+406
-314
lines changed

doc/source/whatsnew/v0.16.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ Bug Fixes
185185
- Bug in retaining index name on appending (:issue:`9862`)
186186
- Bug in ``scatter_matrix`` draws unexpected axis ticklabels (:issue:`5662`)
187187
- Fixed bug in ``StataWriter`` resulting in changes to input ``DataFrame`` upon save (:issue:`9795`).
188+
189+
- Bug in time-series plot causes memory leak (:issue:`9003`)
190+
188191
- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)
189192
- Bug in ``equals`` causing false negatives when block order differed (:issue:`9330`)
190193

pandas/tests/test_graphics.py

+29
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)