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

Skip to content

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

Merged
merged 2 commits into from
Oct 7, 2017

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 6, 2017

PR Summary

Redo of #9281. Making text.draw warn and return instead of raising an exception if x or y 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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

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())
Copy link
Contributor

@anntzer anntzer Oct 6, 2017

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.

Copy link
Member Author

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.

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 "
Copy link
Member

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.

Copy link
Member Author

@jklymak jklymak Oct 6, 2017

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.

Copy link
Member

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).

@tacaswell tacaswell added this to the 2.1.1 (next bug fix release) milestone Oct 6, 2017
@WeatherGod
Copy link
Member

WeatherGod commented Oct 6, 2017 via email

@anntzer
Copy link
Contributor

anntzer commented Oct 6, 2017

@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.
The default log level would be tuned to make such messages visible, and we should make it very easy to switch the logger state at startup (entry in matplotlibrc or environment variable).

@jklymak
Copy link
Member Author

jklymak commented Oct 6, 2017

That’d be cool! I wondered why logger wasn’t being used.

@tacaswell
Copy link
Member

We don't use the std library logging module because we existed before thelogging module and no one has put in the effort to port it :)

@jklymak
Copy link
Member Author

jklymak commented Oct 7, 2017

OK, switched to verbose.report('...', 'helpful').

@tacaswell
Copy link
Member

@jklymak I took the liberty of adding a test.

@jklymak
Copy link
Member Author

jklymak commented Oct 7, 2017

@tacaswell Great! I wasn't quite sure how warning tests were supposed to work anyway, so now I have a good example. Thanks.

@anntzer
Copy link
Contributor

anntzer commented Oct 7, 2017

thanks!

@anntzer anntzer merged commit ad8ef63 into matplotlib:master Oct 7, 2017
lumberbot-app bot pushed a commit that referenced this pull request Oct 7, 2017
@tacaswell
Copy link
Member

oh, I didn't test the warnings, just that it doesn't blow up.

@tacaswell
Copy link
Member

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.

tacaswell added a commit that referenced this pull request Oct 7, 2017
@jklymak jklymak deleted the textcheckpos branch March 5, 2019 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants