Skip to content

Commit 64970ae

Browse files
committed
fix: deduplicate DataFrame index before asfreq in _apply_df_freq_horizon
Prevents ValueError: cannot reindex on an axis with duplicate labels when naive-mpc-optim is called with an InfluxDB backend whose time window (due to UTC offsets) spans two calendar days, producing ~2x the expected data points. The resulting concat of PV + load forecast Series can carry duplicate timestamps that cause asfreq() to fail. Uses the same ~df.index.duplicated() pattern already present in set_df_index_freq() and prepare_data() elsewhere in the codebase.
1 parent 38c83b3 commit 64970ae

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/emhass/command_line.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ def _apply_df_freq_horizon(
736736
step = retrieve_hass_conf["optimization_time_step"]
737737
if not isinstance(step, pd._libs.tslibs.timedeltas.Timedelta):
738738
step = pd.to_timedelta(step, "minute")
739+
df = df[~df.index.duplicated(keep="last")]
739740
df = df.asfreq(step)
740741
else:
741742
df = utils.set_df_index_freq(df)

0 commit comments

Comments
 (0)