Skip to content

fix(optimization): return inf when sampler picks no-feature config#638

Open
SAY-5 wants to merge 2 commits into
Nixtla:mainfrom
SAY-5:fix/optimization-no-features-637
Open

fix(optimization): return inf when sampler picks no-feature config#638
SAY-5 wants to merge 2 commits into
Nixtla:mainfrom
SAY-5:fix/optimization-no-features-637

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 2, 2026

Closes #637.

mlforecast_objective's objective runs config_fn(trial) and hands the resulting MLForecast config straight to the model fit even when the sampled hyperparameters specify no input features (lags, lag_transforms, and date_features all None). That produces a zero-column feature matrix and sklearn raises:

ValueError: at least one array or dtype is required

The v1.0.2 objective guarded against this case (optimization.py:78-83) and returned np.inf so Optuna treated the trial as worst-case and moved on. The guard was dropped in 1.0.3 (commit 7526c56) without a follow-up. This restores it.

Patch

Matches the snippet the reporter validated locally, plus a trial.set_user_attr("config", ...) so the skipped configs still show up in study.trials_dataframe() for diagnostics, keeps the existing diagnostics behavior consistent with successful trials.

Closes Nixtla#637.

`mlforecast_objective`'s `objective` runs `config_fn(trial)` and
hands the resulting MLForecast config straight to the model fit even
when the sampled hyperparameters specify no input features (`lags`,
`lag_transforms`, and `date_features` all `None`). That produces a
zero-column feature matrix and sklearn raises:

    ValueError: at least one array or dtype is required

The v1.0.2 objective guarded against this by returning `np.inf` so
Optuna treated the trial as worst-case and moved on (see
mlforecast/optimization.py:78-83 in v1.0.2). The guard was dropped in
1.0.3 (commit 7526c56) without a follow-up; restore it.

Patch matches the snippet the reporter validated locally, plus a
`set_user_attr("config")` so the skipped configs still show up in
`study.trials_dataframe()` for diagnostics.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 2, 2026

CLA assistant check
All committers have signed the CLA.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 5, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing SAY-5:fix/optimization-no-features-637 (58c74d2) with main (bed599b)

Open in CodSpeed

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 5, 2026

All 14 other matrix runs (macOS / Ubuntu / Windows × Python 3.10, 3.13 + macOS/Windows 3.14) pass. Only all-tests (ubuntu-latest, 3.14) hit the 6h0m runner cap during dependency install/test (Python 3.14 is freshly released and the wheel resolver is slow on Ubuntu); looks like an infra timeout rather than a real failure on this small one-config-skip patch. A retest should clear it.

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.

[Optimization] sklearn models fail with ValueError: at least one array or dtype is required

3 participants