Skip to content

Commit d79fbe5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 20e37a2 commit d79fbe5

8 files changed

Lines changed: 29 additions & 38 deletions

File tree

openml/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# License: BSD 3-Clause
1919
from __future__ import annotations
2020

21+
from openml._get import get
22+
2123
from . import (
2224
_api_calls,
2325
config,
@@ -48,7 +50,6 @@
4850
OpenMLSupervisedTask,
4951
OpenMLTask,
5052
)
51-
from openml._get import get
5253

5354

5455
def populate_cache(

openml/_get.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# to discuss and possibly
55
# todo: add global get utility here
66
# in general, e.g., datasets will not have same name as models etc
7+
from __future__ import annotations
8+
79
from openml.models import get
810

911
__all__ = ["get"]

openml/base/_base_pkg.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
"""Base Packager class."""
22

3+
from __future__ import annotations
4+
35
import inspect
4-
from pathlib import Path
56
import sys
67
import textwrap
8+
from pathlib import Path
79

810
from skbase.base import BaseObject
911
from skbase.utils.dependencies import _check_estimator_deps
1012

1113

1214
class _BasePkg(BaseObject):
13-
1415
_tags = {
1516
"python_dependencies": None,
1617
"python_version": None,
@@ -50,15 +51,11 @@ def serialize(self):
5051

5152
cls_str = cls_str.encode("utf-8")
5253
exec(f"import {compress_method}")
53-
compressed_str = eval(f"{compress_method}.compress(cls_str)")
54-
55-
return compressed_str
54+
return eval(f"{compress_method}.compress(cls_str)")
5655

5756

5857
def _has_source(obj) -> bool:
59-
"""
60-
Return True if inspect.getsource(obj) should succeed.
61-
"""
58+
"""Return True if inspect.getsource(obj) should succeed."""
6259
module_name = getattr(obj, "__module__", None)
6360
if not module_name or module_name not in sys.modules:
6461
return False
@@ -82,7 +79,7 @@ def class_to_source(cls) -> str:
8279
-------
8380
str : complete definition of cls, as str.
8481
Imports are not contained or serialized.
85-
"""""
82+
""" ""
8683

8784
# Fast path: class has retrievable source
8885
if _has_source(cls):
@@ -111,7 +108,7 @@ def class_to_source(cls) -> str:
111108
lines.append(f" def {name}(self): ...")
112109
body_added = True
113110
else:
114-
lines.append(f" {name} = {repr(value)}")
111+
lines.append(f" {name} = {value!r}")
115112
body_added = True
116113

117114
if not body_added:

openml/models/_get.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
21
"""Model retrieval utility."""
32

3+
from __future__ import annotations
4+
45
from functools import lru_cache
56

67

@@ -22,14 +23,10 @@ def get(id: str):
2223
ModuleNotFoundError
2324
if dependencies of object to retrieve are not satisfied
2425
"""
25-
2626
id_lookup = _id_lookup()
2727
obj = id_lookup.get(id)
2828
if obj is None:
29-
raise ValueError(
30-
f"Error in openml.get, object with package id {id} "
31-
"does not exist."
32-
)
29+
raise ValueError(f"Error in openml.get, object with package id {id} " "does not exist.")
3330
return obj().materialize()
3431

3532

@@ -45,9 +42,7 @@ def _id_lookup_cached(obj_type=None):
4542
all_objs = _all_objects(obj_type=obj_type)
4643

4744
# todo: generalize that pkg can contain more than one object
48-
lookup_dict = {obj.get_class_tag("pkg_id"): obj for obj in all_objs}
49-
50-
return lookup_dict
45+
return {obj.get_class_tag("pkg_id"): obj for obj in all_objs}
5146

5247

5348
@lru_cache
@@ -56,8 +51,4 @@ def _all_objects(obj_type=None):
5651

5752
from openml.models.apis._classifier import _ModelPkgClassifier
5853

59-
clses = all_objects(
60-
object_types=_ModelPkgClassifier, package_name="openml", return_names=False
61-
)
62-
63-
return clses
54+
return all_objects(object_types=_ModelPkgClassifier, package_name="openml", return_names=False)

openml/models/apis/_classifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Base package for sklearn classifiers."""
22

3+
from __future__ import annotations
4+
35
from openml.models.base import _OpenmlModelPkg
46

57

68
class _ModelPkgClassifier(_OpenmlModelPkg):
7-
89
_tags = {
910
# tags specific to API type
1011
"pkg_obj_type": "classifier",

openml/models/base/_base.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Base model package class."""
22

3+
from __future__ import annotations
4+
35
from openml.base import _BasePkg
46

57

68
class _OpenmlModelPkg(_BasePkg):
7-
89
_obj = None
910

1011
def _materialize(self):
@@ -22,20 +23,18 @@ def _materialize(self):
2223
if pkg_obj == "reference":
2324
from skbase.utils.dependencies import _safe_import
2425

25-
obj = _safe_import(self._obj)
26-
return obj
26+
return _safe_import(self._obj)
2727

28-
elif pkg_obj == "code":
28+
if pkg_obj == "code":
2929
exec(self._obj)
3030

3131
return obj
3232

3333
# elif pkg_obj == "craft":
3434
# identify and call appropriate craft method
3535

36-
else:
37-
raise ValueError(
38-
'Error in package tag "pkg_obj", '
39-
'must be one of "reference", "code", "craft", '
40-
f'but found value {pkg_obj}, of type {type(pkg_obj)}'
41-
)
36+
raise ValueError(
37+
'Error in package tag "pkg_obj", '
38+
'must be one of "reference", "code", "craft", '
39+
f"but found value {pkg_obj}, of type {type(pkg_obj)}"
40+
)

openml/models/classification/auto_sklearn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Auto-sklearn classifier."""
22

3+
from __future__ import annotations
34

45
from openml.models.apis import _ModelPkgClassifier
56

67

78
class OpenmlPkg__AutoSklearnClassifier(_ModelPkgClassifier):
8-
99
_tags = {
1010
"pkg_id": "AutoSklearnClassifier",
1111
"python_dependencies": "auto-sklearn",

openml/models/classification/xgboost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Xgboost classifier."""
22

3+
from __future__ import annotations
34

45
from openml.models.apis import _ModelPkgClassifier
56

67

78
class OpenmlPkg__XGBClassifier(_ModelPkgClassifier):
8-
99
_tags = {
1010
"pkg_id": "XGBClassifier",
1111
"python_dependencies": "xgboost",

0 commit comments

Comments
 (0)