-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensured dynamic callback is only called once #923
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
Tests of plot instantiation (not display tests, just instantiation) | ||
""" | ||
|
||
from collections import deque | ||
from unittest import SkipTest | ||
from io import BytesIO | ||
|
||
|
@@ -12,7 +13,7 @@ | |
HeatMap, QuadMesh, Spikes, ErrorBars, | ||
Scatter3D) | ||
from holoviews.element.comparison import ComparisonTestCase | ||
from holoviews.streams import PositionXY | ||
from holoviews.streams import PositionXY, PositionX | ||
from holoviews.plotting import comms | ||
|
||
# Standardize backend due to random inconsistencies | ||
|
@@ -46,11 +47,11 @@ def setUp(self): | |
Store.current_backend = 'matplotlib' | ||
if mpl_renderer is None: | ||
raise SkipTest("Matplotlib required to test plot instantiation") | ||
self.default_comm, _ = mpl_renderer.comms['default'] | ||
self.default_comm = mpl_renderer.comms['default'] | ||
mpl_renderer.comms['default'] = (comms.Comm, '') | ||
|
||
def teardown(self): | ||
mpl_renderer.comms['default'] = (self.default_comm, '') | ||
mpl_renderer.comms['default'] = self.default_comm | ||
Store.current_backend = self.previous_backend | ||
|
||
def test_interleaved_overlay(self): | ||
|
@@ -87,6 +88,19 @@ def test_errorbar_test(self): | |
plot = mpl_renderer.get_plot(errorbars) | ||
plot.initialize_plot() | ||
|
||
def test_stream_callback_single_call(self): | ||
def history_callback(x, history=deque(maxlen=10)): | ||
history.append(x) | ||
return Curve(list(history)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like the price stream example notebook in contrib! |
||
stream = PositionX() | ||
dmap = DynamicMap(history_callback, kdims=[], streams=[stream]) | ||
plot = mpl_renderer.get_plot(dmap) | ||
mpl_renderer(plot) | ||
for i in range(20): | ||
stream.update(x=i) | ||
x, y = plot.handles['artist'].get_data() | ||
self.assertEqual(x, np.arange(10)) | ||
self.assertEqual(y, np.arange(10, 20)) | ||
|
||
|
||
class TestBokehPlotInstantiation(ComparisonTestCase): | ||
|
@@ -97,13 +111,13 @@ def setUp(self): | |
raise SkipTest("Bokeh required to test plot instantiation") | ||
Store.current_backend = 'bokeh' | ||
Callback._comm_type = comms.Comm | ||
self.default_comm, _ = bokeh_renderer.comms['default'] | ||
self.default_comm = bokeh_renderer.comms['default'] | ||
bokeh_renderer.comms['default'] = (comms.Comm, '') | ||
|
||
def teardown(self): | ||
Store.current_backend = self.previous_backend | ||
Callback._comm_type = comms.JupyterCommJS | ||
mpl_renderer.comms['default'] = (self.default_comm, '') | ||
mpl_renderer.comms['default'] = self.default_comm | ||
|
||
def test_batched_plot(self): | ||
overlay = NdOverlay({i: Points(np.arange(i)) for i in range(1, 100)}) | ||
|
@@ -156,16 +170,35 @@ def test_stream_callback(self): | |
self.assertEqual(data['y'], np.array([-10])) | ||
|
||
|
||
def test_stream_callback_single_call(self): | ||
def history_callback(x, history=deque(maxlen=10)): | ||
history.append(x) | ||
return Curve(list(history)) | ||
stream = PositionX() | ||
dmap = DynamicMap(history_callback, kdims=[], streams=[stream]) | ||
plot = bokeh_renderer.get_plot(dmap) | ||
bokeh_renderer(plot) | ||
for i in range(20): | ||
stream.update(x=i) | ||
data = plot.handles['source'].data | ||
self.assertEqual(data['x'], np.arange(10)) | ||
self.assertEqual(data['y'], np.arange(10, 20)) | ||
|
||
|
||
class TestPlotlyPlotInstantiation(ComparisonTestCase): | ||
|
||
def setUp(self): | ||
self.previous_backend = Store.current_backend | ||
Store.current_backend = 'plotly' | ||
self.default_comm = bokeh_renderer.comms['default'] | ||
if not plotly_renderer: | ||
raise SkipTest("Plotly required to test plot instantiation") | ||
plotly_renderer.comms['default'] = (comms.Comm, '') | ||
|
||
|
||
def teardown(self): | ||
Store.current_backend = self.previous_backend | ||
plotly_renderer.comms['default'] = self.default_comm | ||
|
||
def _get_plot_state(self, element): | ||
plot = plotly_renderer.get_plot(element) | ||
|
@@ -219,3 +252,17 @@ def test_grid_state(self): | |
self.assertEqual(state['data'][3]['y'], np.array([1, 1])) | ||
self.assertEqual(state['data'][3]['xaxis'], 'x2') | ||
self.assertEqual(state['data'][3]['yaxis'], 'y2') | ||
|
||
def test_stream_callback_single_call(self): | ||
def history_callback(x, history=deque(maxlen=10)): | ||
history.append(x) | ||
return Curve(list(history)) | ||
stream = PositionX() | ||
dmap = DynamicMap(history_callback, kdims=[], streams=[stream]) | ||
plot = plotly_renderer.get_plot(dmap) | ||
plotly_renderer(plot) | ||
for i in range(20): | ||
stream.update(x=i) | ||
state = plot.state | ||
self.assertEqual(state['data'][0]['x'], np.arange(10)) | ||
self.assertEqual(state['data'][0]['y'], np.arange(10, 20)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor nitpick: I don't see why
clone=False
needs to be on the next line in this case. Even if it is over 80 characters long it looks a bit weird...