-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Use standard property alias machinery in contour(). #30433
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
Conversation
a9055a1
to
6b001dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more internally consistent to let "color" be an alias for "colors" instead of treating it as an error? edgecolor and facecolor are both accepted.
lib/matplotlib/tests/test_contour.py
Outdated
|
||
def test_contour_singular_color(): | ||
with pytest.raises(TypeError): | ||
plt.figure().add_subplot().contour([[0]], color="r") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TypeError is coming from the wrong place, the first argument rather than the second. To fix, use
plt.figure().add_subplot().contour([[0, 1], [2, 3]], color="r")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but it’s typically a good idea to use pytest.raises(…, match=…)
to make the test more specific. This would likely have caught the issue of catching the wrong exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue is rather that contour([[0]]) should raise a ValueError rather than a TypeError (the input has the right type, after all).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that ValueError would be more appropriate. But that doesn’t reduce the value of narrowing down tests via match
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave this one as it's for now, changing pytest.raises to more generally test the error message seems like a good idea but also seems a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Note that 'color(s)' remains special-cased because the ContourSet constructor needs to do a fair bit of special wrangling for it.
I intentionally chose to not support 'color' as alias for 'colors' because 'colors' is actually not a ContourSet property (there's no ContourSet.set_colors, unlike 'edgecolors' and 'facecolors', which are aliases for the respective singular forms). Moreover, whereas ContourSet.set_color (singular) does exist, it doesn't really work -- try e.g. from pylab import *
contourf(np.arange(100).reshape(10, 10), levels=[20, 50, 80]).set_color(["c", "m", "y", "k"]) which leaves the spanned region with the default colors and tries to set colors on the boundaries instead. Turning 'color'/'colors' into a real ContourSet property could be a followup issue, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated test failures? Otherwise, looks OK to me.
Seems unrelated indeed. |
Note that 'color(s)' remains special-cased because the ContourSet constructor needs to do a fair bit of special wrangling for it.
Closes #1963.
PR summary
PR checklist