Skip to content

Commit 8672ffb

Browse files
[BUG] Fix Sklearn Models detection by safely importing openml-sklearn (#1556)
#### Metadata * Reference Issue: Fixes #1542 #### Details Fixed sklearn models detection by safely importing openml-sklearn at `openml/runs/__init__.py`
1 parent f9fb3a1 commit 8672ffb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

openml/extensions/functions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# License: BSD 3-Clause
22
from __future__ import annotations
33

4+
import importlib.util
45
from typing import TYPE_CHECKING, Any
56

67
# Need to implement the following by its full path because otherwise it won't be possible to
@@ -16,8 +17,9 @@
1617
SKLEARN_HINT = (
1718
"But it looks related to scikit-learn. "
1819
"Please install the OpenML scikit-learn extension (openml-sklearn) and try again. "
20+
"You can use `pip install openml-sklearn` for installation."
1921
"For more information, see "
20-
"https://github.com/openml/openml-sklearn?tab=readme-ov-file#installation"
22+
"https://docs.openml.org/python/extensions/"
2123
)
2224

2325

@@ -58,6 +60,10 @@ def get_extension_by_flow(
5860
-------
5961
Extension or None
6062
"""
63+
# import openml_sklearn to register SklearnExtension
64+
if importlib.util.find_spec("openml_sklearn"):
65+
import openml_sklearn # noqa: F401
66+
6167
candidates = []
6268
for extension_class in openml.extensions.extensions:
6369
if extension_class.can_handle_flow(flow):
@@ -103,6 +109,10 @@ def get_extension_by_model(
103109
-------
104110
Extension or None
105111
"""
112+
# import openml_sklearn to register SklearnExtension
113+
if importlib.util.find_spec("openml_sklearn"):
114+
import openml_sklearn # noqa: F401
115+
106116
candidates = []
107117
for extension_class in openml.extensions.extensions:
108118
if extension_class.can_handle_model(model):

0 commit comments

Comments
 (0)