Skip to content
6 changes: 5 additions & 1 deletion skore/src/skore/sklearn/_cross_validation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ def _fit_estimator_reports(self) -> list[EstimatorReport]:
"might not contain all the expected results. "
f"Traceback: \n{e}"
)
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 e

console.print(
Panel(
Expand All @@ -222,7 +227,6 @@ def _fit_estimator_reports(self) -> list[EstimatorReport]:
border_style="cyan",
)
)

return estimator_reports

def clear_cache(self) -> None:
Expand Down
16 changes: 16 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,19 @@ def test_cross_validation_timings(
"Predict time test",
]
assert timings.columns.tolist() == expected_columns


class BrokenEstimator(ClassifierMixin, BaseEstimator):
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)

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