Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d0a3d3

Browse files
committed
MNT: Remove unused pickling debug code.
This was deflating our coverage numbers for the tests. If deemed necessary, this code should be resurrected elsewhere (outside tests). Also cleaned up the code a bit.
1 parent ae2381c commit 7d0a3d3

File tree

1 file changed

+5
-92
lines changed

1 file changed

+5
-92
lines changed

lib/matplotlib/tests/test_pickle.py

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import six
54
from six.moves import cPickle as pickle
65
from six.moves import range
76

@@ -15,88 +14,8 @@
1514
import matplotlib.transforms as mtransforms
1615

1716

18-
def depth_getter(obj,
19-
current_depth=0,
20-
depth_stack=None,
21-
nest_info='top level object'):
22-
"""
23-
Returns a dictionary mapping:
24-
25-
id(obj): (shallowest_depth, obj, nest_info)
26-
27-
for the given object (and its subordinates).
28-
29-
This, in conjunction with recursive_pickle, can be used to debug
30-
pickling issues, although finding others is sometimes a case of
31-
trial and error.
32-
33-
"""
34-
if depth_stack is None:
35-
depth_stack = {}
36-
37-
if id(obj) in depth_stack:
38-
stack = depth_stack[id(obj)]
39-
if stack[0] > current_depth:
40-
del depth_stack[id(obj)]
41-
else:
42-
return depth_stack
43-
44-
depth_stack[id(obj)] = (current_depth, obj, nest_info)
45-
46-
if isinstance(obj, (list, tuple)):
47-
for i, item in enumerate(obj):
48-
depth_getter(item, current_depth=current_depth + 1,
49-
depth_stack=depth_stack,
50-
nest_info=('list/tuple item #%s in '
51-
'(%s)' % (i, nest_info)))
52-
else:
53-
if isinstance(obj, dict):
54-
state = obj
55-
elif hasattr(obj, '__getstate__'):
56-
state = obj.__getstate__()
57-
if not isinstance(state, dict):
58-
state = {}
59-
elif hasattr(obj, '__dict__'):
60-
state = obj.__dict__
61-
else:
62-
state = {}
63-
64-
for key, value in six.iteritems(state):
65-
depth_getter(value, current_depth=current_depth + 1,
66-
depth_stack=depth_stack,
67-
nest_info=('attribute "%s" in '
68-
'(%s)' % (key, nest_info)))
69-
70-
return depth_stack
71-
72-
73-
def recursive_pickle(top_obj):
74-
"""
75-
Recursively pickle all of the given objects subordinates, starting with
76-
the deepest first. **Very** handy for debugging pickling issues, but
77-
also very slow (as it literally pickles each object in turn).
78-
79-
Handles circular object references gracefully.
80-
81-
"""
82-
objs = depth_getter(top_obj)
83-
# sort by depth then by nest_info
84-
objs = sorted(six.itervalues(objs), key=lambda val: (-val[0], val[2]))
85-
86-
for _, obj, location in objs:
87-
try:
88-
pickle.dump(obj, BytesIO(), pickle.HIGHEST_PROTOCOL)
89-
except Exception as err:
90-
print(obj)
91-
print('Failed to pickle %s. \n Type: %s. Traceback '
92-
'follows:' % (location, type(obj)))
93-
raise
94-
95-
9617
def test_simple():
9718
fig = plt.figure()
98-
# un-comment to debug
99-
# recursive_pickle(fig)
10019
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)
10120

10221
ax = plt.subplot(121)
@@ -106,13 +25,9 @@ def test_simple():
10625
plt.plot(np.arange(10), label='foobar')
10726
plt.legend()
10827

109-
# Uncomment to debug any unpicklable objects. This is slow so is not
110-
# uncommented by default.
111-
# recursive_pickle(fig)
11228
pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
11329

11430
# ax = plt.subplot(121, projection='hammer')
115-
# recursive_pickle(ax, 'figure')
11631
# pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
11732

11833
plt.figure()
@@ -138,8 +53,9 @@ def test_complete():
13853
data = u = v = np.linspace(0, 10, 80).reshape(10, 8)
13954
v = np.sin(v * -0.6)
14055

56+
# Ensure lists also pickle correctly.
14157
plt.subplot(3, 3, 1)
142-
plt.plot(list(range(10))) # Ensure lists also pickle correctly.
58+
plt.plot(list(range(10)))
14359

14460
plt.subplot(3, 3, 2)
14561
plt.contourf(data, hatches=['//', 'ooo'])
@@ -171,11 +87,9 @@ def test_complete():
17187
plt.subplot(3, 3, 9)
17288
plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4)
17389

174-
###### plotting is done, now test its pickle-ability #########
175-
176-
# Uncomment to debug any unpicklable objects. This is slow (~200 seconds).
177-
# recursive_pickle(fig)
178-
90+
#
91+
# plotting is done, now test its pickle-ability
92+
#
17993
result_fh = BytesIO()
18094
pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL)
18195

@@ -227,7 +141,6 @@ def test_image():
227141
def test_polar():
228142
ax = plt.subplot(111, polar=True)
229143
fig = plt.gcf()
230-
result = BytesIO()
231144
pf = pickle.dumps(fig)
232145
pickle.loads(pf)
233146
plt.draw()

0 commit comments

Comments
 (0)