Skip to content

Commit 48f8cb9

Browse files
authored
Merge pull request #12927 from rth/fix-zip-unpacking
MAINT: Correctly handle empty lists in zip unpacking in mplot3d.art3d
2 parents 4b0196e + 98ebe3d commit 48f8cb9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ def path_to_3d_segment_with_codes(path, zs=0, zdir='z'):
191191
zs = np.broadcast_to(zs, len(path))
192192
pathsegs = path.iter_segments(simplify=False, curves=False)
193193
seg_codes = [((x, y, z), code) for ((x, y), code), z in zip(pathsegs, zs)]
194-
seg, codes = zip(*seg_codes)
195-
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
194+
if seg_codes:
195+
seg, codes = zip(*seg_codes)
196+
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
197+
else:
198+
seg3d = []
199+
codes = []
196200
return seg3d, list(codes)
197201

198202

@@ -204,7 +208,10 @@ def paths_to_3d_segments_with_codes(paths, zs=0, zdir='z'):
204208
zs = np.broadcast_to(zs, len(paths))
205209
segments_codes = [path_to_3d_segment_with_codes(path, pathz, zdir)
206210
for path, pathz in zip(paths, zs)]
207-
segments, codes = zip(*segments_codes)
211+
if segments_codes:
212+
segments, codes = zip(*segments_codes)
213+
else:
214+
segments, codes = [], []
208215
return list(segments), list(codes)
209216

210217

lib/mpl_toolkits/tests/test_mplot3d.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d
44
from matplotlib import cm
55
from matplotlib.testing.decorators import image_comparison, check_figures_equal
6-
from matplotlib.collections import LineCollection
6+
from matplotlib.collections import LineCollection, PolyCollection
77
from matplotlib.patches import Circle
88
import matplotlib.pyplot as plt
99
import numpy as np
@@ -440,6 +440,13 @@ def test_poly3dcollection_closed():
440440
ax.add_collection3d(c2)
441441

442442

443+
def test_poly_collection_2d_to_3d_empty():
444+
poly = PolyCollection([])
445+
art3d.poly_collection_2d_to_3d(poly)
446+
assert isinstance(poly, art3d.Poly3DCollection)
447+
assert poly.get_paths() == []
448+
449+
443450
@image_comparison(baseline_images=['axes3d_labelpad'], extensions=['png'])
444451
def test_axes3d_labelpad():
445452
from matplotlib import rcParams

0 commit comments

Comments
 (0)