Skip to content

Commit 07fe105

Browse files
ymatzkevichauthierj“authierj”dennisbaderjonasblanc
authored
Feature/metadata (#2656)
* Added metadata attribute, carried along through operations * changelog * refactored metadata into a pandas Series * fix lags_past_covariates dict type breaks lags_future_covariates when output_chunk_shift>0 (#2655) * if clause modified to correct bug * contribution added to changelog * implemented modifications from reviewer * unit tests added --------- Co-authored-by: “authierj” <“[email protected]”> * fix failing tfm load with pytorch>=2.6.0 (#2658) * Allow to strip training data for storage and memory reason on save for GlobalForecastingModel (#2649) * Add option to drop training_series during save() for GlobalForecastingModel * Update error on predict with no training series, update tests * Update CHANGELOG.md * Add _clean fonction to get a cleaned instance of the models * Use shallow copy to get clean model * Update darts/models/forecasting/regression_model.py Co-authored-by: Dennis Bader <[email protected]> * Update darts/models/forecasting/torch_forecasting_model.py Co-authored-by: Dennis Bader <[email protected]> * Define _clean() in ForecastingModel * Fix typo in docstring Co-authored-by: Dennis Bader <[email protected]> * Reformulate comment Co-authored-by: Dennis Bader <[email protected]> * Update CHANGELOG.md Co-authored-by: Dennis Bader <[email protected]> * Add clean argument in model.save for conformal and ensemble models * Update docstring * Remove additional training params on clean, update tests * Fix _clean and save logic, update save/load test * Update darts/models/forecasting/forecasting_model.py Co-authored-by: Dennis Bader <[email protected]> * Remove map_location on model load, set cpu as default accelerator * Update CHANGELOG.md * Add covariate to save/load test * Update CHANGELOG.md * Add _clean() to clean sub-model, update unit tests * Add _clean() to clean sub-models, update unit tests * minor refactor * further upadtes * pickle tfm model wrapper instead of torch save / load * update changelog * last fix --------- Co-authored-by: Dennis Bader <[email protected]> * adapted tests for metadata * changelog * add missing metadat propagation and fix tests * metadata changed to dict * tests adapted, one removed for metadata * remove metadata from timeseries generation * update timeseries * extend unit tests * update changelog * udpate changelog --------- Co-authored-by: Jules Authier <[email protected]> Co-authored-by: “authierj” <“[email protected]”> Co-authored-by: Dennis Bader <[email protected]> Co-authored-by: Jonas Blanc <[email protected]> Co-authored-by: authierj <[email protected]>
1 parent 0a4cf0f commit 07fe105

File tree

13 files changed

+483
-186
lines changed

13 files changed

+483
-186
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
1111

1212
**Improved**
1313

14+
- Added support for embedding metadata in `TimeSeries`. You can now attach any type of metadata as a dictionary to your time series, either at series creation using parameter `metadata` (or `metadata_cols` with `from_group_dataframe()`), or add it to an existing series via the `TimeSeries.with_metadata()` method. Unlike static covariates, metadata is not utilized by Darts' models during the forecasting process. However, the metadata is propagated through all downstream tasks, preserving the integrity and continuity of the information throughout the data pipeline. [#2656](https://github.com/unit8co/darts/pull/2656) by [Yoav Matzkevich](https://github.com/ymatzkevich), [Jules Authier](https://github.com/authierj) and [Dennis Bader](https://github.com/dennisbader).
1415
- Improved `CatBoostModel` documentation by describing how to use native multi-output regression. [#2659](https://github.com/unit8co/darts/pull/2659) by [Jonas Blanc](https://github.com/jonasblanc)
1516
- `TimeSeries.from_dataframe()` and `from_series()` now support creating `TimeSeries` from additional backends (Polars, PyArrow, ...). We leverage `narwhals` as the compatibility layer between dataframe libraries. See the `narwhals` [documentation](https://narwhals-dev.github.io/narwhals/) for all supported backends. [#2661](https://github.com/unit8co/darts/pull/2661) by [Jules Authier](https://github.com/authierj)
1617
- Added new export methods: `TimeSeries.to_dataframe()` and `TimeSeries.to_series()`. These methods support exporting `TimeSeries` to DataFrames and Series for all backends supported by `narwhals`. See the `narwhals` documentation [documentation](https://narwhals-dev.github.io/narwhals/extending/) for all supported backends. [#2701](https://github.com/unit8co/darts/pull/2701) by [Jules Authier](https://github.com/authierj)

darts/dataprocessing/transformers/midas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,5 @@ def _create_midas_df(
488488
values=arr,
489489
columns=cols,
490490
static_covariates=static_covariates,
491+
metadata=series.metadata,
491492
)

darts/models/forecasting/baselines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def _target_average(self, prediction: TimeSeries, series: TimeSeries) -> TimeSer
409409
columns=series.components,
410410
static_covariates=series.static_covariates,
411411
hierarchy=series.hierarchy,
412+
metadata=prediction.metadata,
412413
)
413414

414415
def _params_average(self, prediction: TimeSeries, series: TimeSeries) -> TimeSeries:
@@ -444,4 +445,5 @@ def _params_average(self, prediction: TimeSeries, series: TimeSeries) -> TimeSer
444445
columns=prediction.components[: likelihood_n_params * n_components],
445446
static_covariates=None,
446447
hierarchy=None,
448+
metadata=prediction.metadata,
447449
)

darts/models/forecasting/forecasting_model.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,12 @@ def _build_forecast_series(
593593
input_series if input_series is not None else self.training_series
594594
)
595595
return _build_forecast_series(
596-
points_preds,
597-
input_series,
598-
custom_components,
599-
with_static_covs,
600-
with_hierarchy,
601-
pred_start,
596+
points_preds=points_preds,
597+
input_series=input_series,
598+
custom_columns=custom_components,
599+
with_static_covs=with_static_covs,
600+
with_hierarchy=with_hierarchy,
601+
pred_start=pred_start,
602602
)
603603

604604
def _historical_forecasts_sanity_checks(self, *args: Any, **kwargs: Any) -> None:
@@ -1266,6 +1266,7 @@ def retrain_func(
12661266
if not predict_likelihood_parameters
12671267
else None
12681268
),
1269+
metadata=series_.metadata,
12691270
)
12701271
)
12711272
else:

darts/models/forecasting/kalman_forecaster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def _predict(
152152
columns=self.training_series.columns,
153153
static_covariates=self.training_series.static_covariates,
154154
hierarchy=self.training_series.hierarchy,
155+
metadata=self.training_series.metadata,
155156
)
156157

157158
series = series.append(series_future)

darts/models/forecasting/varima.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def _differentiate_series(self, series: TimeSeries) -> TimeSeries:
115115
df=series.to_dataframe(copy=False).diff().dropna(),
116116
static_covariates=series.static_covariates,
117117
hierarchy=series.hierarchy,
118+
metadata=series.metadata,
118119
)
119120
return series
120121

0 commit comments

Comments
 (0)