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

Skip to content

Tweak argument checking in tripcolor(). #22883

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 1 commit into from
Apr 24, 2022
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
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/deprecations/22883-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Passing too many positional arguments to ``tripcolor``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... is now deprecated (extra arguments were previously silently ignored).
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_tripcolor_color():
x = [-1, 0, 1, 0]
y = [0, -1, 0, 1]
fig, ax = plt.subplots()
with pytest.raises(ValueError, match="Missing color parameter"):
with pytest.raises(TypeError, match=r"tripcolor\(\) missing 1 required "):
ax.tripcolor(x, y)
with pytest.raises(ValueError, match="The length of C must match either"):
ax.tripcolor(x, y, [1, 2, 3])
Expand All @@ -255,8 +255,8 @@ def test_tripcolor_color():
with pytest.raises(ValueError,
match="'gouraud' .* at the points.* not at the faces"):
ax.tripcolor(x, y, [1, 2], shading='gouraud') # faces
with pytest.raises(ValueError,
match=r"pass C positionally or facecolors via keyword"):
with pytest.raises(TypeError,
match="positional.*'C'.*keyword-only.*'facecolors'"):
ax.tripcolor(x, y, C=[1, 2, 3, 4])

# smoke test for valid color specifications (via C or facecolors)
Expand All @@ -282,7 +282,7 @@ def test_tripcolor_warnings():
C = [0.4, 0.5]
fig, ax = plt.subplots()
# additional parameters
with pytest.warns(UserWarning, match="Additional positional parameters"):
with pytest.warns(DeprecationWarning, match="Additional positional param"):
ax.tripcolor(x, y, C, 'unused_positional')
# facecolors takes precednced over C
with pytest.warns(UserWarning, match="Positional parameter C .*no effect"):
Expand Down
12 changes: 7 additions & 5 deletions lib/matplotlib/tri/tripcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None,
else:
# Color from positional parameter C
if not args:
raise ValueError(
"Missing color parameter. Please pass C positionally or "
"facecolors via keyword")
raise TypeError(
"tripcolor() missing 1 required positional argument: 'C'; or "
"1 required keyword-only argument: 'facecolors'")
elif len(args) > 1:
_api.warn_external(
"Additional positional parameters {args[1:]!r} are ignored")
_api.warn_deprecated(
"3.6", message=f"Additional positional parameters "
f"{args[1:]!r} are ignored; support for them is deprecated "
f"since %(since)s and will be removed %(removal)s")
C = np.asarray(args[0])
if len(C) == len(tri.x):
# having this before the len(tri.triangles) comparison gives
Expand Down