Skip to content
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

Matplotlib 3.8 test warning #2277

Merged
merged 2 commits into from
Oct 20, 2023
Merged

Matplotlib 3.8 test warning #2277

merged 2 commits into from
Oct 20, 2023

Conversation

lgolston
Copy link
Contributor

Rationale

tests\mpl\conftest.py gives the following warning: "MatplotlibDeprecationWarning: Auto-close()ing of figures upon backend switching is deprecated since 3.8 and will be removed two minor releases later. To suppress this warning, explicitly call plt.close('all') first."

Implications

The warning is addressed.

@rcomer
Copy link
Member

rcomer commented Oct 19, 2023

This is probably a naive question, but: why do we switch backends individually for each test, rather than setting to agg once globally?

@lgolston
Copy link
Contributor Author

lgolston commented Oct 19, 2023

This is probably a naive question, but: why do we switch backends individually for each test, rather than setting to agg once globally?

That is a good question. I just wanted to quiet the warning (which is repeated for every mpl test), but looking at the backend setting and switching now in the tests I do wonder whether what is really necessary. Especially, tests/mpl/__init__.py which switches to tkagg and back.

@greglucas
Copy link
Contributor

I think the backend switch every time is there to guard against a test that may choose to use a different backend so then you don't get that leaking out into subsequent tests.

That tests.mpl.show function seems like it could be removed... It is not used anywhere other than in commented-out code that looks more like it is for debugging what was going on previously. That can be a follow-up PR to clean that portion up though.

@@ -15,6 +15,7 @@ def mpl_test_cleanup(request):
with ExitStack() as stack:
# At exit, close all open figures and switch backend back to original.
stack.callback(plt.switch_backend, plt.get_backend())
stack.callback(plt.close, 'all')
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it matter whether we close all before or after the switch backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if line 17 and 18 are swapped the warning is still given. Since the stack goes in reverse order, I think the flow is that on exit the plot is closed, then backend is switched to original.

@QuLogic QuLogic added this to the Next Release milestone Oct 20, 2023
@QuLogic QuLogic merged commit 74e0210 into SciTools:main Oct 20, 2023
22 checks passed
@lgolston lgolston deleted the warning-mpl8 branch October 23, 2023 02:36
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.

None yet

4 participants