data.fetch_data.load_timeseries_forecast

data.fetch_data.load_timeseries_forecast(data_home=None, on_missing='raise')

Load the day-ahead forecast time series from interim/energy_load.csv.

Reads the Forecasted Load column and converts the index to a UTC DatetimeIndex with hourly frequency. Missing values are rejected by default so callers cannot accidentally feed imputed values into downstream safety-critical pipelines. Pass on_missing='ffill_bfill' to opt into the legacy forward/backward fill behavior that was the default before the 1.0 major release.

Parameters

Name Type Description Default
data_home Optional[Union[str, Path]] Root data directory. If None, resolved via get_data_home(). None
on_missing OnMissing How to handle NaN rows in Forecasted Load. 'raise' (default) fails fast with the gap timestamps; 'ffill_bfill' forward- then back-fills. 'raise'

Returns

Name Type Description
pd.Series pd.Series: Hourly forecasted-load series indexed by UTC timestamps.

Raises

Name Type Description
FileNotFoundError If interim/energy_load.csv does not exist.
KeyError If Forecasted Load column is not present.
ValueError If on_missing='raise' and the series has NaNs.

Examples

>>> import os, tempfile, shutil
>>> import pandas as pd
>>> from spotforecast2_safe.data.fetch_data import (
...     load_timeseries_forecast, get_package_data_home,
... )
>>> tmp = tempfile.mkdtemp()
>>> os.environ["SPOTFORECAST2_DATA"] = tmp
>>> interim = os.path.join(tmp, "interim")
>>> os.makedirs(interim, exist_ok=True)
>>> demo = get_package_data_home() / "demo01.csv"
>>> df = pd.read_csv(demo)
>>> df = df.rename(columns={
...     "Time": "Time (UTC)",
...     "Actual": "Actual Load",
...     "Forecast": "Forecasted Load",
... })
>>> df.to_csv(os.path.join(interim, "energy_load.csv"), index=False)
>>> y_f = load_timeseries_forecast()
>>> isinstance(y_f, pd.Series)
True
>>> shutil.rmtree(tmp)
>>> del os.environ["SPOTFORECAST2_DATA"]