Setting the plot backend should validate .plot immediately · Issue #28163 · pandas-dev/pandas (original) (raw)

Right now a pd.set_option('display.backend', name) will

  1. look for an entrypoint
  2. fall back to importing the module name and setting that to the backend

In the second case, the backend's implementation isn't validated until a plot is actually requested. We should validate that name.plot is a thing when the backend is set.

In [16]: module = types.ModuleType("foo")

In [17]: sys.modules['foo'] = module

In [18]: pd.set_option('plotting.backend', 'foo')

In [19]: df = pd.DataFrame({"A": [1, 2]})

In [20]: df.plot()

AttributeError Traceback (most recent call last) in ----> 1 df.plot()

~/sandbox/pandas/pandas/plotting/_core.py in call(self, *args, **kwargs) 794 data.columns = label_name 795 --> 796 return plot_backend.plot(data, kind=kind, **kwargs) 797 798 def line(self, x=None, y=None, **kwargs):

AttributeError: module 'foo' has no attribute 'plot'

Rather than raising an AttributeError on df.plot, we should raise a ValueError on pd.set_option('plotting.backend', 'foo').