Skip to content

Commit b7ed57e

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

File tree

5 files changed

+431
-314
lines changed

5 files changed

+431
-314
lines changed

doc/source/whatsnew/v0.17.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ Performance Improvements
6060
Bug Fixes
6161
~~~~~~~~~
6262

63+
6364
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)
6465

6566

67+
6668
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
6769
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)
6870

6971

7072

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

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)