Shared base for all multi-target forecasting pipeline tasks.
Inherits the complete data-preparation pipeline (steps 1-7) and all helper methods from spotforecast2_safe.multitask.base.BaseTask. PlottingMixin overrides the three visualisation hooks with live Plotly figures.
The public API — constructor signature, attributes, method names, and the PipelineConfig protocol — is identical to the safe-package base. See spotforecast2_safe.multitask.base.BaseTask for full documentation.
Task subclasses implement run() for their specific mode: LazyTask (lazy), OptunaTask (optuna), SpotOptimTask (spotoptim), PredictTask (predict), CleanTask (clean).
Visualisation additions over the safe base
plot_with_outliers: Renders original vs. cleaned data with outlier markers via spotforecast2.plots.plotter.plot_with_outliers. _show_prediction_figure: Calls make_plot and shows the figure interactively. _show_prediction_figure_agg: Same for the aggregated prediction.
Examples
import tempfileimport numpy as npimport pandas as pdfrom spotforecast2_safe.configurator.config_multi import ConfigMultifrom spotforecast2.multitask.base import BaseTask, PlottingMixinrng = np.random.default_rng(0)idx = pd.date_range("2023-01-01", periods=24*14, freq="h", tz="UTC")df = pd.DataFrame({"load": rng.normal(100, 10, len(idx))}, index=idx)df.index.name ="DateTime"with tempfile.TemporaryDirectory() as tmp: cfg = ConfigMulti( predict_size=6, use_exogenous_features=False, use_outlier_detection=False, auto_save_models=False, cache_home=tmp, ) task = BaseTask(cfg, dataframe=df)# Data-preparation pipeline (steps 1-3) task.prepare_data().detect_outliers().impute()print("Pipeline shape:", task.df_pipeline.shape)print("Targets:", task.config.targets)# PlottingMixin is in the MRO — visualisation hooks are live Plotly calls.print("PlottingMixin in MRO:", PlottingMixin intype(task).__mro__)assert task.df_pipeline.shape[1] ==1assert PlottingMixin intype(task).__mro__
Pipeline shape: (336, 1)
Targets: None
PlottingMixin in MRO: True
/tmp/ipykernel_3027/2659341657.py:22: DeprecationWarning: Derived pipeline fields (start_download, end_download, data_start, data_end, cov_start, cov_end, end_train_ts, start_train_ts) have moved to task.run_state. Reading them from the config is deprecated and will stop working in the next major release. config.targets continues to hold the user input unchanged; read the resolved list from task.run_state.targets.
task.prepare_data().detect_outliers().impute()
BaseTask.run is abstract — it raises NotImplementedError to enforce that every concrete task subclass provides its own implementation. Use LazyTask, OptunaTask, SpotOptimTask, PredictTask, or CleanTask for live pipelines.
import tempfileimport numpy as npimport pandas as pdfrom spotforecast2_safe.configurator.config_multi import ConfigMultifrom spotforecast2.multitask.base import BaseTaskfrom spotforecast2.multitask import LazyTaskrng = np.random.default_rng(0)idx = pd.date_range("2023-01-01", periods=24*14, freq="h", tz="UTC")df = pd.DataFrame({"load": rng.normal(100, 10, len(idx))}, index=idx)df.index.name ="DateTime"# BaseTask.run raises NotImplementedError — use a concrete subclass.with tempfile.TemporaryDirectory() as tmp: cfg = ConfigMulti(cache_home=tmp) base = BaseTask(cfg)try: base.run()exceptNotImplementedErroras exc:print("BaseTask.run() raised NotImplementedError (expected).")print(str(exc)[:60])# LazyTask overrides run() with lazy fitting logic.print("LazyTask.run is overridden:", LazyTask.run isnot BaseTask.run)assert LazyTask.run isnot BaseTask.run
BaseTask.run() raised NotImplementedError (expected).
BaseTask must implement run(). Use LazyTask, OptunaTask, Spo
LazyTask.run is overridden: True