Skip to content

Commit 55a0edb

Browse files
committed
Improved error messages
1 parent a660aa6 commit 55a0edb

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/matplotlib/tests/test_triangulation.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,17 +1124,18 @@ def test_tricontour_non_finite_z():
11241124
triang = mtri.Triangulation(x, y)
11251125
plt.figure()
11261126

1127-
with pytest.raises(ValueError, match='z array cannot contain non-finite ' +
1128-
'values'):
1127+
with pytest.raises(ValueError, match='z array must not contain non-finite '
1128+
'values within the triangulation'):
11291129
plt.tricontourf(triang, [0, 1, 2, np.inf])
11301130

1131-
with pytest.raises(ValueError, match='z array cannot contain non-finite ' +
1132-
'values'):
1131+
with pytest.raises(ValueError, match='z array must not contain non-finite '
1132+
'values within the triangulation'):
11331133
plt.tricontourf(triang, [0, 1, 2, -np.inf])
11341134

1135-
with pytest.raises(ValueError, match='z array cannot contain non-finite ' +
1136-
'values'):
1135+
with pytest.raises(ValueError, match='z array must not contain non-finite '
1136+
'values within the triangulation'):
11371137
plt.tricontourf(triang, [0, 1, 2, np.nan])
11381138

1139-
with pytest.raises(ValueError, match='z cannot be a masked array'):
1139+
with pytest.raises(ValueError, match='z must not contain masked points '
1140+
'within the triangulation'):
11401141
plt.tricontourf(triang, np.ma.array([0, 1, 2, 3], mask=[1, 0, 0, 0]))

lib/matplotlib/tri/tricontour.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ def _contour_args(self, args, kwargs):
8888
# in the triangulation.
8989
z_check = z[np.unique(tri.get_masked_triangles())]
9090
if np.ma.is_masked(z_check):
91-
raise ValueError('z cannot be a masked array')
91+
raise ValueError('z must not contain masked points within the '
92+
'triangulation')
9293
if not np.isfinite(z_check).all():
93-
raise ValueError('z array cannot contain non-finite values')
94+
raise ValueError('z array must not contain non-finite values within'
95+
' the triangulation')
9496

9597
z = np.ma.masked_invalid(z, copy=False)
9698
self.zmax = float(z_check.max())

0 commit comments

Comments
 (0)