-
-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathresources.py
More file actions
223 lines (164 loc) · 6.09 KB
/
resources.py
File metadata and controls
223 lines (164 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from __future__ import annotations
import builtins
from abc import abstractmethod
from collections.abc import Iterable
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal
if TYPE_CHECKING:
import pandas as pd
from openml.datasets.dataset import OpenMLDataFeature, OpenMLDataset
from openml.enums import ResourceType
from .base import ResourceAPI
if TYPE_CHECKING:
from openml.estimation_procedures import OpenMLEstimationProcedure
from openml.evaluations import OpenMLEvaluation
from openml.flows.flow import OpenMLFlow
from openml.setups.setup import OpenMLSetup
class DatasetAPI(ResourceAPI):
"""Abstract API interface for dataset resources."""
resource_type: ResourceType = ResourceType.DATASET
@abstractmethod
def get( # noqa: PLR0913
self,
dataset_id: int,
download_data: bool = False, # noqa: FBT002
cache_format: Literal["pickle", "feather"] = "pickle",
download_qualities: bool = False, # noqa: FBT002
download_features_meta_data: bool = False, # noqa: FBT002
download_all_files: bool = False, # noqa: FBT002
force_refresh_cache: bool = False, # noqa: FBT002
) -> OpenMLDataset: ...
@abstractmethod
def list(
self,
limit: int,
offset: int,
*,
data_id: list[int] | None = None, # type: ignore
**kwargs: Any,
) -> pd.DataFrame: ...
@abstractmethod
def edit( # noqa: PLR0913
self,
dataset_id: int,
description: str | None = None,
creator: str | None = None,
contributor: str | None = None,
collection_date: str | None = None,
language: str | None = None,
default_target_attribute: str | None = None,
ignore_attribute: str | list[str] | None = None, # type: ignore
citation: str | None = None,
row_id_attribute: str | None = None,
original_data_url: str | None = None,
paper_url: str | None = None,
) -> int: ...
@abstractmethod
def fork(self, dataset_id: int) -> int: ...
@abstractmethod
def status_update(self, dataset_id: int, status: Literal["active", "deactivated"]) -> None: ...
@abstractmethod
def list_qualities(self) -> builtins.list[str]: ...
@abstractmethod
def feature_add_ontology(self, dataset_id: int, index: int, ontology: str) -> bool: ...
@abstractmethod
def feature_remove_ontology(self, dataset_id: int, index: int, ontology: str) -> bool: ...
@abstractmethod
def get_features(self, dataset_id: int) -> dict[int, OpenMLDataFeature]: ...
@abstractmethod
def get_qualities(self, dataset_id: int) -> dict[str, float] | None: ...
@abstractmethod
def parse_features_file(
self, features_file: Path, features_pickle_file: Path
) -> dict[int, OpenMLDataFeature]: ...
@abstractmethod
def parse_qualities_file(
self, qualities_file: Path, qualities_pickle_file: Path
) -> dict[str, float]: ...
@abstractmethod
def _download_file(self, url_ext: str) -> Path: ...
@abstractmethod
def download_features_file(self, dataset_id: int) -> Path: ...
@abstractmethod
def download_qualities_file(self, dataset_id: int) -> Path: ...
@abstractmethod
def download_dataset_parquet(
self,
description: dict | OpenMLDataset,
download_all_files: bool = False, # noqa: FBT002
) -> Path | None: ...
@abstractmethod
def download_dataset_arff(
self,
description: dict | OpenMLDataset,
) -> Path: ...
@abstractmethod
def add_topic(self, dataset_id: int, topic: str) -> int: ...
@abstractmethod
def delete_topic(self, dataset_id: int, topic: str) -> int: ...
@abstractmethod
def get_online_dataset_format(self, dataset_id: int) -> str: ...
@abstractmethod
def get_online_dataset_arff(self, dataset_id: int) -> str | None: ...
class TaskAPI(ResourceAPI):
"""Abstract API interface for task resources."""
resource_type: ResourceType = ResourceType.TASK
class EvaluationMeasureAPI(ResourceAPI):
"""Abstract API interface for evaluation measure resources."""
resource_type: ResourceType = ResourceType.EVALUATION_MEASURE
@abstractmethod
def list(self) -> list[str]: ...
class EstimationProcedureAPI(ResourceAPI):
"""Abstract API interface for estimation procedure resources."""
resource_type: ResourceType = ResourceType.ESTIMATION_PROCEDURE
@abstractmethod
def list(self) -> list[OpenMLEstimationProcedure]: ...
class EvaluationAPI(ResourceAPI):
"""Abstract API interface for evaluation resources."""
resource_type: ResourceType = ResourceType.EVALUATION
@abstractmethod
def list( # noqa: PLR0913
self,
limit: int,
offset: int,
*,
function: str,
tasks: list | None = None,
setups: list | None = None,
flows: list | None = None,
runs: list | None = None,
uploaders: list | None = None,
study: int | None = None,
sort_order: str | None = None,
**kwargs: Any,
) -> list[OpenMLEvaluation]: ...
class FlowAPI(ResourceAPI):
"""Abstract API interface for flow resources."""
resource_type: ResourceType = ResourceType.FLOW
class StudyAPI(ResourceAPI):
"""Abstract API interface for study resources."""
resource_type: ResourceType = ResourceType.STUDY
class RunAPI(ResourceAPI):
"""Abstract API interface for run resources."""
resource_type: ResourceType = ResourceType.RUN
class SetupAPI(ResourceAPI):
"""Abstract API interface for setup resources."""
resource_type: ResourceType = ResourceType.SETUP
@abstractmethod
def list(
self,
limit: int,
offset: int,
*,
setup: Iterable[int] | None = None,
flow: int | None = None,
tag: str | None = None,
) -> list[OpenMLSetup]: ...
@abstractmethod
def get(self, setup_id: int) -> OpenMLSetup: ...
@abstractmethod
def exists(
self,
flow: OpenMLFlow,
param_settings: builtins.list[dict[str, Any]],
) -> int | bool: ...