fix(data): normalize station history dates

This commit is contained in:
dasemu committed 2026-03-13 08:45:00 +01:00
1 parent 2a34054399
commit 04eb0fde61
3 files changed
+115 -5

No files matched your search

+20 -2
View File
@@ -84,8 +84,26 @@ def load_station_data(store: SQLiteStore) -> pd.DataFrame:
else:
logger.info("Loaded %d historical station rows from SQLite.", len(df))
# Parse dates with mixed formats (ISO and day-first variants)
df["date"] = pd.to_datetime(df["date"], format="mixed", dayfirst=True)
# Historical station data is stored in SQLite as ISO dates.
if not pd.api.types.is_datetime64_any_dtype(df["date"]):
df["date"] = pd.to_datetime(
df["date"],
format="%Y-%m-%d",
errors="raise",
)
# Keep station history aligned with the weather archive, which is fetched
# only up to the last complete day.
cutoff_ts = pd.Timestamp(date.today() - timedelta(days=1))
original_len = len(df)
df = df[df["date"] <= cutoff_ts].copy()
dropped = original_len - len(df)
if dropped > 0:
logger.info(
"Dropped %d station rows after %s while building the dataset.",
dropped,
cutoff_ts.date().isoformat(),
)
# ---------- open_status ----------
# idestado=1: open (normal operation)