Skip to content

Commit a416fbd

Browse files
committed
_get_estimation_procedure_list work
1 parent edde570 commit a416fbd

4 files changed

Lines changed: 3 additions & 109 deletions

File tree

openml/_api/resources/base/resources.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
if TYPE_CHECKING:
1313
import pandas as pd
1414

15-
from openml.estimation_procedures import OpenMLEstimationProcedure
16-
from openml.evaluations import OpenMLEvaluation
15+
from openml import OpenMLEvaluation
1716
from openml.flows.flow import OpenMLFlow
1817
from openml.setups.setup import OpenMLSetup
1918
from openml.tasks.task import OpenMLTask, TaskType
@@ -88,9 +87,6 @@ class EstimationProcedureAPI(ResourceAPI):
8887

8988
resource_type: ResourceType = ResourceType.ESTIMATION_PROCEDURE
9089

91-
@abstractmethod
92-
def list(self) -> list[OpenMLEstimationProcedure]: ...
93-
9490

9591
class EvaluationAPI(ResourceAPI):
9692
"""Abstract API interface for evaluation resources."""

openml/_api/resources/task.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
import xmltodict
88

9-
import openml
9+
from openml.tasks.functions import _get_estimation_procedure_list
1010
from openml.tasks.task import (
1111
OpenMLClassificationTask,
1212
OpenMLClusteringTask,
@@ -19,62 +19,6 @@
1919
from .base import ResourceV1API, ResourceV2API, TaskAPI
2020

2121

22-
def _get_estimation_procedure_list() -> list[dict[str, Any]]:
23-
"""Return a list of all estimation procedures which are on OpenML.
24-
25-
Returns
26-
-------
27-
procedures : list
28-
A list of all estimation procedures. Every procedure is represented by
29-
a dictionary containing the following information: id, task type id,
30-
name, type, repeats, folds, stratified.
31-
"""
32-
url_suffix = "estimationprocedure/list"
33-
xml_string = openml._api_calls._perform_api_call(url_suffix, "get")
34-
35-
procs_dict = xmltodict.parse(xml_string)
36-
# Minimalistic check if the XML is useful
37-
if "oml:estimationprocedures" not in procs_dict:
38-
raise ValueError("Error in return XML, does not contain tag oml:estimationprocedures.")
39-
40-
if "@xmlns:oml" not in procs_dict["oml:estimationprocedures"]:
41-
raise ValueError(
42-
"Error in return XML, does not contain tag "
43-
"@xmlns:oml as a child of oml:estimationprocedures.",
44-
)
45-
46-
if procs_dict["oml:estimationprocedures"]["@xmlns:oml"] != "http://openml.org/openml":
47-
raise ValueError(
48-
"Error in return XML, value of "
49-
"oml:estimationprocedures/@xmlns:oml is not "
50-
"http://openml.org/openml, but {}".format(
51-
str(procs_dict["oml:estimationprocedures"]["@xmlns:oml"])
52-
),
53-
)
54-
55-
procs: list[dict[str, Any]] = []
56-
for proc_ in procs_dict["oml:estimationprocedures"]["oml:estimationprocedure"]:
57-
task_type_int = int(proc_["oml:ttid"])
58-
try:
59-
task_type_id = TaskType(task_type_int)
60-
procs.append(
61-
{
62-
"id": int(proc_["oml:id"]),
63-
"task_type_id": task_type_id,
64-
"name": proc_["oml:name"],
65-
"type": proc_["oml:type"],
66-
},
67-
)
68-
except ValueError as e:
69-
warnings.warn(
70-
f"Could not create task type id for {task_type_int} due to error {e}",
71-
RuntimeWarning,
72-
stacklevel=2,
73-
)
74-
75-
return procs
76-
77-
7822
def _create_task_from_xml(xml: str) -> OpenMLTask:
7923
"""Create a task given a xml string.
8024

openml/tasks/functions.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# License: BSD 3-Clause
22
from __future__ import annotations
33

4-
import os
5-
import re
64
import warnings
75
from functools import partial
86
from typing import TYPE_CHECKING, Any
97

108
import pandas as pd
119

1210
import openml.utils
13-
from openml._api.resources.task import _create_task_from_xml
1411
from openml.datasets import get_dataset
15-
from openml.exceptions import OpenMLCacheException
1612

1713
from .task import (
1814
OpenMLClassificationTask,
@@ -30,48 +26,6 @@
3026
TASKS_CACHE_DIR_NAME = "tasks"
3127

3228

33-
def _get_cached_tasks() -> dict[int, OpenMLTask]:
34-
"""Return a dict of all the tasks which are cached locally.
35-
36-
Returns
37-
-------
38-
tasks : OrderedDict
39-
A dict of all the cached tasks. Each task is an instance of
40-
OpenMLTask.
41-
"""
42-
task_cache_dir = openml.utils._create_cache_directory(TASKS_CACHE_DIR_NAME)
43-
directory_content = os.listdir(task_cache_dir) # noqa: PTH208
44-
directory_content.sort()
45-
46-
# Find all dataset ids for which we have downloaded the dataset
47-
# description
48-
tids = (int(did) for did in directory_content if re.match(r"[0-9]*", did))
49-
return {tid: _get_cached_task(tid) for tid in tids}
50-
51-
52-
def _get_cached_task(tid: int) -> OpenMLTask:
53-
"""Return a cached task based on the given id.
54-
55-
Parameters
56-
----------
57-
tid : int
58-
Id of the task.
59-
60-
Returns
61-
-------
62-
OpenMLTask
63-
"""
64-
tid_cache_dir = openml.utils._create_cache_directory_for_id(TASKS_CACHE_DIR_NAME, tid)
65-
66-
task_xml_path = tid_cache_dir / "task.xml"
67-
try:
68-
with task_xml_path.open(encoding="utf8") as fh:
69-
return _create_task_from_xml(fh.read())
70-
except OSError as e:
71-
openml.utils._remove_cache_dir_for_id(TASKS_CACHE_DIR_NAME, tid_cache_dir)
72-
raise OpenMLCacheException(f"Task file for tid {tid} not cached") from e
73-
74-
7529
def _get_estimation_procedure_list() -> list[dict[str, Any]]:
7630
"""Return a list of all estimation procedures which are on OpenML.
7731

tests/test_tasks/test_task_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def tearDown(self):
2929

3030
@pytest.mark.test_server()
3131
def test__get_estimation_procedure_list(self):
32-
estimation_procedures = openml._api.resources.task._get_estimation_procedure_list()
32+
estimation_procedures = openml.tasks.functions._get_estimation_procedure_list()
3333
assert isinstance(estimation_procedures, list)
3434
assert isinstance(estimation_procedures[0], dict)
3535
assert estimation_procedures[0]["task_type_id"] == TaskType.SUPERVISED_CLASSIFICATION

0 commit comments

Comments
 (0)