Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/statsforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ def _parse_X_level(
raise ValueError(
f"Expected X to have shape {expected_shape}, but got {X.shape}"
)
X = X[[self.id_col, self.time_col] + self._exog]
processed = ufp.process_df(X, self.id_col, self.time_col, None)
return GroupedArray(processed.data, processed.indptr), level

Expand Down
34 changes: 34 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import polars as pl
import polars.testing as pltest
import pytest
from sklearn.linear_model import LinearRegression
from statsforecast.core import (
ConformalIntervals,
GroupedArray,
Expand All @@ -34,6 +35,7 @@
SeasonalNaive,
SeasonalWindowAverage,
SimpleExponentialSmoothing,
SklearnModel,
WindowAverage,
)
from statsforecast.utils import AirPassengers as ap
Expand Down Expand Up @@ -1538,3 +1540,35 @@ def test_conf_intervals(n_jobs):
# # | eval: false
# # test number of jobs greater than the available cores
# test_conf_intervals(n_jobs=101)


@pytest.mark.parametrize("n_jobs", [1, 2])
@pytest.mark.parametrize("as_polars", [False, True])
@pytest.mark.parametrize("method", ["forecast", "fit_predict", "predict"])
def test_future_exog_column_order(n_jobs, as_polars, method):
rng = np.random.default_rng(0)
df = pd.DataFrame(
{
"unique_id": np.repeat(["a", "b"], 20),
"ds": np.tile(np.arange(20), 2),
"first": rng.normal(size=40),
"second": rng.normal(size=40),
}
)
df["y"] = 2 * df["first"] - 7 * df["second"]
train = df[df.ds < 17]
future = df[df.ds >= 17].drop(columns="y")
# Include an id/time permutation as well as reversing the two features.
future = future[["second", "ds", "first", "unique_id"]]
if as_polars:
train, future = pl.from_pandas(train), pl.from_pandas(future)
sf = StatsForecast(
models=[SklearnModel(LinearRegression())], freq=1, n_jobs=n_jobs
)
if method == "predict":
result = sf.fit(train).predict(h=3, X_df=future)
else:
result = getattr(sf, method)(df=train, h=3, X_df=future)
np.testing.assert_allclose(
result["LinearRegression"].to_numpy(), df.loc[df.ds >= 17, "y"]
)
Loading