Add pyright as a second type checker #14

Merged
alexander merged 5 commits from add-pyright into develop 2026-12-01 15:18:18 +01:00
Showing only changes of commit 804a4a0966 - Show all commits

Iterate over the rows in Forecast.from_dataframe()

Alexander Hess 2026-12-01 14:49:03 +01:00
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -222,40 +222,32 @@ class Forecast(meta.Base):
"""
forecasts = []
for timestamp_idx in data.index:
start_at = timestamp_idx.to_pydatetime()
actual = int(data.loc[timestamp_idx, "actual"])
prediction = float(round(data.loc[timestamp_idx, "prediction"], 5))
# Explicit type casting. SQLAlchemy does not convert
# `float('NaN')`s into plain `None`s.
low80 = data.loc[timestamp_idx, "low80"]
high80 = data.loc[timestamp_idx, "high80"]
low95 = data.loc[timestamp_idx, "low95"]
high95 = data.loc[timestamp_idx, "high95"]
low80 = None if math.isnan(low80) else float(round(low80, 5))
high80 = None if math.isnan(high80) else float(round(high80, 5))
low95 = None if math.isnan(low95) else float(round(low95, 5))
high95 = None if math.isnan(high95) else float(round(high95, 5))
rows = data[["actual", "prediction", "low80", "high80", "low95", "high95"]]
for (
timestamp_idx,
actual,
prediction,
low80,
high80,
low95,
high95,
) in rows.itertuples(name=None):
forecasts.append(
cls(
pixel=pixel,
start_at=start_at,
start_at=timestamp_idx.to_pydatetime(),
time_step=time_step,
train_horizon=train_horizon,
model=model,
actual=actual,
prediction=prediction,
low80=low80,
high80=high80,
low95=low95,
high95=high95,
actual=int(actual),
prediction=float(round(prediction, 5)),
# Explicit type casting. SQLAlchemy does not convert
# `float('NaN')`s into plain `None`s.
low80=None if math.isnan(low80) else float(round(low80, 5)),
high80=None if math.isnan(high80) else float(round(high80, 5)),
low95=None if math.isnan(low95) else float(round(low95, 5)),
high95=None if math.isnan(high95) else float(round(high95, 5)),
),
)