Skip to content

Commit

Permalink
[Jupyter][Fix] convert datetimes to str so they can convert to json (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rbavery authored Feb 1, 2025
1 parent 5367aba commit 7bbe0b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bindings/kepler.gl-jupyter/keplergl/keplergl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ def _df_to_dict(df):
- dictionary: a dictionary variable that can be used in Kepler.gl
'''
return df.to_dict('split')
df_copy = df.copy()
# Convert all columns that aren't JSON serializable to strings
for col in df_copy.columns:
try:
# just check the first item in the colum
json.dumps(df_copy[col].iloc[0] if len(df_copy) > 0 else None)
except (TypeError, OverflowError):
df_copy[col] = df_copy[col].astype(str)

return df_copy.to_dict('split')


def _df_to_arrow(df: pd.DataFrame):
Expand Down

0 comments on commit 7bbe0b8

Please sign in to comment.