Skip to content

Commit

Permalink
Merge pull request pandas-dev#9814 from sinhrks/tsplot_df
Browse files Browse the repository at this point in the history
BUG: Repeated time-series plot causes memory leak
  • Loading branch information
sinhrks committed Jul 29, 2015
2 parents d197833 + 976a045 commit 92da9ed
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 317 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Expand Up @@ -408,7 +408,7 @@ Bug Fixes
- Bug in ``Series.plot(kind='hist')`` Y Label not informative (:issue:`10485`)
- Bug in ``read_csv`` when using a converter which generates a ``uint8`` type (:issue:`9266`)


- Bug causes memory leak in time-series line and area plot (:issue:`9003`)


- Bug in line and kde plot cannot accept multiple colors when ``subplots=True`` (:issue:`9894`)
Expand Down
30 changes: 30 additions & 0 deletions pandas/tests/test_graphics.py
Expand Up @@ -3281,6 +3281,36 @@ def test_sharey_and_ax(self):
self.assertTrue(ax.yaxis.get_label().get_visible(),
"y label is invisible but shouldn't")

def test_memory_leak(self):
""" Check that every plot type gets properly collected. """
import weakref
import gc

results = {}
for kind in plotting._plot_klass.keys():
args = {}
if kind in ['hexbin', 'scatter', 'pie']:
df = self.hexbin_df
args = {'x': 'A', 'y': 'B'}
elif kind == 'area':
df = self.tdf.abs()
else:
df = self.tdf

# Use a weakref so we can see if the object gets collected without
# also preventing it from being collected
results[kind] = weakref.proxy(df.plot(kind=kind, **args))

# have matplotlib delete all the figures
tm.close()
# force a garbage collection
gc.collect()
for key in results:
# check that every plot was collected
with tm.assertRaises(ReferenceError):
# need to actually access something to get an error
results[key].lines

@slow
def test_df_grid_settings(self):
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
Expand Down

0 comments on commit 92da9ed

Please sign in to comment.