From d9ae183ea8468a90dad07142e6e23ed280de5877 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 25 Mar 2024 10:47:19 +0100 Subject: [PATCH] fix _clean_belief_dataframe for a BDF with a single index. (#1019) Signed-off-by: Victor Garcia Reolid --- .../data/models/reporting/pandas_reporter.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/flexmeasures/data/models/reporting/pandas_reporter.py b/flexmeasures/data/models/reporting/pandas_reporter.py index fbbd5e7c3..0f0910008 100644 --- a/flexmeasures/data/models/reporting/pandas_reporter.py +++ b/flexmeasures/data/models/reporting/pandas_reporter.py @@ -168,9 +168,18 @@ def _clean_belief_dataframe( # filing the missing indexes with default values: if "belief_time" not in bdf.index.names: if belief_horizon is not None: - belief_time = ( - bdf["event_start"] + +bdf.event_resolution - belief_horizon - ) + + # In case that all the index but `event_start` are dropped + if ( + isinstance(bdf.index, pd.DatetimeIndex) + and bdf.index.name == "event_start" + ): + event_start = bdf.index + else: + event_start = bdf.index.get_event_values("event_start") + + belief_time = event_start + bdf.event_resolution - belief_horizon + else: belief_time = [belief_time] * len(bdf) bdf["belief_time"] = belief_time