Skip to content

Commit

Permalink
Enhancements for interactive API (#640)
Browse files Browse the repository at this point in the history
* Set max_rows for interactive DataFrame

* Allow column access on interactive DataFrames

* Add error for interactive on DataArray without name
  • Loading branch information
philippjfr authored Jul 11, 2021
1 parent 60d5195 commit a32da7a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hvplot/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys

import holoviews as hv
import pandas as pd
import panel as pn
import param

Expand Down Expand Up @@ -52,7 +53,7 @@ class Interactive():

def __init__(self, obj, transform=None, plot=False, depth=0,
loc='top_left', center=False, dmap=False, inherit_kwargs={},
**kwargs):
max_rows=100, **kwargs):
self._init = False
self._obj = obj
self._method = None
Expand All @@ -63,6 +64,11 @@ def __init__(self, obj, transform=None, plot=False, depth=0,
transform = hv.util.transform.xr_dim
if is_xarray_dataarray(obj):
dim = obj.name
if dim is None:
raise ValueError(
"Cannot use interactive API on DataArray without name."
"Assign a name to the DataArray and try again."
)
elif is_tabular(obj):
transform = hv.util.transform.df_dim
self._transform = transform(dim)
Expand All @@ -74,6 +80,7 @@ def __init__(self, obj, transform=None, plot=False, depth=0,
self._center = center
self._dmap = dmap
self._inherit_kwargs = inherit_kwargs
self._max_rows = max_rows
self._kwargs = kwargs
ds = hv.Dataset(self._obj)
self._current = self._transform.apply(ds, keep_index=True, compute=False)
Expand All @@ -93,6 +100,8 @@ def evaluate(*args, **kwargs):
obj = getattr(obj, self._method, obj)
if self._plot:
return Interactive._fig
elif isinstance(obj, pd.DataFrame):
return pn.pane.DataFrame(obj, max_rows=self._max_rows)
else:
return obj
return evaluate
Expand All @@ -117,6 +126,8 @@ def __dir__(self):
if self._method:
current = getattr(current, self._method)
extras = {attr for attr in dir(current) if not attr.startswith('_')}
if is_tabular(currrent) and hasattr(current, 'columns'):
extras |= set(current.columns)
try:
return sorted(set(super(Interactive, self).__dir__()) | extras)
except Exception:
Expand Down

0 comments on commit a32da7a

Please sign in to comment.