10000 MAINT: Correctly handle empty lists in zip unpacking in mplot3d.art3d by rth · Pull Request #12927 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Correctly handle empty lists in zip unpacking in mplot3d.art3d #12927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ def path_to_3d_segment_with_codes(path, zs=0, zdir='z'):
zs = np.broadcast_to(zs, len(path))
pathsegs = path.iter_segments(simplify=False, curves=False)
seg_codes = [((x, y, z), code) for ((x, y), code), z in zip(pathsegs, zs)]
seg, codes = zip(*seg_codes)
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
if seg_codes:
seg, codes = zip(*seg_codes)
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg]
else:
seg3d = []
codes = []
return seg3d, list(codes)


Expand All @@ -204,7 +208,10 @@ def paths_to_3d_segments_with_codes(paths, zs=0, zdir='z'):
zs = np.broadcast_to(zs, len(paths))
segments_codes = [path_to_3d_segment_with_codes(path, pathz, zdir)
for path, pathz in zip(paths, zs)]
segments, codes = zip(*segments_codes)
if segments_codes:
segments, codes = zip(*segments_codes)
else:
segments, codes = [], []
return list(segments), list(codes)


Expand Down
9 changes: 8 additions & 1 deletion lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d
from matplotlib import cm
from matplotlib.testing.decorators import image_comparison, check_figures_equal
from matplotlib.collections import LineCollection
from matplotlib.collections import LineCollection, PolyCollection
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -440,6 +440,13 @@ def test_poly3dcollection_closed():
ax.add_collection3d(c2)


def test_poly_collection_2d_to_3d_empty():
poly = PolyCollection([])
art3d.poly_collection_2d_to_3d(poly)
assert isinstance(poly, art3d.Poly3DCollection)
assert poly.get_paths() == []


@image_comparison(baseline_images=['axes3d_labelpad'], extensions=['png'])
def test_axes3d_labelpad():
from matplotlib import rcParams
Expand Down
0