Skip to content

fix: preserve fitted order of future exogenous columns - #1270

Open
Anton Soloviev (antonsoo) wants to merge 1 commit into
Nixtla:mainfrom
antonsoo:fix/future-exog-column-order
Open

Anton Soloviev (antonsoo) wants to merge 1 commit into
Nixtla:mainfrom
antonsoo:fix/future-exog-column-order

Conversation

@antonsoo

Copy link
Copy Markdown

Select future covariate columns in the stored training order before converting X_df into a grouped array. The existing shape and required-name checks stay in place.

Currently the required features are checked by name but passed to the model in the incoming dataframe order. Reordering two named columns silently exchanges their fitted coefficients:

import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from statsforecast import StatsForecast
from statsforecast.models import SklearnModel
from statsforecast.utils import AirPassengersDF

df = AirPassengersDF.copy()
df["trend"] = (df.ds.dt.year - 1949) * 12 + df.ds.dt.month
df["season"] = np.sin(2 * np.pi * df.ds.dt.month / 12)
sf = StatsForecast(models=[SklearnModel(LinearRegression())], freq="ME")
sf.fit(df.iloc[:-12])
future = df.iloc[-12:].drop(columns="y")
expected = sf.predict(h=12, X_df=future)
actual = sf.predict(h=12, X_df=future[["unique_id", "ds", "season", "trend"]])
pd.testing.assert_frame_equal(actual, expected)

This fails on current main, with a maximum prediction difference of about 2,654 passengers, and passes with this change.

Validation:

  • Twelve before-failing regression cases cover forecast, fit_predict, and fit().predict(), pandas/Polars, and one/two workers.
  • Real AirPassengers and monthly CO2 data, with native ARIMA and scikit-learn regression, were checked against separately fitted single-series models. Across 72 dtype/backend/worker/horizon/API configurations, 1,824 incorrect reordered forecast values become zero; the maximum reference difference is 5.69e-14. All 72 correctly ordered controls retain identical result bytes.
  • Core and focused tests: 60 passed. Project pre-commit hooks pass.

The real-data checks establish covariate alignment, not improved forecast accuracy. Distributed Spark/Dask/Ray execution was not exercised.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T09:09:36.087732Z 58ef884 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants