-
-
Notifications
You must be signed in to change notification settings - Fork 75
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
- pandas version:
2.0.1 - plotly_resampler version:
0.9.0rc1
code snippet which fails
import pandas as pd; import numpy as np
from plotly_resampler import FigureResampler
df = pd.DataFrame({'timestamp': pd.date_range('2020-01-01', '2020-01-02', freq='1s')})
df['value'] = np.random.randn(len(df))
fr = FigureResampler()
# This works
# fr.add_trace({}, hf_x=pd.Index(df.timestamp), hf_y=df.value)
# This doesn't
fr.add_trace({}, hf_x=df.timestamp, hf_y=df.value)
frWhat causes the fail:
this line:
plotly-resampler/plotly_resampler/figure_resampler/figure_resampler_interface.py
Line 787 in e56cbc7
| axis_type = "date" if isinstance(dc.x, pd.DatetimeIndex) else "linear" |
Will give that the datetime64 array requires a linear axis. As such, the xaxis.range[0] and xaxis.range[1] arguments will not be parsed to timestamps, and the hf_x slicing (i.e. the bisect), will fail, resulting in this error:

Solution
extend the check with:
axis_type = (
"date"
if isinstance(dc.x, pd.DatetimeIndex) or
pd.core.dtypes.common.is_datetime64_any_dtype(dc.x)
else "linear"
)TODO:
- verify if this occurs and works for pandas <2
Indeed this, occurs aswell for pandas<2 - create a PR and add tests for this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working