Skip to content

Commit abe5801

Browse files
committed
BUG: Repeated time-series plot causes memory leak
1 parent 753d66b commit abe5801

File tree

5 files changed

+442
-316
lines changed

5 files changed

+442
-316
lines changed

doc/source/whatsnew/v0.17.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ Bug Fixes
6262

6363
- Bug where read_hdf store.select modifies the passed columns list when
6464
multi-indexed (:issue:`7212`)
65+
6566
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)
6667

6768

6869
- Bug where Panel.from_dict does not set dtype when specified (:issue:`10058`)
70+
71+
6972
- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
7073
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)
7174

@@ -80,6 +83,7 @@ Bug Fixes
8083

8184
- Bug in `Series.plot(label="LABEL")` not correctly setting the label (:issue:`10119`)
8285
- Bug in `plot` not defaulting to matplotlib `axes.grid` setting (:issue:`9792`)
86+
- Bug causes memory leak in time-series line and area plot (:issue:`9003`)
8387

8488

8589
- Bug in GroupBy.get_group raises ValueError when group key contains NaT (:issue:`6992`)

pandas/tests/test_graphics.py

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

3466+
def test_memory_leak(self):
3467+
""" Check that every plot type gets properly collected. """
3468+
import weakref
3469+
import gc
3470+
3471+
results = {}
3472+
for kind in plotting._plot_klass.keys():
3473+
args = {}
3474+
if kind in ['hexbin', 'scatter', 'pie']:
3475+
df = self.hexbin_df
3476+
args = {'x': 'A', 'y': 'B'}
3477+
elif kind == 'area':
3478+
df = self.tdf.abs()
3479+
else:
3480+
df = self.tdf
3481+
3482+
# Use a weakref so we can see if the object gets collected without
3483+
# also preventing it from being collected
3484+
results[kind] = weakref.proxy(df.plot(kind=kind, **args))
3485+
3486+
# have matplotlib delete all the figures
3487+
tm.close()
3488+
# force a garbage collection
3489+
gc.collect()
3490+
for key in results:
3491+
# check that every plot was collected
3492+
with tm.assertRaises(ReferenceError):
3493+
# need to actually access something to get an error
3494+
results[key].lines
34663495

34673496
@slow
34683497
def test_df_grid_settings(self):

0 commit comments

Comments
 (0)