Skip to content
5 changes: 5 additions & 0 deletions skore/src/skore/sklearn/_cross_validation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def _fit_estimator_reports(self) -> list[EstimatorReport]:
border_style="cyan",
)
)
if len(estimator_reports) == 0:
raise RuntimeError(
"Cross-validation failed: no estimators were successfully fitted. "
"Please check your data, estimator, or cross-validation setup."
) from None

return estimator_reports

Expand Down
18 changes: 18 additions & 0 deletions skore/tests/unit/sklearn/test_cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,21 @@ def test_cross_validation_timings(
"Predict time test",
]
assert timings.columns.tolist() == expected_columns


class BrokenEstimator(BaseEstimator, ClassifierMixin):
def fit(self, X, y):
raise ValueError("Intentional failure for testing")

def predict(self, X):
return [0] * len(X)


def test_cross_validation_report_with_zero_estimators():
X, y = make_classification(n_samples=100, n_features=10, random_state=42)

with pytest.raises(
RuntimeError,
match="Cross-validation failed: no estimators were successfully fitted",
):
CrossValidationReport(BrokenEstimator(), X, y)