-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Allow plotting backend option context without matplotlib #27517
Comments
@TomAugspurger, if I understand you correctly, you mean, make default backend |
I'm not sure. That may be my first approach. We may need to have a larger discussion around when backends are loaded / validated. Right now it's when used ( |
I think what we do now, load the backend when the option is set is the best option. If users make a typo in the name of the backend, I don't want to raise an exception at a later time, when they run a proper call to In this case, the problem seems to be something else. You're setting the backend to |
Here's a better example import sys
import types
import pandas as pd
foo = types.ModuleType('foo')
foo.plot = lambda *args, **kwargs: None
sys.modules['foo'] = foo
with pd.option_context('plotting.backend', 'foo'):
pass which raises with the following with no mpl: Traceback (most recent call last):
File "/Users/taugspurger/sandbox/pandas/pandas/core/config_init.py", line 594, in register_plotting_backend_cb
import pandas.plotting._matplotlib # noqa
File "/Users/taugspurger/sandbox/pandas/pandas/plotting/_matplotlib/__init__.py", line 3, in <module>
from pandas.plotting._matplotlib.boxplot import (
File "/Users/taugspurger/sandbox/pandas/pandas/plotting/_matplotlib/boxplot.py", line 4, in <module>
from matplotlib.artist import setp
ModuleNotFoundError: No module named 'matplotlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tmp.py", line 11, in <module>
pass
File "/Users/taugspurger/sandbox/pandas/pandas/_config/config.py", line 412, in __exit__
_set_option(pat, val, silent=True)
File "/Users/taugspurger/sandbox/pandas/pandas/_config/config.py", line 136, in _set_option
o.cb(key)
File "/Users/taugspurger/sandbox/pandas/pandas/core/config_init.py", line 597, in register_plotting_backend_cb
"matplotlib is required for plotting when the "
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected. That's inside the context managers |
Ah, thanks for clarifying, I think I understand now. I think my preferred option is to not import the backend if it's I think the only thing that may be somehow inconsistent, is that if the backend is set to the default value Does it make sense to you? |
Indeed, the first example now raises
while the second runs without raising any exception. I guess this issue can be closed. |
There's a comment in test_register_entrypoint
Since this is closed, does that mean we can remove that decoration? |
and cleanup tests eg pandas-dev#27517
and cleanup tests eg pandas-dev#27517
and cleanup tests eg pandas-dev#27517
Right now, using
pd.option_context
to set the backend fails on__exit__
when matplotlib isn't installed.I don't believe that should raise an error. We may need to make the default option
None
, and then resole that to matplotlib later on.The text was updated successfully, but these errors were encountered: