Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Jupyter][Fix] convert datetimes to str so they can convert to json (#2968)
Ryan Avery7bbe0b839e38
diff --git a/bindings/kepler.gl-jupyter/keplergl/keplergl.py b/bindings/kepler.gl-jupyter/keplergl/keplergl.pyindex 4b5943d29..9e909a835 100644--- a/bindings/kepler.gl-jupyter/keplergl/keplergl.py+++ b/bindings/kepler.gl-jupyter/keplergl/keplergl.py@@ -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):