Skip to content

fix(xgboost): return error instead of panicking on empty training data - #448

Open
SAY-5 wants to merge 1 commit into
smartcorelib:mainfrom
SAY-5:fix-xgb-empty-data
Open

fix(xgboost): return error instead of panicking on empty training data#448
SAY-5 wants to merge 1 commit into
smartcorelib:mainfrom
SAY-5:fix-xgb-empty-data

Conversation

@SAY-5

@SAY-5 SAY-5 commented Aug 25, 2026

Copy link
Copy Markdown

Fixes #446

Checklist

  • My branch is up-to-date with main branch.
  • Everything works and tested on latest stable Rust.
  • Coverage and Linting have been applied

Current behaviour

XGRegressor::fit panics on a training set with zero rows. find_best_split runs 0..sorted_idxs.len() - 1, which underflows on an empty slice; in debug builds this is attempt to subtract with overflow and in release builds it surfaces as index out of bounds. A zero-row matrix is reachable through the public Array2::take, so this is reachable from safe user code.

New expected behaviour

fit validates that the training data has at least one row and returns Err(Failed::because(FailedError::ParametersError, ...)) for empty data, mirroring the existing subsample validation a few lines above. A model trained on no data is not useful, so this matches the error direction the reporter preferred. Non-empty inputs are unaffected. A regression test covers the empty-data case.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5
SAY-5 requested a review from Mec-iS as a code owner August 25, 2026 02:17
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.

XGRegressor::fit panics on a zero-row training set

1 participant