Skip to content

Commit

Permalink
Add deserialization of non-deserialized base64 data in `CDSCallback._…
Browse files Browse the repository at this point in the history
…process_msg` (#5587)
  • Loading branch information
hoxbro authored Jan 11, 2023
1 parent 4e33d1f commit 55ddbcb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import base64
import time

from collections import defaultdict, OrderedDict
Expand Down Expand Up @@ -924,6 +925,19 @@ def _process_msg(self, msg):
values = new_values
elif any(isinstance(v, (int, float)) for v in values):
values = [np.nan if v is None else v for v in values]
elif (
isinstance(values, list)
and len(values) == 4
and values[2] in ("big", "little")
and isinstance(values[3], list)
):
# Account for issue seen in https://github.com/holoviz/geoviews/issues/584
# This could be fixed in Bokeh 3.0, but has not been tested.
# Example:
# ['pm9vF9dSY8EAAADgPFNjwQAAAMAmU2PBAAAAAMtSY8E=','float64', 'little', [4]]
buffer = base64.decodebytes(values[0].encode())
dtype = np.dtype(values[1]).newbyteorder(values[2])
values = np.frombuffer(buffer, dtype)
msg['data'][col] = values
return self._transform(msg)

Expand Down
13 changes: 12 additions & 1 deletion holoviews/tests/plotting/bokeh/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from bokeh.io.doc import set_curdoc
from bokeh.models import Range1d, Plot, ColumnDataSource, Selection, PolyEditTool
from holoviews.plotting.bokeh.callbacks import (
Callback, PointDrawCallback, PolyDrawCallback, PolyEditCallback,
Callback, CDSCallback, PointDrawCallback, PolyDrawCallback, PolyEditCallback,
BoxEditCallback, PointerXCallback, TapCallback
)
from holoviews.plotting.bokeh.renderer import BokehRenderer
Expand Down Expand Up @@ -435,3 +435,14 @@ def test_rangexy_framewise_not_reset_if_triggering(self):
))
stream.event(x_range=(0, 3))
self.assertEqual(stream.x_range, (0, 3))


def test_msg_with_base64_array():
# Account for issue seen in https://github.com/holoviz/geoviews/issues/584
data_before = ["AAAAAAAAJEAAAAAAAAA0QAAAAAAAAD5AAAAAAAAAREA=", "float64", "little", [4]]
msg_before = {"data": {"x": data_before}}
msg_after = CDSCallback(None, None, None)._process_msg(msg_before)
data_after = msg_after["data"]["x"]

data_expected = np.array([10.0, 20.0, 30.0, 40.0])
assert np.equal(data_expected, data_after).all()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# of those.
extras_require['tests'] = extras_require['tests_core'] + [
'dask',
'ibis-framework', # Mapped to ibis-sqlite in setup.cfg for conda
'ibis-framework <4', # Mapped to ibis-sqlite in setup.cfg for conda
'xarray >=0.10.4',
'networkx',
'shapely',
Expand Down

0 comments on commit 55ddbcb

Please sign in to comment.