-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
In text, warn and return instead of raise exception for non-finite x, y #9295
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
lib/matplotlib/text.py
Outdated
if not np.isfinite(posx) or not np.isfinite(posy): | ||
warnst = "x and y are not finite values for text " | ||
warnst += "string '%s'. Not rendering text." | ||
warnings.warn(warnst%self.get_text()) |
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.
Please use str.format and implicit string concat, something like
warnings.warn("x and y ..."
"...".format(self.get_text()))
Otherwise looks good.
I think I'm neutral on the warning here.
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.
Since it used to throw an exception before, I can't imagine too many people are going to complain if it throws a warning.
lib/matplotlib/text.py
Outdated
posx, posy = trans.transform_point((posx, posy)) | ||
if not np.isfinite(posx) or not np.isfinite(posy): | ||
warnings.warn("x and y are not finite values for text " |
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 am -0.75 on warning. There are legit reasons for intending to be in this state (hence the original issue). We do not want to spam the user with un-suppressible warnings in that case.
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.
Ooops, sorry, commented on this above. This threw an error before, which was presumably far worse than spammy-warnings. But I'm more than happy to take the warning out if you prefer.
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 it is better to let it pass silently (just like we do if you have non-finite numbers in a Line2D
object).
I've been going back-n-forth on this (between issuing a warning and being
silent). On the one hand, I have seen people complain about matplotlib
doing things such as silently allowing a legend to exist outside of a
figure window without saying "boo", but on the other hand, practically
speaking, how would a warning assist with debugging? If we issue a warning,
almost certainly, we should accompany it with some additional information
like the text string and maybe who it's parent is?
…On Fri, Oct 6, 2017 at 5:05 PM, Thomas A Caswell ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/matplotlib/text.py
<#9295 (comment)>
:
> posx, posy = trans.transform_point((posx, posy))
+ if not np.isfinite(posx) or not np.isfinite(posy):
+ warnings.warn("x and y are not finite values for text "
I think it is better to let it pass silently (just like we do if you have
non-finite numbers in a Line2D object).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#9295 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-FCFPorpJ1oLimVttIBkG7aW0CzDks5sppYZgaJpZM4Pw_DH>
.
|
@WeatherGod Perhaps it would be worth relying on the Verbose system (which should really be converted to just use the stdlib logger)? This would seem helpful both here and for the empty legend case. |
That’d be cool! I wondered why logger wasn’t being used. |
We don't use the std library logging module because we existed before the |
…nite x, y - Changed warning to verbose
OK, switched to |
@jklymak I took the liberty of adding a test. |
@tacaswell Great! I wasn't quite sure how warning tests were supposed to work anyway, so now I have a good example. Thanks. |
thanks! |
…n for non-finite x, y
oh, I didn't test the warnings, just that it doesn't blow up. |
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tests/test_font_manager.py#L64 is the pattern to follow to make sure something does/does not generate any warnings. |
Backport PR #9295 on branch v2.1.x
PR Summary
Redo of #9281. Making
text.draw
warn and return instead of raising an exception ifx
ory
are non-finite.Open to removing the warning, but I think it is less mysterious than simply not rendering the text.
Addresses the easy part of #9267
PR Checklist