Skip to content

Setting the plot backend should validate .plot immediately #28163

Closed
@TomAugspurger

Description

@TomAugspurger

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)
<ipython-input-20-848b80e64df8> in <module>
----> 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').

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions