Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e142894

Browse files
authored
Merge pull request #22883 from anntzer/tca
Tweak argument checking in tripcolor().
2 parents e077394 + 7db1913 commit e142894

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Passing too many positional arguments to ``tripcolor``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is now deprecated (extra arguments were previously silently ignored).

lib/matplotlib/tests/test_triangulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_tripcolor_color():
242242
x = [-1, 0, 1, 0]
243243
y = [0, -1, 0, 1]
244244
fig, ax = plt.subplots()
245-
with pytest.raises(ValueError, match="Missing color parameter"):
245+
with pytest.raises(TypeError, match=r"tripcolor\(\) missing 1 required "):
246246
ax.tripcolor(x, y)
247247
with pytest.raises(ValueError, match="The length of C must match either"):
248248
ax.tripcolor(x, y, [1, 2, 3])
@@ -255,8 +255,8 @@ def test_tripcolor_color():
255255
with pytest.raises(ValueError,
256256
match="'gouraud' .* at the points.* not at the faces"):
257257
ax.tripcolor(x, y, [1, 2], shading='gouraud') # faces
258-
with pytest.raises(ValueError,
259-
match=r"pass C positionally or facecolors via keyword"):
258+
with pytest.raises(TypeError,
259+
match="positional.*'C'.*keyword-only.*'facecolors'"):
260260
ax.tripcolor(x, y, C=[1, 2, 3, 4])
261261

262262
# smoke test for valid color specifications (via C or facecolors)
@@ -282,7 +282,7 @@ def test_tripcolor_warnings():
282282
C = [0.4, 0.5]
283283
fig, ax = plt.subplots()
284284
# additional parameters
285-
with pytest.warns(UserWarning, match="Additional positional parameters"):
285+
with pytest.warns(DeprecationWarning, match="Additional positional param"):
286286
ax.tripcolor(x, y, C, 'unused_positional')
287287
# facecolors takes precednced over C
288288
with pytest.warns(UserWarning, match="Positional parameter C .*no effect"):

lib/matplotlib/tri/tripcolor.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None,
7979
else:
8080
# Color from positional parameter C
8181
if not args:
82-
raise ValueError(
83-
"Missing color parameter. Please pass C positionally or "
84-
"facecolors via keyword")
82+
raise TypeError(
83+
"tripcolor() missing 1 required positional argument: 'C'; or "
84+
"1 required keyword-only argument: 'facecolors'")
8585
elif len(args) > 1:
86-
_api.warn_external(
87-
"Additional positional parameters {args[1:]!r} are ignored")
86+
_api.warn_deprecated(
87+
"3.6", message=f"Additional positional parameters "
88+
f"{args[1:]!r} are ignored; support for them is deprecated "
89+
f"since %(since)s and will be removed %(removal)s")
8890
C = np.asarray(args[0])
8991
if len(C) == len(tri.x):
9092
# having this before the len(tri.triangles) comparison gives

0 commit comments

Comments
 (0)