Repository: probabl-ai/skore

Issue:
We should bullet proof the `find_ml_task` in `EstimatorReport`
It is not an actual bug but reading again this line:

```python
self._ml_task = _find_ml_task(self._y_test, estimator=self._estimator)
```

in the initialization stage makes me think that we should double check that we are fine (and maybe more tests). Basically, since we allow `y_test` to be None sometimes, I want just to be sure that `estimator` is not in a stage where everything is unifitted and `None`.

From the top of the head, we should be fine because we should a fitted estimator when `y_test` is None but we should double check.

Discussion:

Patch:
diff --git a/skore/src/skore/sklearn/find_ml_task.py b/skore/src/skore/sklearn/find_ml_task.py
index 0af490d..7ba71f5 100644
--- a/skore/src/skore/sklearn/find_ml_task.py
+++ b/skore/src/skore/sklearn/find_ml_task.py
@@ -71,6 +71,9 @@ def _find_ml_task(y, estimator=None) -> MLTask:
                     if estimator.classes_.size > 2:
                         return "multiclass-classification"
             else:  # fallback on the target
+                if y is None:
+                    return "unsupported"
+
                 target_type = type_of_target(y)
                 if target_type == "binary":
                     return "binary-classification"


Test patch:
diff --git a/skore/tests/unit/sklearn/test_utils.py b/skore/tests/unit/sklearn/test_utils.py
index 631d645..680b748 100644
--- a/skore/tests/unit/sklearn/test_utils.py
+++ b/skore/tests/unit/sklearn/test_utils.py
@@ -62,3 +62,10 @@ def test_find_ml_task_with_estimator(X, y, estimator, expected_task, should_fit)
 )
 def test_find_ml_task_without_estimator(target, expected_task):
     assert _find_ml_task(target) == expected_task
+
+
+def test_find_ml_task_unfitted_estimator():
+    from sklearn.dummy import DummyClassifier
+
+    estimator = DummyClassifier()
+    assert _find_ml_task(None, estimator) == "unsupported"