Skip to content

Try/except import of Axes3D #27178

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 3 commits into from
Oct 26, 2023
Merged

Try/except import of Axes3D #27178

merged 3 commits into from
Oct 26, 2023

Conversation

ksunden
Copy link
Member

@ksunden ksunden commented Oct 23, 2023

PR summary

On some installs, the mpl_toolkits namespace package gets an old
version which uses deprecated (And removed) code from the main library.

On such the import of Axes3D will error with an ImportError.
This prevents users from using any of matplotlib, since it is imported
unconditionally by default.

This just try/excepts the imports (and adjusts the registration code
accordingly) to allow users to continue using matplotlib (though not 3D
and possibly not other mpl_toolkits) even with older installs occluding
the mpl_toolkits.

Addresses at least the most pressing part of #26827
(Not quite sure we want to close that or not)

PR checklist

On some installs, the `mpl_toolkits` namespace package gets an old
version which uses deprecated (And removed) code from the main library.

On such the import of Axes3D will error with an `ImportError`.
This prevents users from using any of `matplotlib`, since it is imported
unconditionally by default.

This just try/excepts the imports (and adjusts the registration code
accordingly) to allow users to continue using matplotlib (though not 3D
and possibly not other mpl_toolkits) even with older installs occluding
the mpl_toolkits.
@ksunden
Copy link
Member Author

ksunden commented Oct 23, 2023

Do we want to add a warning somewhere in here? (Currently just silently ignores that the import didn't work)

I'm 50/50 on it currently:

There is something wrong with the install, but most users are unlikely to be negatively affected by it, and getting a warning unrelated to what you are doing seems unhelpful.

Perhaps we could put code in the retrieval that looks for the "3d" key and gives a targeted error message rather than just a standard KeyError, such that we tell users what is going on, but only those affected by it? (not sure I like that complexity though...)

@tacaswell tacaswell added this to the v3.8.1 milestone Oct 23, 2023
@tacaswell
Copy link
Member

I think we should warn. I'm inclined to let people know that their installations are messed up (or I may just be cranky today after two h5py issues that boiled down to "broken installation").

@ksunden
Copy link
Member Author

ksunden commented Oct 24, 2023

I did not use ImportWarning, which, while it seems appropriate, is ignored by default and therefore wouldn't actually warn most users.

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic QuLogic merged commit 652d44a into matplotlib:main Oct 26, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Oct 26, 2023
timhoffm added a commit that referenced this pull request Oct 26, 2023
…178-on-v3.8.x

Backport PR #27178 on branch v3.8.x (Try/except import of Axes3D)
ksunden added a commit to ksunden/matplotlib that referenced this pull request Nov 8, 2023
Needed for the same reasons as matplotlib#27178 (Namely that we should not be failing on import just because mpl_toolkits is broken), but mpl 3.6 presents with an AttributeError rather than ImportError

See discussion in matplotlib#26827 and matplotlib#27289

Just expanded liberally in case there are other presentations we have not seen
ksunden added a commit to ksunden/matplotlib that referenced this pull request Nov 8, 2023
Needed for the same reasons as matplotlib#27178 (Namely that we should not be failing on import just because mpl_toolkits is broken), but mpl 3.6 presents with an AttributeError rather than ImportError

See discussion in matplotlib#26827 and matplotlib#27289

Just expanded liberally in case there are other presentations we have not seen
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.

3 participants