|
27 | 27 | from numpy.testing import assert_array_equal, assert_allclose
|
28 | 28 | from numpy.testing.decorators import slow
|
29 | 29 | import pandas.tools.plotting as plotting
|
| 30 | +import weakref |
| 31 | +import gc |
30 | 32 |
|
31 | 33 |
|
32 | 34 | def _skip_if_mpl_14_or_dev_boxplot():
|
@@ -3115,6 +3117,33 @@ def _check_errorbar_color(containers, expected, has_err='has_xerr'):
|
3115 | 3117 | self._check_has_errorbars(ax, xerr=0, yerr=1)
|
3116 | 3118 | _check_errorbar_color(ax.containers, 'green', has_err='has_yerr')
|
3117 | 3119 |
|
| 3120 | + def test_memory_leak(self): |
| 3121 | + """ Check that every plot type gets properly collected. """ |
| 3122 | + import matplotlib.pyplot as plt |
| 3123 | + results = {} |
| 3124 | + for kind in plotting._plot_klass.keys(): |
| 3125 | + args = {} |
| 3126 | + if kind in ['hexbin', 'scatter', 'pie']: |
| 3127 | + df = self.hexbin_df |
| 3128 | + args = {'x': 'A', 'y': 'B'} |
| 3129 | + elif kind == 'area': |
| 3130 | + df = self.tdf.abs() |
| 3131 | + else: |
| 3132 | + df = self.tdf |
| 3133 | + |
| 3134 | + # Use a weakref so we can see if the object gets collected without |
| 3135 | + # also preventing it from being collected |
| 3136 | + results[kind] = weakref.proxy(df.plot(kind=kind, **args)) |
| 3137 | + |
| 3138 | + # have matplotlib delete all the figures |
| 3139 | + plt.close('all') |
| 3140 | + # force a garbage collection |
| 3141 | + gc.collect() |
| 3142 | + for key in results: |
| 3143 | + # check that every plot was collected |
| 3144 | + with tm.assertRaises(ReferenceError): |
| 3145 | + # need to actually access something to get an error |
| 3146 | + results[key].lines |
3118 | 3147 |
|
3119 | 3148 | @tm.mplskip
|
3120 | 3149 | class TestDataFrameGroupByPlots(TestPlotBase):
|
|
0 commit comments