Type-check pandas with pandas-stubs
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m54s
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m54s
This commit is contained in:
parent
01416a1175
commit
2bc2408694
1 changed files with 28 additions and 9 deletions
|
|
@ -3,6 +3,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime as dt
|
||||
import typing as t
|
||||
|
||||
import pandas as pd
|
||||
import sqlalchemy as sa
|
||||
|
|
@ -42,7 +43,7 @@ class OrderHistory:
|
|||
self._n_daily_time_steps = int(n_daily_time_steps)
|
||||
|
||||
# The `_data` are populated by `.aggregate_orders()`.
|
||||
self._data = None
|
||||
self._data: pd.DataFrame | None = None
|
||||
|
||||
@property
|
||||
def time_step(self) -> int:
|
||||
|
|
@ -148,15 +149,18 @@ class OrderHistory:
|
|||
if data.empty:
|
||||
return data
|
||||
|
||||
# The `index` holds the "pixel_id" and "start_at" levels
|
||||
index = t.cast(pd.MultiIndex, data.index)
|
||||
|
||||
# Calculate the first and last "start_at" value ...
|
||||
start_day = data.index.levels[1].min().date()
|
||||
start_day = index.levels[1].min().date()
|
||||
start = dt.datetime(
|
||||
start_day.year,
|
||||
start_day.month,
|
||||
start_day.day,
|
||||
pkg_config.SERVICE_START,
|
||||
)
|
||||
end_day = data.index.levels[1].max().date()
|
||||
end_day = index.levels[1].max().date()
|
||||
end = dt.datetime(
|
||||
end_day.year,
|
||||
end_day.month,
|
||||
|
|
@ -167,7 +171,7 @@ class OrderHistory:
|
|||
# The "start_at" values must lie within the operating hours.
|
||||
gen = (
|
||||
(pixel_id, start_at)
|
||||
for pixel_id in sorted(data.index.levels[0])
|
||||
for pixel_id in sorted(index.levels[0])
|
||||
for start_at in pd.date_range(start, end, freq=f"{self._time_step}min")
|
||||
if pkg_config.SERVICE_START <= start_at.hour < pkg_config.SERVICE_END
|
||||
)
|
||||
|
|
@ -317,7 +321,7 @@ class OrderHistory:
|
|||
msg = "Not enough historic data for `predict_at`"
|
||||
raise RuntimeError(msg)
|
||||
|
||||
actuals_ts = intra_pixel.loc[[predict_at], "n_orders"]
|
||||
actuals_ts = intra_pixel.loc[intra_pixel.index == predict_at, "n_orders"]
|
||||
if not len(actuals_ts): # pragma: no cover
|
||||
msg = "`predict_at` is not in the order history"
|
||||
raise LookupError(msg)
|
||||
|
|
@ -510,7 +514,7 @@ class OrderHistory:
|
|||
msg = "Not enough historic data for `predict_day`"
|
||||
raise RuntimeError(msg)
|
||||
|
||||
actuals_ts = intra_pixel.loc[[predict_at], "n_orders"]
|
||||
actuals_ts = intra_pixel.loc[intra_pixel.index == predict_at, "n_orders"]
|
||||
if not len(actuals_ts): # pragma: no cover
|
||||
msg = "`predict_at` is not in the order history"
|
||||
raise LookupError(msg)
|
||||
|
|
|
|||
Loading…
Reference in a new issue