`from sklearn.model_selection import *` raises ImportError since 1.8.0
Introduce yourself
Hi, I'm a CS student and regular scikit-learn user, mostly through model_selection. I ran into this while star-importing the module in a notebook and traced it back to a specific commit. First time filing a bug here.
Describe the bug and give evidence about its user-facing impact
from sklearn.model_selection import * raises an ImportError on 1.8.0+. It worked in 1.7.2, and every other public submodule still star-imports fine.
The cause: HalvingGridSearchCV and HalvingRandomSearchCV are listed in __all__ (in sklearn/model_selection/__init__.py), but the module's __getattr__ deliberately raises ImportError for both until you import enable_halving_search_cv. Star-import pulls every name in __all__, so it hits that guard and fails. The two names were added to __all__ in #31847 (the ruff absolute-imports cleanup); before that they weren't exported.
Impact: any notebook or script doing from sklearn.model_selection import * breaks on upgrade to 1.8.0, with an error that looks unrelated to what the user actually did.
Steps/Code to Reproduce
from sklearn.model_selection import *Expected Results
Star-import succeeds like it did in 1.7.2, without exporting the experimental Halving classes.
Actual Results
Traceback (most recent call last):
File "<string>", line 1, in <module>
File ".../sklearn/model_selection/__init__.py", line 100, in __getattr__
raise ImportError(
ImportError: HalvingGridSearchCV is experimental and the API might change without any deprecation cycle. To use it, you need to explicitly import enable_halving_search_cv:
from sklearn.experimental import enable_halving_search_cvVersions
System:
python: 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
machine: Windows-11-10.0.26200-SP0
Python dependencies:
sklearn: 1.10.dev0
pip: 25.0.1
numpy: 2.6.0.dev0
scipy: 2.0.0.dev0
pandas: 3.1.0.dev0+2081.ge909fc44ba
joblib: 1.6.0
threadpoolctl: 3.7.0
narwhals: 2.26.0
Also reproduces on 1.8.0.Interest in fixing the bug
Happy to open a PR. Plan: drop the two names from __all__ and keep them in the TYPE_CHECKING import with # noqa: F401, the way 1.7.2 had it.
Source: scikit-learn/scikit-learn