Skip to content

Commit cfb488f

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

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
@@ -103,6 +103,9 @@ Bug Fixes
103103
- Bug in retaining index name on appending (:issue:`9862`)
104104
- Bug in ``scatter_matrix`` draws unexpected axis ticklabels (:issue:`5662`)
105105
- Fixed bug in ``StataWriter`` resulting in changes to input ``DataFrame`` upon save (:issue:`9795`).
106+
107+
- Bug in time-series plot causes memory leak (:issue:`9003`)
108+
106109
- Bug in ``transform`` causing length mismatch when null entries were present and a fast aggregator was being used (:issue:`9697`)
107110
- Bug in ``equals`` causing false negatives when block order differed (:issue:`9330`)
108111
- Bug in ``read_sql_table`` error when reading postgres table with timezone (:issue:`7139`)

pandas/tests/test_graphics.py

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

3392+
def test_memory_leak(self):
3393+
""" Check that every plot type gets properly collected. """
3394+
import weakref
3395+
import gc
3396+
3397+
results = {}
3398+
for kind in plotting._plot_klass.keys():
3399+
args = {}
3400+
if kind in ['hexbin', 'scatter', 'pie']:
3401+
df = self.hexbin_df
3402+
args = {'x': 'A', 'y': 'B'}
3403+
elif kind == 'area':
3404+
df = self.tdf.abs()
3405+
else:
3406+
df = self.tdf
3407+
3408+
# Use a weakref so we can see if the object gets collected without
3409+
# also preventing it from being collected
3410+
results[kind] = weakref.proxy(df.plot(kind=kind, **args))
3411+
3412+
# have matplotlib delete all the figures
3413+
tm.close()
3414+
# force a garbage collection
3415+
gc.collect()
3416+
for key in results:
3417+
# check that every plot was collected
3418+
with tm.assertRaises(ReferenceError):
3419+
# need to actually access something to get an error
3420+
results[key].lines
33923421

33933422

33943423
@tm.mplskip

0 commit comments

Comments
 (0)