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

Cannot create plotly histogram from datetime data #1001

Open
MarcSkovMadsen opened this issue Dec 3, 2022 · 0 comments
Open

Cannot create plotly histogram from datetime data #1001

MarcSkovMadsen opened this issue Dec 3, 2022 · 0 comments
Labels

Comments

@MarcSkovMadsen
Copy link
Collaborator

hvplot==0.8.2

Motivated by #998 I'm trying to improve the hist reference guide.

When I try to create a hist plot from a datetime column it works fine as long as I use the matplotlib or bokeh backends. When I start using the plotly backend it raises an exception.

import pandas as pd
from bokeh.sampledata.commits import data
import hvplot.pandas
backend = "plotly"
hvplot.extension(backend)

data=data.reset_index().sort_values("datetime")
plot = data.hvplot.hist(
    "datetime",
    bin_range=(pd.Timestamp('2012-11-30'), pd.Timestamp('2017-05-01')),
    bins=54, 
)

import holoviews as hv
hv.render(plot, backend)
$ python script.py
Traceback (most recent call last):
  File "C:\repos\private\tmp\holoviews\script.py", line 15, in <module>
    hv.render(plot, backend)
  File "C:\repos\private\tmp\holoviews\holoviews\util\__init__.py", line 829, in render
    return renderer_obj.get_plot_state(obj)
  File "C:\repos\private\tmp\holoviews\holoviews\plotting\plotly\renderer.py", line 86, in get_plot_state
    fig_dict = go.Figure(fig_dict).to_dict()
  File "C:\repos\private\hvplot\.venv\lib\site-packages\plotly\graph_objs\_figure.py", line 616, in __init__
    super(Figure, self).__init__(data, layout, frames, skip_invalid, **kwargs)
  File "C:\repos\private\hvplot\.venv\lib\site-packages\plotly\basedatatypes.py", line 514, in __init__
    data = self._data_validator.validate_coerce(
  File "C:\repos\private\hvplot\.venv\lib\site-packages\_plotly_utils\basevalidators.py", line 2668, in validate_coerce
    trace = self.get_trace_class(trace_type)(
  File "C:\repos\private\hvplot\.venv\lib\site-packages\plotly\graph_objs\_bar.py", line 3199, in __init__
    self["width"] = _v
  File "C:\repos\private\hvplot\.venv\lib\site-packages\plotly\basedatatypes.py", line 4859, in __setitem__
    self._set_prop(prop, value)
  File "C:\repos\private\hvplot\.venv\lib\site-packages\plotly\basedatatypes.py", line 5198, in _set_prop
    val = validator.validate_coerce(val)
  File "C:\repos\private\hvplot\.venv\lib\site-packages\_plotly_utils\basevalidators.py", line 803, in validate_coerce
    if not (self.min_val <= v <= self.max_val):
TypeError: The DType <class 'numpy.dtype[timedelta64]'> could not be promoted by <class 'numpy.dtype[float64]'>. 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.dtype[timedelta64]'>, <class 'numpy.dtype[float64]'>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant