Skip to content

Commit

Permalink
Support partial bound function (#6009)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Dec 6, 2023
1 parent 50e51cd commit 91f841e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions holoviews/core/spaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools
import types
from collections import defaultdict
from contextlib import contextmanager
from contextlib import contextmanager, suppress
from functools import partial
from itertools import groupby
from numbers import Number
Expand Down Expand Up @@ -547,7 +547,10 @@ def __call__(self, *args, **kwargs):
kwarg_hash = kwargs.pop('_memoization_hash_', ())
(self.args, self.kwargs) = (args, kwargs)
if hasattr(self.callable, 'rx'):
return self.callable.rx.value
with suppress(TypeError):
# If param.bind is used and not all arguments are set
# it will raise TypeError
return self.callable.rx.value
if not args and not kwargs and not any(kwarg_hash): return self.callable()
inputs = [i for i in self.inputs if isinstance(i, DynamicMap)]
streams = []
Expand Down
20 changes: 20 additions & 0 deletions holoviews/tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import pandas as pd
import param
import pytest
from panel.widgets import IntSlider

import holoviews as hv
from holoviews.core.spaces import DynamicMap
from holoviews.core.util import Version
from holoviews.element import Curve, Histogram, Points, Polygons, Scatter
Expand Down Expand Up @@ -595,6 +597,24 @@ def subscriber_y(**kwargs):
self.assertEqual(values_y, [{}])


@pytest.mark.usefixtures("bokeh_backend")
def test_dynamicmap_partial_bind_and_streams():
# Ref: https://github.com/holoviz/holoviews/issues/6008

def make_plot(z, x_range, y_range):
return Curve([1, 2, 3, 4, z])

slider = IntSlider(name='Slider', start=0, end=10)
range_xy = RangeXY()

dmap = DynamicMap(param.bind(make_plot, z=slider), streams=[range_xy])

bk_figure = hv.render(dmap)

assert bk_figure.renderers[0].data_source.data["y"][-1] == 0
assert range_xy.x_range == (0, 4)
assert range_xy.y_range == (-0.4, 4.4)


class TestSubscribers(ComparisonTestCase):

Expand Down

0 comments on commit 91f841e

Please sign in to comment.