fix(elecprice): handle mixed UTC offsets in Tibber prices around DST (#1448)

Once Tibber publishes prices across a DST change, the series holds
timestamps with two UTC offsets and pd.to_datetime() raises "Mixed
timezones detected", so every optimization run is canceled. Parse via
UTC and convert back to the configured timezone.

Fixes #1446
This commit is contained in:
sarankumar
2026-10-25 06:10:48 +01:00
committed by GitHub
parent baafe570ff
commit cdbaae45ba
2 changed files with 25 additions and 1 deletions
+20
View File
@@ -217,6 +217,26 @@ class TestElecPriceTibber:
assert normalized.iloc[1] == pytest.approx(0.50)
def test_tibber_normalize_series_handles_dst_change(self, provider, set_other_timezone):
"""Prices spanning a DST change (mixed UTC offsets) are normalized, not rejected."""
set_other_timezone("Europe/Berlin")
index = [
to_datetime("2026-10-25T02:45:00+02:00", in_timezone="Europe/Berlin"),
to_datetime("2026-10-25T02:00:00+01:00", in_timezone="Europe/Berlin"),
to_datetime("2026-10-25T02:15:00+01:00", in_timezone="Europe/Berlin"),
]
series = pd.Series([0.10, 0.20, 0.30], index=index)
normalized = provider._normalize_series(series)
assert normalized.tolist() == pytest.approx([0.10, 0.20, 0.30])
assert [ts.timestamp() for ts in normalized.index] == [
to_datetime("2026-10-25T00:45:00+00:00").timestamp(),
to_datetime("2026-10-25T01:00:00+00:00").timestamp(),
to_datetime("2026-10-25T01:15:00+00:00").timestamp(),
]
assert provider._resolution_seconds(normalized) == 900
def test_empty_tomorrow_stores_only_today_and_warns(self, provider):
"""An empty tomorrow list does not create fake values before forecasting."""
response = TibberGraphQLResponse.model_validate(