Skip to content

Commit 1abeca8

Browse files
committed
Fixing issue with serializing datetime columns
1 parent 66bf54e commit 1abeca8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,18 @@ def load_data(aoi_value: str):
388388
# time series
389389
try:
390390
ts_df = reader.read_ts(aoi_name)
391-
ts_json = ts_df.drop(columns=["geometry", "geometry_wkt"], errors="ignore").to_json(
392-
date_format="iso", orient="split"
393-
)
391+
ts_df = ts_df.drop(columns=["geometry", "geometry_wkt", "bbox_area"], errors="ignore")
392+
ts_df["time"] = pd.to_datetime(ts_df["time"]).dt.strftime("%Y-%m-%d")
393+
ts_json = ts_df.to_json(orient="split")
394394
except Exception as e:
395395
print(f"TS load error: {e}")
396396
ts_json = None
397397

398398
# forecast
399399
try:
400400
fc_df = reader.read_forecasts(aoi_name, forecast_date="latest")
401-
fc_json = fc_df.to_json(date_format="iso", orient="split")
401+
fc_df["ds"] = pd.to_datetime(fc_df["ds"]).dt.strftime("%Y-%m-%d")
402+
fc_json = fc_df.to_json(orient="split")
402403
except Exception as e:
403404
print(f"Forecast load error: {e}")
404405
fc_json = None
@@ -607,7 +608,7 @@ def update_summary_stats(ts_json, fc_json, metrics):
607608
try:
608609
fc_df = pd.read_json(fc_json, orient="split")
609610
horizon = fc_df.groupby("unique_id")["ds"].count().max()
610-
fc_end = pd.to_datetime(fc_df["ds"]).max().strftime("%Y-%m-%d")
611+
fc_end = fc_df["ds"].max()
611612
cards.append(summary_stat_card("Forecast horizon", f"{horizon}w", f"to {fc_end}", "#378ADD"))
612613
except Exception:
613614
cards.append(summary_stat_card("Forecast horizon", "—", "", "#888"))

0 commit comments

Comments
 (0)