8000 Backport PR #21658: Validate that input to Poly3DCollection is a list… · matplotlib/matplotlib@5ccc591 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ccc591

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #21658: Validate that input to Poly3DCollection is a list of 2D array-like
1 parent 9d30a1a commit 5ccc591

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ def __init__(self, verts, *args, zsort='average', **kwargs):
714714
and _edgecolors properties.
715715
"""
716716
super().__init__(verts, *args, **kwargs)
717+
if isinstance(verts, np.ndarray):
718+
if verts.ndim != 3:
719+
raise ValueError('verts must be a list of (N, 3) array-like')
720+
else:
721+
if any(len(np.shape(vert)) != 2 for vert in verts):
722+
raise ValueError('verts must be a list of (N, 3) array-like')
717723
self.set_zsort(zsort)
718724
self._codes3d = None
719725

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,16 @@ def test_patch_collection_modification(fig_test, fig_ref):
704704
ax_ref.add_collection3d(c)
705705

706706

707+
def test_poly3dcollection_verts_validation():
708+
poly = [[0, 0, 1], [0, 1, 1], [0, 1, 0], [0, 0, 0]]
709+
with pytest.raises(ValueError, match=r'list of \(N, 3\) array-like'):
710+
art3d.Poly3DCollection(poly) # should be Poly3DCollection([poly])
711+
712+
poly = np.array(poly, dtype=float)
713+
with pytest.raises(ValueError, match=r'list of \(N, 3\) array-like'):
714+
art3d.Poly3DCollection(poly) # should be Poly3DCollection([poly])
715+
716+
707717
@mpl3d_image_comparison(['poly3dcollection_closed.png'])
708718
def test_poly3dcollection_closed():
709719
fig = plt.figure()

0 commit comments

Comments
 (0)
0