juba / pyobsplot

Observable Plot in Jupyter notebooks and Quarto documents
https://juba.github.io/pyobsplot/
MIT License
184 stars 8 forks source link

Unexpected scale for pandas datetime column #19

Closed harrylojames closed 1 year ago

harrylojames commented 1 year ago

datetime64[ns] objects aren't converted to javascript date objects. Presume this is intended as per the section on datetimes. Would be great if it were possible!

import pandas as pd
from pyobsplot import Plot

df = pd.DataFrame({'full_date_time': {0: pd.Timestamp('2022-12-01 00:00:00'),
  1: pd.Timestamp('2022-12-01 01:00:00')},
 'value': {0: 20.0, 1: 18.0}})

Plot.plot({"marks":[Plot.dot(df, {"x":"full_date_time", "y": "value"})]})

image

harrylojames commented 1 year ago

Excuse my ignorance on what's been written under the hood but Quarto's ojs_define seems to work pretty smoothly for converting panda's objects if there are any tricks not yet borrowed.

juba commented 1 year ago

Yes, you're right, date objects are converted correctly, but timestamps and datetime are not.

I'll take a look, thanks for reporting !

juba commented 1 year ago

I think this should be fixed in the new 0.3.6 release, but let me know if it is working correctly for you.

Thanks !

harrylojames commented 1 year ago

2 for 2 🎉thank you!