Skip to content
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

"TypeError: invalid type promotion" when plotting streamz.DataFrame with recent bokeh #2422

Closed
dcferreira opened this issue Mar 8, 2018 · 2 comments

Comments

@dcferreira
Copy link

I'm getting a very non-informative error when trying to do a simple plot from one of the streaming examples (slightly modified) from the documentation.
I have a notebook with 2 cells, the first one:

import pandas as pd
from streamz.dataframe import Random
import holoviews as hv
from holoviews.streams import Buffer
hv.extension('bokeh')

sdf = Random()

and the 2nd:

%%opts Curve [width=500 show_grid=True]

raw_dmap = hv.DynamicMap(hv.Curve, streams=[Buffer(sdf.x)])
raw_dmap

When executing the 2nd cell, I get the following traceback:

ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.null_wrapper at 0x7f8a04257048>, <Future finished exception=TypeError('invalid type promotion',)>)
Traceback (most recent call last):
  File "/tmp/test/lib/python3.6/site-packages/tornado/ioloop.py", line 760, in _run_callback
    ret = callback()
  File "/tmp/test/lib/python3.6/site-packages/tornado/stack_context.py", line 276, in null_wrapper
    return fn(*args, **kwargs)
  File "/tmp/test/lib/python3.6/site-packages/tornado/ioloop.py", line 781, in _discard_future_result
    future.result()
  File "/tmp/test/lib/python3.6/site-packages/tornado/gen.py", line 1113, in run
    yielded = self.gen.send(value)
  File "/tmp/test/lib/python3.6/site-packages/streamz/dataframe/core.py", line 831, in _cb
    yield source._emit((last, now, freq))
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 226, in _emit
    r = downstream.update(x, who=self)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 490, in update
    return self._emit(result)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 226, in _emit
    r = downstream.update(x, who=self)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 490, in update
    return self._emit(result)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 226, in _emit
    r = downstream.update(x, who=self)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 490, in update
    return self._emit(result)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 226, in _emit
    r = downstream.update(x, who=self)
  File "/tmp/test/lib/python3.6/site-packages/streamz/core.py", line 443, in update
    result = self.func(x, *self.args, **self.kwargs)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/streams.py", line 389, in send
    self.event(data=data)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/streams.py", line 328, in event
    self.trigger([self])
  File "/tmp/test/lib/python3.6/site-packages/holoviews/streams.py", line 154, in trigger
    subscriber(**dict(union))
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/plot.py", line 513, in refresh
    self.update(stream_key)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/plot.py", line 492, in update
    item = self.__getitem__(key)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/plot.py", line 230, in __getitem__
    self.update_frame(frame)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 802, in update_frame
    self._update_glyphs(element, ranges)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 751, in _update_glyphs
    self._update_datasource(source, data)
  File "/tmp/test/lib/python3.6/site-packages/holoviews/plotting/bokeh/plot.py", line 194, in _update_datasource
    source.stream(data, stream.length)
  File "/tmp/test/lib/python3.6/site-packages/bokeh/models/sources.py", line 367, in stream
    self._stream(new_data, rollover)
  File "/tmp/test/lib/python3.6/site-packages/bokeh/models/sources.py", line 471, in _stream
    self.data._stream(self.document, self, new_data, rollover, setter)
  File "/tmp/test/lib/python3.6/site-packages/bokeh/core/property/containers.py", line 383, in _stream
    data = np.append(self[k], new_data[k])
  File "/tmp/test/lib/python3.6/site-packages/numpy/lib/function_base.py", line 5166, in append
    return concatenate((arr, values), axis=axis)
TypeError: invalid type promotion

Note: For some reason, each 1/10 times I execute the cell, I don't get the traceback, but the stream still stops, indicating that the error did occur. If you don't get a traceback while reproducing this, just try again.

At some point, the input pandas DataFrame is converted into a dictionary, changing the type of the index generated by streamz.dataframe.Random to float (rather than a pandas timestamp).
Since it expects the same type as the static example provided in the beginning of the stream, this TypeError is thrown.

Workaround: This happens with bokeh==0.12.14 (latest), but if I downgrade to bokeh==0.12.10, it works as expected.

My setup:

dferreira:/tmp$ virtualenv -p ~/.pyenv/versions/3.6.4/bin/python test
dferreira:/tmp$ cd test
dferreira:/tmp/test$ source bin/activate
(test) dferreira:/tmp/test$ pip install jupyter bokeh streamz matplotlib pandas git+git://github.com/ioam/holoviews.git
(test) dferreira:/tmp/test$ jupyter notebook
# test example, get error
(test) dferreira:/tmp/test$ pip install -U bokeh==0.12.10
(test) dferreira:/tmp/test$ jupyter notebook
# test again, everything works
@philippjfr
Copy link
Member

philippjfr commented Mar 8, 2018

This is fixed by #2383, which has already been applied in the last public release of holoviews (version 1.9.5). I've also just submitted a fix to bokeh to fix the underlying issue: bokeh/bokeh#7609

@dcferreira
Copy link
Author

Oops, should have searched better. Thanks for the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants