Skip to content

Commit 0301d73

Browse files
authored
Stop swallowing groupby widgets when passing widgets (#346)
* Stop swallowing groupby widgets when passing widgets * Slight test improvement
1 parent b536e1f commit 0301d73

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

hvplot/plotting/core.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ def __call__(self, x=None, y=None, kind=None, **kwds):
4343
kind=kind, type=type(self._data)))
4444

4545
if panel_available:
46-
dynamic , arg_deps, arg_names = process_dynamic_args(x, y, kind, **kwds)
46+
panel_args = ['widgets', 'widget_location', 'widget_layout', 'widget_type']
47+
panel_dict = {}
48+
for k in panel_args:
49+
if k in kwds:
50+
panel_dict[k] = kwds.pop(k)
51+
dynamic, arg_deps, arg_names = process_dynamic_args(x, y, kind, **kwds)
4752
if dynamic or arg_deps:
48-
if kwds.get('groupby', None):
49-
raise ValueError('Groupby is not yet supported when using explicit '
50-
'widgets. Try using the `widgets` kwarg instead')
5153
@pn.depends(*arg_deps, **dynamic)
5254
def callback(*args, **dyn_kwds):
5355
xd = dyn_kwds.pop('x', x)
@@ -60,13 +62,9 @@ def callback(*args, **dyn_kwds):
6062
fn_args[(name, kwds[name])].append(arg)
6163
for (name, fn), args in fn_args.items():
6264
combined_kwds[name] = fn(*args)
63-
return self._get_converter(xd, yd, kindd, **combined_kwds)(kindd, xd, yd)
65+
plot = self._get_converter(xd, yd, kindd, **combined_kwds)(kindd, xd, yd)
66+
return pn.panel(plot, **panel_dict)
6467
return pn.panel(callback)
65-
panel_args = ['widgets', 'widget_location', 'widget_type']
66-
panel_dict = {}
67-
for k in panel_args:
68-
if k in kwds:
69-
panel_dict[k] = kwds.pop(k)
7068
if panel_dict:
7169
plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
7270
return pn.panel(plot, **panel_dict)

hvplot/tests/testpanel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def test_casting_widgets_to_different_classes(self):
5959

6060
assert len(look_for_class(pane, pn.widgets.DiscreteSlider)) == 1
6161

62-
def test_using_explicit_widgets_with_groupby_raises_error(self):
62+
def test_using_explicit_widgets_with_groupby_does_not_raise_error(self):
6363
import panel as pn
6464

6565
x = pn.widgets.Select(name='x', value='sepal_length', options=self.cols)
6666
y = pn.widgets.Select(name='y', value='sepal_width', options=self.cols)
6767

68-
with self.assertRaisesRegex(ValueError, "Groupby is not yet"):
69-
self.flowers.hvplot(x, y, groupby='species')
68+
pane = self.flowers.hvplot(x, y, groupby='species')
69+
assert isinstance(pane, pn.param.ParamFunction)

0 commit comments

Comments
 (0)