Skip to content

Commit d789e83

Browse files
committed
lazy imports
1 parent 24582ef commit d789e83

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

openml/datasets/functions.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import openml._api_calls
1919
import openml.utils
20-
from openml._api import api_context
2120
from openml.exceptions import (
2221
OpenMLServerError,
2322
)
@@ -57,6 +56,8 @@ def list_qualities() -> list[str]:
5756
-------
5857
list
5958
"""
59+
from openml._api import api_context
60+
6061
return api_context.backend.datasets.list_qualities()
6162

6263

@@ -110,6 +111,8 @@ def list_datasets(
110111
If qualities are calculated for the dataset, some of
111112
these are also included as columns.
112113
"""
114+
from openml._api import api_context
115+
113116
listing_call = partial(
114117
api_context.backend.datasets.list,
115118
data_id=data_id,
@@ -344,6 +347,8 @@ def get_dataset(
344347
dataset : :class:`openml.OpenMLDataset`
345348
The downloaded dataset.
346349
"""
350+
from openml._api import api_context
351+
347352
if download_all_files:
348353
warnings.warn(
349354
"``download_all_files`` is experimental and is likely to break with new releases.",
@@ -654,6 +659,8 @@ def status_update(data_id: int, status: Literal["active", "deactivated"]) -> Non
654659
status : str,
655660
'active' or 'deactivated'
656661
"""
662+
from openml._api import api_context
663+
657664
legal_status = {"active", "deactivated"}
658665
if status not in legal_status:
659666
raise ValueError(f"Illegal status value. Legal values: {legal_status}")
@@ -732,6 +739,8 @@ def edit_dataset(
732739
-------
733740
Dataset id
734741
"""
742+
from openml._api import api_context
743+
735744
if not isinstance(data_id, int):
736745
raise TypeError(f"`data_id` must be of type `int`, not {type(data_id)}.")
737746

@@ -780,6 +789,8 @@ def fork_dataset(data_id: int) -> int:
780789
Dataset id of the forked dataset
781790
782791
"""
792+
from openml._api import api_context
793+
783794
return api_context.backend.datasets.fork(dataset_id=data_id)
784795

785796

@@ -804,6 +815,8 @@ def data_feature_add_ontology(data_id: int, index: int, ontology: str) -> bool:
804815
-------
805816
True or throws an OpenML server exception
806817
"""
818+
from openml._api import api_context
819+
807820
return api_context.backend.datasets.feature_add_ontology(data_id, index, ontology)
808821

809822

@@ -827,6 +840,8 @@ def data_feature_remove_ontology(data_id: int, index: int, ontology: str) -> boo
827840
-------
828841
True or throws an OpenML server exception
829842
"""
843+
from openml._api import api_context
844+
830845
return api_context.backend.datasets.feature_remove_ontology(data_id, index, ontology)
831846

832847

@@ -847,6 +862,8 @@ def _topic_add_dataset(data_id: int, topic: str) -> int:
847862
-------
848863
Dataset id
849864
"""
865+
from openml._api import api_context
866+
850867
return api_context.backend.datasets.add_topic(data_id, topic)
851868

852869

@@ -867,6 +884,8 @@ def _topic_delete_dataset(data_id: int, topic: str) -> int:
867884
-------
868885
Dataset id
869886
"""
887+
from openml._api import api_context
888+
870889
return api_context.backend.datasets.delete_topic(data_id, topic)
871890

872891

@@ -947,6 +966,8 @@ def _get_dataset_parquet(
947966
output_filename : Path, optional
948967
Location of the Parquet file if successfully downloaded, None otherwise.
949968
"""
969+
from openml._api import api_context
970+
950971
return api_context.backend.datasets.download_dataset_parquet(description, download_all_files)
951972

952973

@@ -977,6 +998,8 @@ def _get_dataset_arff(
977998
output_filename : Path
978999
Location of ARFF file.
9791000
"""
1001+
from openml._api import api_context
1002+
9801003
return api_context.backend.datasets.download_dataset_arff(description)
9811004

9821005

@@ -1005,7 +1028,7 @@ def _get_dataset_features_file(
10051028
Path
10061029
Path of the cached dataset feature file
10071030
"""
1008-
# cache directory not used here anymore
1031+
from openml._api import api_context
10091032

10101033
return api_context.backend.datasets.download_features_file(dataset_id)
10111034

@@ -1035,7 +1058,7 @@ def _get_dataset_qualities_file(
10351058
str
10361059
Path of the cached qualities file
10371060
"""
1038-
# cache directory not used here anymore
1061+
from openml._api import api_context
10391062

10401063
return api_context.backend.datasets.download_qualities_file(dataset_id)
10411064

@@ -1055,6 +1078,8 @@ def _get_online_dataset_arff(dataset_id: int) -> str | None:
10551078
str or None
10561079
A string representation of an ARFF file. Or None if file already exists.
10571080
"""
1081+
from openml._api import api_context
1082+
10581083
return api_context.backend.datasets.get_online_dataset_arff(dataset_id)
10591084

10601085

@@ -1072,6 +1097,8 @@ def _get_online_dataset_format(dataset_id: int) -> str:
10721097
str
10731098
Dataset format.
10741099
"""
1100+
from openml._api import api_context
1101+
10751102
return api_context.backend.datasets.get_online_dataset_format(dataset_id)
10761103

10771104

@@ -1091,4 +1118,6 @@ def delete_dataset(dataset_id: int) -> bool:
10911118
bool
10921119
True if the deletion was successful. False otherwise.
10931120
"""
1121+
from openml._api import api_context
1122+
10941123
return api_context.backend.datasets.delete(dataset_id)

0 commit comments

Comments
 (0)