Skip to content

Commit 24ea494

Browse files
committed
Merge main fix conflict
2 parents d38dca3 + fabbc28 commit 24ea494

15 files changed

Lines changed: 1586 additions & 500 deletions

File tree

openml/_api/clients/http.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import Any, cast
1313
from urllib.parse import urlencode, urljoin, urlparse
1414

15-
import arff
1615
import requests
1716
import xmltodict
1817
from requests import Response
@@ -93,28 +92,32 @@ def _key_to_path(self, key: str) -> Path:
9392
def _get_body_filename_from_response(self, response: Response) -> str:
9493
content_type = response.headers.get("Content-Type", "").lower()
9594

95+
# check for .json
9696
if "application/json" in content_type:
9797
return "body.json"
9898

99+
# check for .xml
99100
if "text/xml" in content_type:
100101
return "body.xml"
101102

103+
# check for .zip
102104
if response.content.startswith(b"PK\x03\x04"):
103105
return "body.zip"
104106

105-
try:
106-
arff.loads(response.text)
107-
return "body.arff"
108-
except arff.ArffException:
109-
pass
107+
# check for .arff
108+
for raw_line in response.text.splitlines():
109+
stripped_line = raw_line.strip()
110+
# skip empty lines and comments
111+
if not stripped_line or stripped_line.startswith("%"):
112+
continue
113+
if stripped_line.lower().startswith("@relation"):
114+
return "body.arff"
115+
break
110116

111117
return "body.txt"
112118

113119
def _get_body_filename_from_path(self, path: Path) -> str:
114-
candidates = []
115-
for p in path.iterdir():
116-
if p.name.startswith("body.") and len(p.suffixes) == 1:
117-
candidates.append(p)
120+
candidates = [p for p in path.glob("body.*") if len(p.suffixes) == 1]
118121

119122
if not candidates:
120123
raise FileNotFoundError(f"No body file found in path: {path}")

openml/_api/resources/base/resources.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from openml.estimation_procedures import OpenMLEstimationProcedure
1919
from openml.evaluations import OpenMLEvaluation
2020
from openml.flows.flow import OpenMLFlow
21+
from openml.runs.run import OpenMLRun
2122
from openml.setups.setup import OpenMLSetup
23+
from openml.tasks.task import TaskType
2224

2325

2426
class DatasetAPI(ResourceAPI):
@@ -191,6 +193,21 @@ class FlowAPI(ResourceAPI):
191193

192194
resource_type: ResourceType = ResourceType.FLOW
193195

196+
@abstractmethod
197+
def get(self, flow_id: int, *, reset_cache: bool = False) -> OpenMLFlow: ...
198+
199+
@abstractmethod
200+
def list(
201+
self,
202+
limit: int | None = None,
203+
offset: int | None = None,
204+
tag: str | None = None,
205+
uploader: str | None = None,
206+
) -> pd.DataFrame: ...
207+
208+
@abstractmethod
209+
def exists(self, name: str, external_version: str) -> int | bool: ...
210+
194211

195212
class StudyAPI(ResourceAPI):
196213
"""Abstract API interface for study resources."""
@@ -214,6 +231,46 @@ class RunAPI(ResourceAPI):
214231

215232
resource_type: ResourceType = ResourceType.RUN
216233

234+
@abstractmethod
235+
def get(
236+
self,
237+
run_id: int,
238+
*,
239+
reset_cache: bool = False,
240+
) -> OpenMLRun: ...
241+
242+
@abstractmethod
243+
def list( # type: ignore[valid-type] # noqa: PLR0913
244+
self,
245+
limit: int,
246+
offset: int,
247+
*,
248+
ids: builtins.list[int] | None = None,
249+
task: builtins.list[int] | None = None,
250+
setup: builtins.list[int] | None = None,
251+
flow: builtins.list[int] | None = None,
252+
uploader: builtins.list[int] | None = None,
253+
study: int | None = None,
254+
tag: str | None = None,
255+
display_errors: bool = False,
256+
task_type: TaskType | int | None = None,
257+
) -> pd.DataFrame: ...
258+
259+
@abstractmethod
260+
def download_text_file(
261+
self,
262+
source: str,
263+
*,
264+
md5_checksum: str | None = None,
265+
) -> str: ...
266+
267+
@abstractmethod
268+
def file_id_to_url(
269+
self,
270+
file_id: int,
271+
filename: str | None = None,
272+
) -> str: ...
273+
217274

218275
class SetupAPI(ResourceAPI):
219276
"""Abstract API interface for setup resources."""

0 commit comments

Comments
 (0)