FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: be more careful about not importing pyplot early by tacaswell · Pull Request #17764 · matplotlib/matplotlib · GitHub

Repository navigation

FIX: be more careful about not importing pyplot early - #17764

Merged
anntzer merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_early_use_call
Jun 29, 2020
Merged

anntzer merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_early_use_call

Conversation

Copy link
Copy Markdown
Member

PR Summary

In matplotlib.use we import pyplot to use switch_backend, however
if the user calls mpl.use(...) before importing pyplot then
during the initial import of pyplot, before we set the selected
backend we try to set the backend set via rcParams.

This change only imports pyplot if it is already imported, otherwise
it is safe to just set the rcParams and not go through the full
plt.switch_backend path.

closes #17763

This seems difficult to test given that it is dependent on import order.

PR Checklist

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

tacaswell added this to the v3.3.0 milestone Jun 26, 2020
Comment thread lib/matplotlib/__init__.py Outdated

Copy link
Copy Markdown
Member Author

Both fair points.

tacaswell force-pushed the fix_early_use_call branch from a5a1311 to c9464aa Compare June 28, 2020 02:31
In matplotlib.use we import pyplot to use `switch_backend`, however
if the user calls  `mpl.use(...)` before importing pyplot then
during the initial import of pyplot, before we set the selected
backend we try to set the backend set via rcParams.

This change only imports pyplot if it is already imported, otherwise
it is safe to just set the rcParams and not go through the full
`plt.switch_backend` path.

closes matplotlib#17763
tacaswell force-pushed the fix_early_use_call branch from c9464aa to b94f5c0 Compare June 28, 2020 02:33

Copy link
Copy Markdown
Member Author

The test failure was real, it turns out we were relying on the implicit in use to explode when the user asked for an unusable backend. I solved this by a) changing the backend_fallback rcparam in use (which I think we talked about before, but at least I was not sure about. Coming back to this again with a bit of time it seems clear that this is the correct behavior) b) add a pyplot import in the test to get the exception.

Hopefully the comments are clear?

anntzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

looks reasonable.

anntzer merged commit d2f25c9 into matplotlib:master Jun 29, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jun 29, 2020
timhoffm added a commit that referenced this pull request Jun 29, 2020
…764-on-v3.3.x

Backport PR #17764 on branch v3.3.x (FIX: be more careful about not importing pyplot early)
tacaswell deleted the fix_early_use_call branch July 3, 2020 22:07
tacaswell mentioned this pull request Jul 3, 2020
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

matplotlib.use('agg', force=True) does not ignore unavailable configured backend

3 participants


Back | FazBrowse Home | New Git URL