hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

timedelta64[ns] axis tick formatting problem

Open zbarry opened this issue 5 years ago • 5 comments

ALL software version info

hvplot 0.6.0

Description of expected behavior and the observed behavior

It looks like tick formatting for time axes is not being applied for the first plot in a layout, only in subsequent ones:

import pandas as pd
import holoviews as hv
import hvplot.pandas
import numpy as np

hv.extension('bokeh')

time_end = 10
sampling_time = 0.2

timepoints = np.arange(0, time_end, sampling_time)

df = pd.DataFrame(dict(
    time=pd.to_timedelta(timepoints, 's'),
    value=np.sin(timepoints),
    value_2=timepoints,
))

(
    df.hvplot(x='time', y='value') 
    + df.hvplot(x='time', y='value_2')
)

image

zbarry avatar Jun 30 '20 19:06 zbarry

Just as an initial guess I think the issue here might be that JS does not have sufficient integer precision to represent nanosecond datetimes so something is getting lost along the way.

philippjfr avatar Jun 30 '20 22:06 philippjfr

Ah, I see. Is there some other dtype you think I should try instead to represent time series data based on timedeltas?

zbarry avatar Jul 01 '20 15:07 zbarry

If it is a precision issue in JS, then presumably this can can be reproduced with a pure Bokeh example?

jlstevens avatar Aug 03 '20 15:08 jlstevens

Looking at this again I think this is just down to the fact that timedeltas aren't handled well.

philippjfr avatar Jan 14 '21 12:01 philippjfr

A similar issue affects polars (unsurprisingly since it converts to pandas first, and the pandas dtype ends up being timedelta64[ns] as well):

import polars as pl
df = pl.DataFrame(dict(a=list(range(10000)), b=list(range(10000))), schema=dict(a=pl.Duration('ns'), b=int))
df.plot.line('a', 'b')

So whoever takes on https://github.com/holoviz/holoviews/issues/5939 should ensure nanosecond works as well (and not rely on Python timedeltas: https://github.com/pola-rs/polars/issues/14695)

EDIT: updated the snippet to a more obvious example of truncation to microsecond.

douglas-raillard-arm avatar Feb 27 '24 11:02 douglas-raillard-arm