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

Skip to content

Reduce do_3d_projection deprecation warnings in external artists #21741

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
Nov 26, 2021

Conversation

jakelishman
Copy link
Contributor

@jakelishman jakelishman commented Nov 24, 2021

PR Summary

Previously, when finding the 3D zorder, external artists were assumed to
use the calling convention of Patch3D.do_3d_projection from Matplotlib
3.3, where it took a positional renderer parameter. This triggered
a deprecation warning, even if the artist could support the new
convention. Now we attempt to bind the signature first, and only emit a
deprecation warning if the calling convention does not appear to work.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

Fix #21740.

The original logic this modifies was introduced in #18302, where there was a comment that this was deliberately avoiding signature parsing to make things simpler. However, with the new calling convention only being used if the Artist.__module__ is mplot3d-internal, this meant that library code (e.g. Qiskit/qiskit#7301) could not avoid triggering the deprecation warning, even if downstream Artist did actually fulfill the convention. Since the warnings are triggered during the drawing phase, which may well be outside library control, we couldn't suppress the warnings without changing global user filters.

If the performance hit from using signature.bind is too heavy, it could also do

try:
    return artist.do_3d_projection()
except TypeError as exc:
    # - check the exception stack that the issue was the bind, not raised within the function
    # - do the deprecation warning
    return artist.do_3d_projection(renderer)

Previously, when finding the 3D zorder, external artists were assumed to
use the calling convention of `Patch3D.do_3d_projection` from Matplotlib
3.3, where it took a positional `renderer` parameter.  This triggered
a deprecation warning, even if the artist could support the new
convention.  Now we attempt to bind the signature first, and only emit a
deprecation warning if the calling convention does not appear to work.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell tacaswell added this to the v3.5.1 milestone Nov 24, 2021
@tacaswell
Copy link
Member

Thanks for working on this!

This overlaps with #21704 where I took the more direct "try and see if it works" path. @jakelishman Would you be willing to extract the tests from that PR to this one?

I think this PR has a marginally better implementation because it drops the special-case for our internal artists, but we still need to adjust the deprecation version.

@jakelishman
Copy link
Contributor Author

Ah sorry, I missed #21704 when I was searching to see if the issue was already reported. I've incorporated the same sort of tests in 53e124b, including the match argument to pytest.warns that @QuLogic had comment on that PR. I added one for the split mpl 3.3/3.4 convention as well, since as a downstream library we're still looking to support 3.3 at the same time as 3.4 and 3.5.

@QuLogic QuLogic merged commit d2ee3d5 into matplotlib:main Nov 26, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 26, 2021
@QuLogic
Copy link
Member

QuLogic commented Nov 26, 2021

Thanks @jakelishman! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

QuLogic added a commit that referenced this pull request Nov 26, 2021
…741-on-v3.5.x

Backport PR #21741 on branch v3.5.x (Reduce do_3d_projection deprecation warnings in external artists)
@jakelishman jakelishman deleted the fix/do_3d_projection-deprecation branch January 11, 2022 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: unavoidable DeprecationWarning when using Patch3D
3 participants