1717
1818import openml ._api_calls
1919import openml .utils
20+ from openml ._api import api_context
2021from openml .exceptions import (
2122 OpenMLServerError ,
2223)
@@ -56,8 +57,6 @@ def list_qualities() -> list[str]:
5657 -------
5758 list
5859 """
59- from openml ._api import api_context
60-
6160 return api_context .backend .datasets .list_qualities ()
6261
6362
@@ -111,8 +110,6 @@ def list_datasets(
111110 If qualities are calculated for the dataset, some of
112111 these are also included as columns.
113112 """
114- from openml ._api import api_context
115-
116113 listing_call = partial (
117114 api_context .backend .datasets .list ,
118115 data_id = data_id ,
@@ -375,8 +372,6 @@ def get_dataset(
375372 if did_cache_dir .exists ():
376373 _remove_cache_dir_for_id (DATASETS_CACHE_DIR_NAME , did_cache_dir )
377374
378- from openml ._api import api_context
379-
380375 return api_context .backend .datasets .get (
381376 dataset_id ,
382377 download_data ,
@@ -659,8 +654,6 @@ def status_update(data_id: int, status: Literal["active", "deactivated"]) -> Non
659654 status : str,
660655 'active' or 'deactivated'
661656 """
662- from openml ._api import api_context
663-
664657 legal_status = {"active" , "deactivated" }
665658 if status not in legal_status :
666659 raise ValueError (f"Illegal status value. Legal values: { legal_status } " )
@@ -739,8 +732,6 @@ def edit_dataset(
739732 -------
740733 Dataset id
741734 """
742- from openml ._api import api_context
743-
744735 if not isinstance (data_id , int ):
745736 raise TypeError (f"`data_id` must be of type `int`, not { type (data_id )} ." )
746737
@@ -789,8 +780,6 @@ def fork_dataset(data_id: int) -> int:
789780 Dataset id of the forked dataset
790781
791782 """
792- from openml ._api import api_context
793-
794783 return api_context .backend .datasets .fork (dataset_id = data_id )
795784
796785
@@ -815,8 +804,6 @@ def data_feature_add_ontology(data_id: int, index: int, ontology: str) -> bool:
815804 -------
816805 True or throws an OpenML server exception
817806 """
818- from openml ._api import api_context
819-
820807 return api_context .backend .datasets .feature_add_ontology (data_id , index , ontology )
821808
822809
@@ -840,8 +827,6 @@ def data_feature_remove_ontology(data_id: int, index: int, ontology: str) -> boo
840827 -------
841828 True or throws an OpenML server exception
842829 """
843- from openml ._api import api_context
844-
845830 return api_context .backend .datasets .feature_remove_ontology (data_id , index , ontology )
846831
847832
@@ -862,8 +847,6 @@ def _topic_add_dataset(data_id: int, topic: str) -> int:
862847 -------
863848 Dataset id
864849 """
865- from openml ._api import api_context
866-
867850 return api_context .backend .datasets .add_topic (data_id , topic )
868851
869852
@@ -884,8 +867,6 @@ def _topic_delete_dataset(data_id: int, topic: str) -> int:
884867 -------
885868 Dataset id
886869 """
887- from openml ._api import api_context
888-
889870 return api_context .backend .datasets .delete_topic (data_id , topic )
890871
891872
@@ -966,8 +947,6 @@ def _get_dataset_parquet(
966947 output_filename : Path, optional
967948 Location of the Parquet file if successfully downloaded, None otherwise.
968949 """
969- from openml ._api import api_context
970-
971950 return api_context .backend .datasets .download_dataset_parquet (description , download_all_files )
972951
973952
@@ -998,8 +977,6 @@ def _get_dataset_arff(
998977 output_filename : Path
999978 Location of ARFF file.
1000979 """
1001- from openml ._api import api_context
1002-
1003980 return api_context .backend .datasets .download_dataset_arff (description )
1004981
1005982
@@ -1029,7 +1006,6 @@ def _get_dataset_features_file(
10291006 Path of the cached dataset feature file
10301007 """
10311008 # cache directory not used here anymore
1032- from openml ._api import api_context
10331009
10341010 return api_context .backend .datasets .download_features_file (dataset_id )
10351011
@@ -1060,7 +1036,6 @@ def _get_dataset_qualities_file(
10601036 Path of the cached qualities file
10611037 """
10621038 # cache directory not used here anymore
1063- from openml ._api import api_context
10641039
10651040 return api_context .backend .datasets .download_qualities_file (dataset_id )
10661041
@@ -1080,12 +1055,7 @@ def _get_online_dataset_arff(dataset_id: int) -> str | None:
10801055 str or None
10811056 A string representation of an ARFF file. Or None if file already exists.
10821057 """
1083- dataset_xml = openml ._api_calls ._perform_api_call (f"data/{ dataset_id } " , "get" )
1084- # build a dict from the xml.
1085- # use the url from the dataset description and return the ARFF string
1086- return openml ._api_calls ._download_text_file (
1087- xmltodict .parse (dataset_xml )["oml:data_set_description" ]["oml:url" ],
1088- )
1058+ return api_context .backend .datasets .get_online_dataset_arff (dataset_id )
10891059
10901060
10911061# TODO used only in tests
@@ -1102,9 +1072,7 @@ def _get_online_dataset_format(dataset_id: int) -> str:
11021072 str
11031073 Dataset format.
11041074 """
1105- dataset_xml = openml ._api_calls ._perform_api_call (f"data/{ dataset_id } " , "get" )
1106- # build a dict from the xml and get the format from the dataset description
1107- return xmltodict .parse (dataset_xml )["oml:data_set_description" ]["oml:format" ].lower () # type: ignore
1075+ return api_context .backend .datasets .get_online_dataset_format (dataset_id )
11081076
11091077
11101078def delete_dataset (dataset_id : int ) -> bool :
@@ -1123,6 +1091,4 @@ def delete_dataset(dataset_id: int) -> bool:
11231091 bool
11241092 True if the deletion was successful. False otherwise.
11251093 """
1126- from openml ._api import api_context
1127-
11281094 return api_context .backend .datasets .delete (dataset_id )
0 commit comments