question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`holoviews.element. Curve` does not accept pandas data frame where index is `TimedeltaIndex`

See original GitHub issue

The following code works as expected:

import pandas as pd
import holoviews as hv
hv.extension('bokeh', 'matplotlib')
import numpy as np

dt = pd.date_range('2018-02-23T12:34:45', '2018-02-23T12:47:00', freq='1s', name='t')
data = pd.DataFrame(np.sin((dt-dt[0]) / np.timedelta64(1,'m')).values, columns=('A', ), index=dt)

hv.Curve(data)

but

data.index = dt - dt[0]
hv.Curve(data)

raises an error:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I would like to plot pandas data frames indexed both by DatetimeIndex (works) or TimedeltaIndex (does not work)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philippjfrcommented, Jun 8, 2020

The formatting issues are subsumed by https://github.com/holoviz/holoviews/issues/3143 so I’ll close this now.

1reaction
miccolicommented, Jun 26, 2018

I’ve done some testing using my patched bokeh miccoli/bokeh@0545753. Starting from numpy datetime64 and timedelta64 types, I’ve created two different pandas data frames.

dt = np.arange('2018-03-14T15:30:21', '2020-06-28T13:30:23', dtype='datetime64[h]')
td = dt - dt[len(dt)//2]
y = np.sin(4*np.pi*td / td.ptp())

pddt = pd.DataFrame(y, index=dt, columns=['sin'])
pddt.index.name = 'datetime'

pdtd = pd.DataFrame(y, index=td, columns=['sin'])
pdtd.index.name = 'timedelta'

Here the results of hv.Curve(pddt) and hv.Curve(pdtd)

image

image

The problem here is that in bokeh timedelta are scaled as ms (millisecond) and represented with a plain linear axis. This is could be OK, but the choice of ms is not very sensible in my opinion… Using the matplotlib backend one gets the same linear axis but with timedelta scaled as ns (nanosecond).

image

Things are not that better in pandas: pdtd.plot(figsize=(14,3), grid=True)

image

Things to fix, in my opinion:

  1. consistent behaviour for bokeh and matplotlib
  2. if a linear axis is to be used (without dynamic scaling like the bokeh datetime axis), times should be given in seconds and properly labelled as so.

Of course the ideal solution would be to implement native timedelta support in bokeh (extending the datetime axis or maybe creating a new timedelta axis type.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

holoviews.element. Curve does not accept pandas data frame ...
Curve does not accept pandas data frame where index is TimedeltaIndex # ... import pandas as pd import holoviews as hv hv.extension('bokeh', ...
Read more >
Holoviews Table does not visually preserves index
1) You could set the index as your key dimension: hv.Table(statdf, kdims=['index']). When using the bokeh backend this will still give you ...
Read more >
Pandas Conversion - HoloViews
Let's start by constructing a Pandas dataframe of a few columns and display ... is not needed by HoloViews, the index of the...
Read more >
ValueError: You must specify a period or x must be a pandas ...
Though it uses the time index (DatetimeIndex) for its x-axis, it does not require an item to hit the frequency exactly, in contrast...
Read more >
param.depends watch=True not working Part2
I clicked the table , too . the graph axis has changed. ... np import pandas as pd import panel as pn import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found