From 4733589166b9c2a1a81f96c5f23ef032f9962af9 Mon Sep 17 00:00:00 2001 From: Jakub Krasuski Date: Sun, 4 Oct 2026 20:45:46 +0200 Subject: [PATCH] fix: keep all the features in pipeline when h is 0 --- tests/test_feature_engineering.py | 23 +++++++++++++++++++++++ utilsforecast/feature_engineering.py | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/tests/test_feature_engineering.py b/tests/test_feature_engineering.py index 48d13e5e..2989f3cb 100644 --- a/tests/test_feature_engineering.py +++ b/tests/test_feature_engineering.py @@ -179,3 +179,26 @@ def test_pipeline(setup_series, freq, setup_pipeline, setup_features): future_df.drop(columns="unique_id"), check_dtype=False, ) + + +@pytest.mark.parametrize("engine", ["pandas", "polars"]) +def test_pipeline_no_horizon(setup_series, setup_features, engine): + # with h=0 there are no future values, but every feature must be computed + series, series_pl = setup_series + individual_results = [f(series, freq="D", h=0) for f in setup_features] + expected = reduce_join( + [r[0] for r in individual_results], on=["unique_id", "ds", "y"] + ) + if engine == "pandas": + transformed, future = pipeline(series, features=setup_features, freq="D", h=0) + else: + transformed, future = pipeline( + series_pl, features=setup_features, freq="1d", h=0 + ) + transformed = transformed.to_pandas() + pd.testing.assert_frame_equal( + transformed.drop(columns="unique_id"), + expected.drop(columns="unique_id"), + check_dtype=False, + ) + assert future.shape == (0, 0) diff --git a/utilsforecast/feature_engineering.py b/utilsforecast/feature_engineering.py index febebf83..e1b61c2f 100644 --- a/utilsforecast/feature_engineering.py +++ b/utilsforecast/feature_engineering.py @@ -369,6 +369,10 @@ def pipeline( if transformed is None: transformed = f_transformed future = f_future + elif h == 0: + # the future dataframe is empty, so the features are the new columns + feat_cols = [c for c in f_transformed.columns if c not in df.columns] + transformed = ufp.horizontal_concat([transformed, f_transformed[feat_cols]]) else: feat_cols = [c for c in f_future.columns if c not in (id_col, time_col)] transformed = ufp.horizontal_concat([transformed, f_transformed[feat_cols]])