3232import time as _time
3333from dataclasses import dataclass , field
3434from pathlib import Path
35- from typing import Optional
35+ from typing import Any
3636
3737import structlog
3838
@@ -154,8 +154,8 @@ def __init__(
154154 self ,
155155 node : str = "Maitencillo" ,
156156 model_path : str | Path = "models/price_predictor.onnx" ,
157- model_p10_path : Optional [ str | Path ] = None ,
158- model_p90_path : Optional [ str | Path ] = None ,
157+ model_p10_path : str | Path | None = None ,
158+ model_p90_path : str | Path | None = None ,
159159 history_window : int = 192 , # 8 days → supports lag_168h
160160 alpha : float = 0.3 ,
161161 cache_ttl_s : float = _CACHE_TTL_S ,
@@ -173,7 +173,7 @@ def __init__(
173173 log .info ("cmg_predictor.using_int8" , node = node , path = str (int8_path ))
174174
175175 # Quantile model paths (auto-discover from base path)
176- def _q_path (suffix : str , override : Optional [ str | Path ] ) -> Path :
176+ def _q_path (suffix : str , override : str | Path | None ) -> Path :
177177 if override :
178178 return Path (override )
179179 base = Path (model_path )
@@ -198,7 +198,7 @@ def _q_path(suffix: str, override: Optional[str | Path]) -> Path:
198198 self ._smooth : dict [int , float ] = {h : _HOURLY_MEAN_CMG [h ] for h in range (24 )}
199199
200200 # Forecast cache: (timestamp_s, [PriceForecast])
201- self ._cache : Optional [ tuple [float , list [PriceForecast ]]] = None
201+ self ._cache : tuple [float , list [PriceForecast ]] | None = None
202202
203203 # ── Model Loading ─────────────────────────────────────────────────────────
204204
@@ -302,7 +302,7 @@ def load_history_from_csv(self, csv_path: Path) -> int:
302302 def predict_next_24h (
303303 self ,
304304 current_hour : int ,
305- current_cmg : Optional [ float ] = None ,
305+ current_cmg : float | None = None ,
306306 ) -> list [PriceForecast ]:
307307 """Generate 24h price forecasts with uncertainty bands.
308308
@@ -380,7 +380,7 @@ def _make_feature_vector(
380380 lag_168h : float ,
381381 day_of_week : float = 0.0 ,
382382 soc_pct : float = 50.0 ,
383- ) -> " np.ndarray" :
383+ ) -> np .ndarray :
384384 """Build the input feature vector for ONNX inference."""
385385 is_weekend = float (int (day_of_week ) >= 5 )
386386 if self ._n_features == 11 :
@@ -401,7 +401,7 @@ def _make_feature_vector(
401401 ]
402402 return np .array ([vec ], dtype = np .float32 )
403403
404- def _run_session (self , session : object , features : " np.ndarray" ) -> float :
404+ def _run_session (self , session : Any , features : np .ndarray ) -> float :
405405 """Run a single ONNX session and return scalar output."""
406406 out = session .run (None , {self ._input_name : features }) # type: ignore[union-attr]
407407 return float (out [0 ].flatten ()[0 ])
0 commit comments