From 80c6700dd7f0358f171aeafefecbf68a629feaff Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Fri, 20 Sep 2019 12:29:37 +0200 Subject: [PATCH] Ensure that empty Stream source elements get remapped (#3978) --- holoviews/streams.py | 4 +++- holoviews/tests/teststreams.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/holoviews/streams.py b/holoviews/streams.py index 24d8a64c14..39b2996916 100644 --- a/holoviews/streams.py +++ b/holoviews/streams.py @@ -338,10 +338,12 @@ def source(self): @source.setter def source(self, source): - if self.source: + if self.source is not None: source_list = self.registry[self.source] if self in source_list: source_list.remove(self) + if not source_list: + self.registry.pop(self.source) if source is None: self._source = None diff --git a/holoviews/tests/teststreams.py b/holoviews/tests/teststreams.py index 3107f985ae..113af287a7 100644 --- a/holoviews/tests/teststreams.py +++ b/holoviews/tests/teststreams.py @@ -627,6 +627,15 @@ def test_source_empty_element(self): stream = PointerX(source=points) self.assertIs(stream.source, points) + def test_source_empty_element_remap(self): + points = Points([]) + stream = PointerX(source=points) + self.assertIs(stream.source, points) + curve = Curve([]) + stream.source = curve + self.assertNotIn(points, Stream.registry) + self.assertIn(curve, Stream.registry) + def test_source_empty_dmap(self): points_dmap = DynamicMap(lambda x: Points([]), kdims=['X']) stream = PointerX(source=points_dmap)