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

Streaming example fails #1500

Open
1 task
yt87 opened this issue Feb 17, 2025 · 1 comment
Open
1 task

Streaming example fails #1500

yt87 opened this issue Feb 17, 2025 · 1 comment

Comments

@yt87
Copy link

yt87 commented Feb 17, 2025

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Software Version Info
Include version information here

 python           3.12.9       h9e4cc4f_0_cpython  conda-forge  
 hvplot           0.11.2       pyhd8ed1ab_0        conda-forge
 streamz          0.6.4        pyhd8ed1ab_1        conda-forge
 bokeh            3.6.3        pyhd8ed1ab_0        conda-forge
 numpy            2.2.3        py312h72c5963_0     conda-forge

Description of expected behavior and the observed behavior

The first streaming example on https://hvplot.holoviz.org/user_guide/Streaming.html raises numpy exception, also shows hvplot deprecation message.

Complete, minimal, self-contained example code that reproduces the issue

# code goes here between backticks
from streamz.dataframe import Random
import hvplot.streamz  # noqa
df = Random(interval='500ms', freq='50ms')
df.hvplot()

Stack traceback and/or browser JavaScript console output

/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/hvplot/converter.py:100): ParamFutureWarning: get_param_values has been deprecated and will be removed in a future version. Use .param.values().items() instead (or .param.values() for the common case of dict(....param.get_param_values()))
old = {k: v for k, v in self.param.get_param_values() if k not in ['callable', 'name']}

Traceback (most recent call last):
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/pyviz_comms/__init__.py", line 339, in _handle_msg
    self._on_msg(msg)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/panel/viewable.py", line 493, in _on_msg
    patch.apply_to_document(doc, comm.id if comm else None)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in apply_to_document
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
    return f()
           ^^^
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/protocol/messages/patch_doc.py", line 104, in <lambda>
    invoke_with_curdoc(doc, lambda: doc.apply_json_patch(self.payload, setter=setter))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/document/document.py", line 391, in apply_json_patch
    DocumentPatchedEvent.handle_event(self, event, setter)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/document/events.py", line 244, in handle_event
    event_cls._handle_event(doc, event)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/document/events.py", line 566, in _handle_event
    model._stream(data, rollover, event.setter)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/models/sources.py", line 577, in _stream
    self.data._stream(self.document, self, new_data, rollover, setter)
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/bokeh/core/property/wrappers.py", line 492, in _stream
    seq = np.append(old_seq, new_seq)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/george/miniforge3/envs/aawu/lib/python3.12/site-packages/numpy/lib/_function_base_impl.py", line 5711, in append
    return concatenate((arr, values), axis=axis)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.exceptions.DTypePromotionError: The DType <class 'numpy.dtypes.DateTime64DType'> could not be promoted by <class 'numpy.dtypes.Float64DType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes.Float64DType'>)

The traceback repeats, although the plot does show up in Jupyter.

Screenshots or screencasts of the bug in action

  • I may be interested in making a pull request to address this
@yt87
Copy link
Author

yt87 commented Mar 10, 2025

I think I know what causes the above behaviour. The exception is raised when np.append is called by PropertyValueColumnData._stream in file bokeh/core/property/wrappers.py when the arguments are of type np.datatime64 and np.float64. This happens because the initial data field in ColumnarDataSource, file bokeh/core/models/sources.py during class instantiation is not converted. Adding the conversion to __init__ seems to work:

for key, values in self.data.items():
    # Apply the transformation if the data contains datetimes
    if isinstance(values, np.ndarray) and values.dtype.kind.lower() == 'm':
        self.data[key] = convert_datetime_array(values)

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

1 participant