Using a string (instead of list) raises misleading AttributeError on hover_cols in hvplot

When specifying hover_cols with a list everything works fine.

import pandas as pd
import numpy as np
import hvplot.pandas

df = pd.DataFrame(index=range(n),data=dict(value=np.random.random(n),tip=np.random.random(n)))


But when I mistakenly added only a single string…


hvplot returns an incomprehensible and misleading AttributeError.

AttributeError                            Traceback (most recent call last)
<ipython-input-42-823a146127eb> in <module>
----> 1 df.hvplot.scatter(y='value',hover_cols='tip')

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\plotting\ in scatter(self, x, y, **kwds)
    189             The HoloViews representation of the plot.
    190         """
--> 191         return self(x, y, kind='scatter', **kwds)
    193     def area(self, x=None, y=None, y2=None, stacked=True, **kwds):

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\plotting\ in __call__(self, x, y, kind, **kwds)
     70                 return pn.panel(plot, **panel_dict)
---> 72         return self._get_converter(x, y, kind, **kwds)(kind, x, y)
     74     def _get_converter(self, x=None, y=None, kind=None, **kwds):

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\ in __call__(self, kind, x, y)
    942                 obj = DynamicMap(cbcallable, streams=[])
    943             else:
--> 944                 obj = method(x, y)
    946         if and self.project:

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\ in scatter(self, x, y, data)
   1236     def scatter(self, x=None, y=None, data=None):
-> 1237         return self.chart(Scatter, x, y, data)
   1239     def area(self, x=None, y=None, data=None):

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\ in chart(self, element, x, y, data)
   1202     def chart(self, element, x, y, data=None):
   1203         "Helper method for simple x vs. y charts"
-> 1204         data, x, y = self._process_chart_args(data, x, y)
   1205         if x and y and not isinstance(y, (list, tuple)):
   1206             return self.single_chart(element, x, y, data)

~\AppData\Local\Continuum\anaconda3\envs\data-37\lib\site-packages\hvplot\ in _process_chart_args(self, data, x, y, single_y)
   1185         # set index to column if needed in hover_cols
-> 1186         if self.use_index and any(c for c in self.hover_cols if
   1187                                   c in self.indexes and
   1188                                   c not in data.columns):

AttributeError: 'HoloViewsConverter' object has no attribute 'hover_cols'

How does hvplot suddenly not recognise hover_cols anymore?

It’s not that hvplot doesn’t recognise hover_cols anymore. It’s that HoloViewsConverter hasn’t hover_cols as an attribute after initialization. When using hvplot an instance of HoloViewsConverter is created but at that time hover_cols is only a parameter and not an attribute.

You can see that the attribute is created here
But it only checks if hover_cols is None, if it’s equal to ‘all’ or if it’s a list. If you pass a string other than ‘all’, the attribute hover_cols won’t be created.

A quick fix would be to add the string case :

elif hover_cols !='all' and isinstance(hover_cols,str):
    self.hover_cols = [hover_cols]
1 Like

Would happily accept a PR to this effect.

Done I’ve created an issue #503 and a PR #504

Hope that will do the job.

1 Like