Skip to content

Commit

Permalink
Workaround for datetime streaming bug in bokeh
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 1, 2018
1 parent e054229 commit 86b886c
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
GenericElementPlot, GenericOverlayPlot)
from ..util import attach_streams
from .util import (layout_padding, pad_plots, filter_toolboxes, make_axis,
update_shared_sources, empty_plot, decode_bytes)
update_shared_sources, empty_plot, decode_bytes,
bokeh_version)

from bokeh.layouts import gridplot
from bokeh.plotting.helpers import _known_tools as known_tools
from bokeh.util.serialization import convert_datetime_array

TOOLS = {name: tool if isinstance(tool, basestring) else type(tool())
for name, tool in known_tools.items()}
Expand Down Expand Up @@ -184,7 +186,32 @@ def _update_datasource(self, source, data):
stream = self.streaming[0]
if stream._triggering:
data = {k: v[-stream._chunk_length:] for k, v in data.items()}
source.stream(data, stream.length)

# NOTE: Workaround for bug in bokeh 0.12.14, data conversion
# should be removed once fixed in bokeh (https://github.com/bokeh/bokeh/issues/7587)
converted_data = {}
for k, vals in data.items():
cdata = source.data[k]
odata = data[k]
if (bokeh_version in ['0.12.14', '0.12.15dev1'] and
isinstance(cdata, np.ndarray) and cdata.dtype.kind == 'M'
and isinstance(vals, np.ndarray) and vals.dtype.kind == 'M'):
cdata = convert_datetime_array(cdata)
odata = convert_datetime_array(odata)
if len(odata):
cdata = np.concatenate([odata, cdata])
converted_data[k] = cdata
if converted_data:
for k, vals in data.items():
cdata = source.data[k]
odata = data[k]
if k not in converted_data:
if len(odata):
cdata = np.concatenate([odata, cdata])
converted_data[k] = cdata
source.data.update(converted_data)
else:
source.stream(data, stream.length)
else:
source.data.update(data)

Expand Down

0 comments on commit 86b886c

Please sign in to comment.