-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[WIP] Add check in text for finite values of x and y #9281
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
Add check for finite values of x and y: allow None Add check for finite values of x and y: allow None
@@ -1165,7 +1166,10 @@ def set_x(self, x): | |||
|
|||
ACCEPTS: float | |||
""" | |||
self._x = x | |||
if x is None or np.isfinite(x): |
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.
... do we accept None? what would that even mean? (in any case this is inconsistent with the ACCEPTS: float just above).
I am not convinced that the Text class should catch this case. IMO this is fairly similar to how we allow nans and infs when plotting data, and simply silently ignore such elements. The true issue is with the webagg backend silently dropping draw exceptions. The relevant chunk is in backend_webagg_core, in
We send a draw event, and the draw method raises an exception asynchronously (as can be seen by adding an except clause and printing the exception to a file (stdout is not available because of how jupyter handles things)), but there's no one to actually catch that exception, so it is silently dropped. This should not be the case. OTOH coming back to the proposed fix I have been known to be very much on the "let the user shoot himself in the foot if he wants to" camp :-) and it is true that in this specific case I can't really think of a compelling reason to allow such inputs. |
@anntzer So, first, yeah, WRT this issue. 1) I completely agree that the fundamental problem is that
Given that there are no |
Given the place from where the exception is thrown, it looks totally reasonable (and an improvement) to change the message to something like "Text object position must be finite" (or whatever sounds reasonable to you), because that's exactly what the error is. Actually, if it was really up to me I would just let nonfinite x and y pass through silently... (in any case, I think the behavior you notice is indeed that some cases require delaying the definition of x and y, which means that catching at set_xy time is never going to cover all cases, so again let's just check things where we can actually cover all cases). |
OK, so the plan is to pass any invalid through, and when it comes time to actually render just have it not render because the position is invalid? I'm OK w/ that and it was the behaviour I was expecting when I (accidentally) called |
PR Summary
If we pass non-finite
x
ory
toax.text
the code fails during draw rather than on instantiation orset_x
andset_y
. This just adds anp.isfinite
check tox
andy
and calls the internal method at instantiation.See #9267
PR Checklist