holoviz / holoviz/hvplot

hvPlot for derived classes

Open
#509 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

For hvplot=0.6.0, I expected to be able to use .hvplot on both library-provided classes and on user-derived classes. For instance, I expected to be able to define my own subclass of an xr.DataArray, streamz.dataframe.Dataframe, or pd.DataFrame class, and to use .hvplot() on those objects the same as on the superclass objects as long as I didn't do anything crazy in the subclass.

For a no-op derived class (just "pass"), it seems to work fine for pd.DataFrame:

![image](https://user-images.githubusercontent.com/1695496/93641745-6adc1000-f9c2-11ea-860b-973f3b91168b.png)

But it doesn't work for the other two types:

![image](https://user-images.githubusercontent.com/1695496/93641842-9d860880-f9c2-11ea-9b65-d8e8b6676310.png)
![image](https://user-images.githubusercontent.com/1695496/93642240-58aea180-f9c3-11ea-8a36-9c2865ff2a0a.png)

```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
2 pass
3
----> 4 MyDataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]}, name="rand").hvplot()

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/plotting/core.py in __call__(self, x, y, kind, **kwds)
70 return pn.panel(plot, **panel_dict)
71
---> 72 return self._get_converter(x, y, kind, **kwds)(kind, x, y)
73
74 def _get_converter(self, x=None, y=None, kind=None, **kwds):

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/plotting/core.py in _get_converter(self, x, y, kind, **kwds)
78 kind = kind or params.pop('kind', None)
79 return HoloViewsConverter(
---> 80 self._data, x, y, kind=kind, **params
81 )
82

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/converter.py in __init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, figsize, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, **kwds)
322 self._process_data(kind, data, x, y, by, groupby, row, col,
323 use_dask, persist, backlog, label, value_label,
--> 324 hover_cols, attr_labels, kwds)
325
326 self.dynamic = dynamic

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/converter.py in _process_data(self, kind, data, x, y, by, groupby, row, col, use_dask, persist, backlog, label, value_label, hover_cols, attr_labels, kwds)
657 self.data = data
658 else:
--> 659 raise ValueError('Supplied data type %s not understood' % type(data).__name__)
660
661 # Validate data and arguments

ValueError: Supplied data type MyDataArray not understood
```

![image](https://user-images.githubusercontent.com/1695496/93642081-0ff6e880-f9c3-11ea-9104-500f8517fb8b.png)
![image](https://user-images.githubusercontent.com/1695496/93642284-724fe900-f9c3-11ea-9853-dd79630bc859.png)

```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
2 pass
3
----> 4 MyRandom(interval='200ms', freq='50ms').hvplot()

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/plotting/core.py in __call__(self, x, y, kind, **kwds)
70 return pn.panel(plot, **panel_dict)
71
---> 72 return self._get_converter(x, y, kind, **kwds)(kind, x, y)
73
74 def _get_converter(self, x=None, y=None, kind=None, **kwds):

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/plotting/core.py in _get_converter(self, x, y, kind, **kwds)
78 kind = kind or params.pop('kind', None)
79 return HoloViewsConverter(
---> 80 self._data, x, y, kind=kind, **params
81 )
82

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/converter.py in __init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, figsize, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, **kwds)
322 self._process_data(kind, data, x, y, by, groupby, row, col,
323 use_dask, persist, backlog, label, value_label,
--> 324 hover_cols, attr_labels, kwds)
325
326 self.dynamic = dynamic

~/miniconda3/envs/holoviz-tutorial/lib/python3.7/site-packages/hvplot/converter.py in _process_data(self, kind, data, x, y, by, groupby, row, col, use_dask, persist, backlog, label, value_label, hover_cols, attr_labels, kwds)
657 self.data = data
658 else:
--> 659 raise ValueError('Supplied data type %s not understood' % type(data).__name__)
660
661 # Validate data and arguments

ValueError: Supplied data type MyRandom not understood
```

My guess is that it's because this code in [hvplot/util.py](https://github.com/holoviz/hvplot/blob/master/hvplot/util.py#L229) is only checking by the source module, not isinstance:
```
def check_library(obj, library):
if not isinstance(library, list):
library = [library]
return any([obj.__module__.split('.')[0].startswith(l) for l in library])
```
But if so I don't have any explanation for why classes derived from pd.DataFrame seem to work, given that _all_ the classes defined above should be in module `__main__`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.