Skip to content

Commit 35152b1

Browse files
committed
Avoid gc in test_memory_leak
1 parent 3a331eb commit 35152b1

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pandas/tests/plotting/frame/test_frame.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
date,
55
datetime,
66
)
7-
import gc
87
import itertools
98
import re
109
import string
11-
import weakref
1210

1311
import numpy as np
1412
import pytest
@@ -2164,15 +2162,14 @@ def test_memory_leak(self, kind):
21642162
index=date_range("2000-01-01", periods=10, freq="B"),
21652163
)
21662164

2167-
# Use a weakref so we can see if the object gets collected without
2168-
# also preventing it from being collected
2169-
ref = weakref.ref(df.plot(kind=kind, **args))
2170-
2171-
# have matplotlib delete all the figures
2172-
plt.close("all")
2173-
# force a garbage collection
2174-
gc.collect()
2175-
assert ref() is None
2165+
ax = df.plot(kind=kind, **args)
2166+
if kind in ["line", "area"]:
2167+
for i, (cached_data, _, _) in enumerate(ax._plot_data):
2168+
ser = df.iloc[:, i]
2169+
assert not tm.shares_memory(ser, cached_data)
2170+
tm.assert_numpy_array_equal(ser._values, cached_data._values)
2171+
else:
2172+
assert not hasattr(ax, "_plot_data")
21762173

21772174
def test_df_gridspec_patterns_vert_horiz(self):
21782175
# GH 10819

0 commit comments

Comments
 (0)