ipydatagrid icon indicating copy to clipboard operation
ipydatagrid copied to clipboard

date object not supported (not JSON serializable)

Open cccs-jc opened this issue 3 years ago • 3 comments

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

cccs-jc avatar Jan 06 '22 14:01 cccs-jc

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?)

martinRenou avatar Jan 06 '22 15:01 martinRenou

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

cccs-jc avatar Jan 06 '22 15:01 cccs-jc

Thanks for reporting! We will look into adding this.

ibdafna avatar Mar 10 '22 22:03 ibdafna

Fixed by #350

ibdafna avatar Oct 25 '22 15:10 ibdafna