Using hvplot.explorer with dates


I wanted to use hvplot.explorer on a dataframe but it only works if I drop the “timestamp” column (see screenshot), otherwise I get the error:

“ValueError: failed to validate RangeSlider(id=‘20073’, …).end: expected a value of type Real, got 2022-11-09T00:11:14.000000000 of type datetime64”

Is there a way to use date/time with explorer?


Can you share a minimal, reproducible example (MRE)?

I tried to upload as simple .csv file but am not allowed as a new user. Turns out the hvplot.explorer will work when the time/date is a string, but fails when it is a Pandas timestamp (i.e. the format in the first cell in the screenshot below renders explorer unusable, while the format in the second works). This seems surprising that hvplot does not natively handle the Pandas timestamp type.


As it is just a CSV you can just copy it into a message, maybe limit it to 20-30 rows.

Here is a copy of a file called “sample.csv” to demonstrate the issue I’m describing.

10/9/2022 6:52,2L22,0.73,0.54,new llrf
10/9/2022 6:36,2L22,0.84,0.73,new llrf
10/9/2022 3:39,2L26,0.49,0.47,new llrf
10/9/2022 2:36,1L23,0.25,0.2,old llrf
10/9/2022 2:36,1L23,0.1,0.3,old llrf
10/9/2022 2:36,1L23,0.3,0.1,old llrf
10/9/2022 2:35,1L23,0.99,0.96,old llrf
10/9/2022 2:20,1L23,0.25,0.25,old llrf
10/9/2022 2:20,1L23,0.99,0.99,old llrf
10/9/2022 1:51,1L24,0.4,0.2,old llrf

If you simply read in the .csv with no modifications, the timestamp will be interpreted as a string. Using hvplot.explorer works in this instance (i.e. you can plot a variable against the timestamp, even if the timestamp is not in chronological order). You can reproduce this using the commands below:


However, if you change the timestamp to a Pandas timestamp object - to get functionality that is not possible with a string - and then trying to use hvplot.explorer, it will not work. You can reproduce that result using the commands below:

I then get the following error:

This doesn’t work either, also date related, it would seem?

import xarray as xr
import hvplot.xarray

url = ''
ds = xr.open_dataset(url)

df = ds['Temperature_height_above_ground'][:5, 0, 600, 1000].to_dataframe()


@cdtennant: The error you are seeing is a bug. I will open an issue around this. Next time try to paste the code so people don’t have to write it from screenshots. An example of this could be:

import numpy as np
import pandas as pd

data = dict(
    y=np.arange(10) + 10,
    t=pd.date_range("2020-01-01", freq="1d", periods=10),
df = pd.DataFrame(data)

@rsignell: The error you are seeing is because all the x values and all the y values are the same, if I add this line df.iloc[0, [0, 1]] += 1 it succeeds. I don’t think it is unreasonable that if this happens to be the case, the sliders should be disabled and not give an error. I can also provoke your data explorer to the original error by @cdtennant.

Doh! Thanks @Hoxbro! And naturally a dataframe with x and y dropped also works: Jupyter Notebook Viewer