Skip to content

Commit 3de0919

Browse files
committed
updates and req change
1 parent dc411dd commit 3de0919

5 files changed

Lines changed: 81 additions & 25 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<oml:task xmlns:oml="http://openml.org/openml">
2+
<oml:task_id>1</oml:task_id>
3+
<oml:task_name>Task 1: anneal (Supervised Classification)</oml:task_name>
4+
<oml:task_type_id>1</oml:task_type_id>
5+
<oml:task_type>Supervised Classification</oml:task_type>
6+
<oml:input name="source_data">
7+
<oml:data_set>
8+
<oml:data_set_id>1</oml:data_set_id>
9+
<oml:target_feature>class</oml:target_feature>
10+
</oml:data_set> </oml:input>
11+
<oml:input name="estimation_procedure">
12+
<oml:estimation_procedure>
13+
<oml:id>1</oml:id>
14+
<oml:type>crossvalidation</oml:type>
15+
<oml:data_splits_url>https://test.openml.org/api_splits/get/1/Task_1_splits.arff</oml:data_splits_url>
16+
<oml:parameter name="number_repeats">1</oml:parameter>
17+
<oml:parameter name="number_folds">10</oml:parameter>
18+
<oml:parameter name="percentage"></oml:parameter>
19+
<oml:parameter name="stratified_sampling">true</oml:parameter>
20+
</oml:estimation_procedure> </oml:input>
21+
<oml:input name="cost_matrix">
22+
<oml:cost_matrix></oml:cost_matrix> </oml:input>
23+
<oml:input name="evaluation_measures">
24+
<oml:evaluation_measures>
25+
<oml:evaluation_measure></oml:evaluation_measure>
26+
</oml:evaluation_measures> </oml:input>
27+
<oml:output name="predictions">
28+
<oml:predictions>
29+
<oml:format>ARFF</oml:format>
30+
<oml:feature name="repeat" type="integer"/>
31+
<oml:feature name="fold" type="integer"/>
32+
<oml:feature name="row_id" type="integer"/>
33+
<oml:feature name="confidence.classname" type="numeric"/>
34+
<oml:feature name="prediction" type="string"/>
35+
</oml:predictions> </oml:output>
36+
<oml:tag>OpenML100</oml:tag>
37+
<oml:tag>TestResourceV1API_test_tag_and_untag_1770372752545432</oml:tag>
38+
<oml:tag>test_tag_OpenMLTaskMethodsTest_17700286279390957</oml:tag>
39+
</oml:task>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Date": "Tue, 10 Feb 2026 15:45:22 GMT", "Server": "Apache/2.4.54 (Debian)", "X-Powered-By": "PHP/7.4.33", "Expires": "Thu, 19 Nov 1981 08:52:00 GMT", "Cache-Control": "no-store, no-cache, must-revalidate", "Pragma": "no-cache", "Vary": "Accept-Encoding", "Content-Encoding": "gzip", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept", "Content-Type": "text/xml; charset=utf-8", "Set-Cookie": "ci_session=71n03c5kbs3nr74l6uut7r2kohu6omq6; expires=Tue, 10-Feb-2026 17:45:22 GMT; Max-Age=7200; path=/; HttpOnly, cookiesession1=678B28D0FDBAF9389A2310E05536C9AA;Expires=Wed, 10 Feb 2027 15:45:22 GMT;Path=/;HttpOnly", "Keep-Alive": "timeout=300, max=100", "Connection": "Keep-Alive", "Content-Length": "765"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status_code": 200, "url": "https://test.openml.org/api/v1/xml/task/1", "reason": "OK", "encoding": "utf-8", "elapsed": 0.871917, "created_at": 1770738319.5877619, "request": {"method": "GET", "url": "https://test.openml.org/api/v1/xml/task/1", "headers": {"user-agent": "openml-python/0.16.0", "Accept-Encoding": "gzip, deflate", "Accept": "*/*", "Connection": "keep-alive"}, "body": null}}

tests/test_api/test_task.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,74 @@
1-
# License: BSD 3-Clause
21
from __future__ import annotations
32

43
import pytest
54
import pandas as pd
65
from openml._api.resources.task import TaskV1API, TaskV2API
6+
from openml._api.resources.base.fallback import FallbackProxy
77
from openml.exceptions import OpenMLNotSupportedError
88
from openml.testing import TestAPIBase
9-
from openml.tasks.task import TaskType
109
from openml.enums import APIVersion
10+
from openml.tasks.task import TaskType
11+
1112

12-
class TestTaskV1(TestAPIBase):
13+
class TestTaskV1API(TestAPIBase):
1314
def setUp(self):
1415
super().setUp()
15-
self.resource = TaskV1API(self.http_clients[APIVersion.V1])
16+
self.client = self.http_clients[APIVersion.V1]
17+
self.task = TaskV1API(self.client)
1618

