8000 Fix tests · matplotlib/matplotlib@1782309 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1782309

Browse files
Fix tests
linting
1 parent d18c52b commit 1782309

File tree

4 files changed

+31
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,16 @@ def do_3d_projection(self):
467467
# broadcast mask to 3D
468468
viewlim_mask = viewlim_mask[..., np.newaxis].repeat(3, axis=-1)
469469
mask = mask | viewlim_mask
470-
xyzs = np.ma.array(proj3d._proj_transform_vectors(segments, self.axes.M), mask=mask)
470+
xyzs = np.ma.array(proj3d._proj_transform_vectors(segments, self.axes.M),
471+
mask=mask)
471472
segments_2d = xyzs[..., 0:2]
8000
472473
LineCollection.set_segments(self, segments_2d)
473474

474475
# FIXME
475-
minz = min(xyzs[..., 2].min(), 1e9)
476+
if len(xyzs) > 0:
477+
minz = min(xyzs[..., 2].min(), 1e9)
478+
else:
479+
minz = np.nan
476480
return minz
477481

478482

@@ -872,7 +876,8 @@ def do_3d_projection(self):
872876
mask = mask | xyz.mask
873877
if self._axlim_clip:
874878
mask = mask | _viewlim_mask(*self._offsets3d, self.axes)
875-
mask = np.broadcast_to(mask, (len(self._offsets3d), *self._offsets3d[0].shape))
879+
mask = np.broadcast_to(mask,
880+
(len(self._offsets3d), *self._offsets3d[0].shape))
876881
xyzs = np.ma.array(self._offsets3d, mask=mask)
877882
else:
878883
xyzs = self._offsets3d
@@ -1083,13 +1088,14 @@ def get_vector(self, segments3d):
10831088
return self._get_vector(segments3d)
10841089

10851090
def _get_vector(self, segments3d):
1086-
"""Optimize points for projection.
1091+
"""
1092+
Optimize points for projection.
10871093
10881094
Parameters
10891095
----------
10901096
segments3d : NumPy array or list of NumPy arrays
10911097
List of vertices of the boundary of every segment. If all paths are
1092-
of equal length and this argument is a NumPy arrray, then it should
1098+
of equal length and this argument is a NumPy array, then it should
10931099
be of shape (num_faces, num_vertices, 3).
10941100
"""
10951101
if isinstance(segments3d, np.ndarray):
@@ -1175,8 +1181,7 @@ def do_3d_projection(self):
11751181
if self._edge_is_mapped:
11761182
self._edgecolor3d = self._edgecolors
11771183

1178-
1179-
needs_masking = self._invalid_vertices is not False
1184+
needs_masking = np.any(self._invalid_vertices)
11801185
num_faces = len(self._faces)
11811186
mask = self._invalid_vertices
11821187

@@ -1207,30 +1212,39 @@ def do_3d_projection(self):
12071212
else:
12081213
cedge = cedge.repeat(num_faces, axis=0)
12091214

1210-
face_z = self._zsortfunc(pzs, axis=-1)
1215+
if len(pzs) > 0:
1216+
face_z = self._zsortfunc(pzs, axis=-1)
1217+
else:
1218+
face_z = pzs
12111219
if needs_masking:
12121220
face_z = face_z.data
12131221
face_order = np.argsort(face_z, axis=-1)[::-1]
12141222

1215-
faces_2d = pfaces[face_order, :, :2]
1216-
if self._codes3d is not None:
1223+
if len(pfaces) > 0:
1224+
faces_2d = pfaces[face_order, :, :2]
1225+
else:
1226+
faces_2d = pfaces
1227+
if self._codes3d is not None and len(self._codes3d) > 0:
12171228
if needs_masking:
12181229
segment_mask = ~mask[face_order, :]
12191230
faces_2d = [face[mask, :] for face, mask
12201231
in zip(faces_2d, segment_mask)]
12211232
codes = [self._codes3d[idx] for idx in face_order]
12221233
PolyCollection.set_verts_and_codes(self, faces_2d, codes)
12231234
else:
1224-
if needs_masking:
1235+
if needs_masking and len(faces_2d) > 0:
12251236
invalid_vertices_2d = np.broadcast_to(
12261237
mask[face_order, :, None],
12271238
faces_2d.shape)
12281239
faces_2d = np.ma.MaskedArray(
12291240
faces_2d, mask=invalid_vertices_2d)
12301241
PolyCollection.set_verts(self, faces_2d, self._closed)
12311242

1232-
self._facecolors2d = cface[face_order]
1233-
if len(self._edgecolor3d) == len(cface):
1243+
if len(cface) > 0:
1244+
self._facecolors2d = cface[face_order]
1245+
else:
1246+
self._facecolors2d = cface
1247+
if len(self._edgecolor3d) == len(cface) and len(cedge) > 0:
12341248
self._edgecolors2d = cedge[face_order]
12351249
else:
12361250
self._edgecolors2d = self._edgecolor3d
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def _proj_transform_vec(vec, M):
140140

141141

142142
def _proj_transform_vectors(vecs, M):
143-
"""Vectorized version of ``_proj_transform_vec``.
143+
"""
144+
Vectorized version of ``_proj_transform_vec``.
145+
144146
Parameters
145147
----------
146148
vecs : ... x 3 np.ndarray
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def test_poly3dcollection_verts_validation():
996996
art3d.Poly3DCollection(poly) # should be Poly3DCollection([poly])
997997

998998
poly = np.array(poly, dtype=float)
999-
with pytest.raises(ValueError, match=r'list of \(N, 3\) array-like'):
999+
with pytest.raises(ValueError, match=r'MxNx3 array'):
10001000
art3d.Poly3DCollection(poly) # should be Poly3DCollection([poly])
10011001

10021002