Skip to content

[BUG] Fix CatBoost and sparse-horizon cross-validation with Polars#613

Open
janrth wants to merge 1 commit intoNixtla:mainfrom
janrth:bug/cross_validation_pl
Open

[BUG] Fix CatBoost and sparse-horizon cross-validation with Polars#613
janrth wants to merge 1 commit intoNixtla:mainfrom
janrth:bug/cross_validation_pl

Conversation

@janrth
Copy link
Copy Markdown
Contributor

@janrth janrth commented Apr 4, 2026

This PR fixes two Polars cross-validation issues in MLForecast:

CatBoostRegressor failed on Polars inputs because the shared fit/predict path passed polars.DataFrame objects directly into CatBoost, which only accepts pandas/numpy-style inputs.

Sparse-horizon cross-validation (horizons=[...]) failed on Polars because the expected-row validation used pandas-only .nunique() on a Polars series.

Changes to fix this:
In the shared model fit path, CatBoost inputs are converted from Polars to pandas before calling .fit(...).
In the shared prediction path, CatBoost inputs are likewise converted from Polars to pandas before calling .predict(...).
In sparse-horizon cross-validation, the expected series count now uses:
.nunique() for pandas
.n_unique() for Polars

Added targeted regression tests covering:

Polars cross-validation with a CatBoost-like estimator on the shared fit/predict path
Polars sparse-horizon cross-validation with refit=False

Solves #594

Checklist:

  • This PR has a meaningful title and a clear description.
  • The tests pass.
  • All linting tasks pass.
  • The notebooks are clean.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 4, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing janrth:bug/cross_validation_pl (fb4e287) with main (adcccd2)

Open in CodSpeed

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.

1 participant