ipydatagrid
ipydatagrid copied to clipboard
date object not supported (not JSON serializable)
Describe the bug ipydatagrid does not support date object
To Reproduce
import pandas as pd
import numpy as np
import datetime
from ipydatagrid import DataGrid
df = pd.DataFrame({ 'Date': [datetime.date(2021, 5, 11)], 'Val': [1] })
DataGrid(df)
Expected behavior I get this error TypeError: datetime.date(2021, 5, 11) is not JSON serializable
It looks like ipydatagrid supports pandas's datetime structures though, so calling pd.to_datetime on your list seems to work:
import pandas as pd
import numpy as np
import datetime
from ipydatagrid import DataGrid
df = pd.DataFrame({ 'Date': pd.to_datetime([datetime.date(2021, 5, 11)]), 'Val': [1] })
DataGrid(df)
I guess we could modify ipydatagrid's serializers so that it supports Python datetime objects (same applies to bqplot I suppose?)
I'm actually using spark to produce the pandas dataframe
pd = sdf.toPandas()
and there isn't any options to toPandas()
it would be great if ipydatagrid did the conversion
Thanks for reporting! We will look into adding this.
Fixed by #350