1719
@pytest.mark.uses_test_server()
1820
def test_list_tasks(self):
1921
"""Verify V1 list endpoint returns a populated DataFrame."""
20-
tasks_df = self.resource.list(limit=5, offset=0)
22+
tasks_df = self.task.list(limit=5, offset=0)
2123
assert isinstance(tasks_df, pd.DataFrame)
2224
assert not tasks_df.empty
2325
assert "tid" in tasks_df.columns
2426

25-
@pytest.mark.uses_test_server()
26-
def test_estimation_procedure_list(self):
27-
"""Verify that estimation procedure list endpoint works."""
28-
procs = self.resource._get_estimation_procedure_list()
29-
assert isinstance(procs, list)
30-
assert len(procs) > 0
31-
assert "id" in procs[0]
32-
33-
class TestTaskV2(TestAPIBase):
27+
class TestTaskV2API(TestAPIBase):
3428
def setUp(self):
3529
super().setUp()
36-
self.resource = TaskV2API(self.http_clients[APIVersion.V2])
30+
self.client = self.http_clients[APIVersion.V2]
31+
self.task = TaskV2API(self.client)
3732

3833
@pytest.mark.uses_test_server()
3934
def test_list_tasks(self):
4035
"""Verify V2 list endpoint returns a populated DataFrame."""
4136
with pytest.raises(OpenMLNotSupportedError):
42-
self.resource.list(limit=5, offset=0)
37+
self.task.list(limit=5, offset=0)
4338

4439
class TestTasksCombined(TestAPIBase):
4540
def setUp(self):
4641
super().setUp()
47-
self.v1_resource = TaskV1API(self.http_clients[APIVersion.V1])
48-
self.v2_resource = TaskV2API(self.http_clients[APIVersion.V2])
42+
self.v1_client = self.http_clients[APIVersion.V1]
43+
self.v2_client = self.http_clients[APIVersion.V2]
44+
self.task_v1 = TaskV1API(self.v1_client)
45+
self.task_v2 = TaskV2API(self.v2_client)
46+
self.task_fallback = FallbackProxy(self.task_v1, self.task_v2)
4947

5048
def _get_first_tid(self, task_type: TaskType) -> int:
5149
"""Helper to find an existing task ID for a given type using the V1 resource."""
52-
tasks = self.v1_resource.list(limit=1, offset=0, task_type=task_type)
50+
tasks = self.task_v1.list(limit=1, offset=0, task_type=task_type)
5351
if tasks.empty:
5452
pytest.skip(f"No tasks of type {task_type} found on test server.")
5553
return int(tasks.iloc[0]["tid"])
5654

5755
@pytest.mark.uses_test_server()
58-
def test_v2_get_task(self):
59-
"""Verify that we can get a task from V2 API using a task ID found via V1."""
56+
def test_get_matches(self):
57+
"""Verify that we can get a task from V2 API and it matches V1."""
58+
# Refactored to match the 'test_get_matches' style from Reference
59+
tid = self._get_first_tid(TaskType.SUPERVISED_CLASSIFICATION)
60+
61+
output_v1 = self.task_v1.get(tid)
62+
output_v2 = self.task_v2.get(tid)
63+
64+
assert int(output_v1.task_id) == tid
65+
assert int(output_v2.task_id) == tid
66+
assert output_v1.task_id == output_v2.task_id
67+
assert output_v1.task_type == output_v2.task_type
68+
69+
@pytest.mark.uses_test_server()
70+
def test_get_fallback(self):
71+
"""Verify the fallback proxy works for retrieving tasks."""
6072
tid = self._get_first_tid(TaskType.SUPERVISED_CLASSIFICATION)
61-
task_v1 = self.v1_resource.get(tid)
62-
task_v2 = self.v2_resource.get(tid)
63-
assert int(task_v1.task_id) == tid
64-
assert int(task_v2.task_id) == tid
73+
output_fallback = self.task_fallback.get(tid)
74+
assert int(output_fallback.task_id) == tid

tests/test_tasks/test_task_functions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def test__get_task_live(self):
113113
# https://github.com/openml/openml-python/issues/378
114114
openml.tasks.get_task(34536)
115115

116+
@pytest.mark.uses_test_server()
117+
def test_get_task(self):
118+
task = openml.tasks.get_task(1, download_data=True) # anneal; crossvalidation
119+
assert isinstance(task, OpenMLTask)
120+
116121
@pytest.mark.uses_test_server()
117122
def test_get_task_lazy(self):
118123
task = openml.tasks.get_task(2, download_data=False) # anneal; crossvalidation

0 commit comments

Comments
 (0)