Skip to content

Commit b430c73

Browse files
committed
ADD /task/list/type/{id} api call
1 parent c3a3766 commit b430c73

4 files changed

Lines changed: 47 additions & 28 deletions

File tree

doc/progress.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ API call implemented tested properly test
1616
/data/features/{id} yes yes
1717
/data/qualities/{id} yes yes
1818
/data/list/ yes yes
19-
/data/list/tag/{tag}
19+
/data/list/tag/{tag} yes yes
2020
/data/upload/ yes yes
2121
/data/tag
2222
/data/untag

openml/tasks/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .task import OpenMLTask
22
from .split import OpenMLSplit
3-
from .task_functions import get_task, list_tasks
3+
from .task_functions import get_task, list_tasks, list_tasks_by_type
44

5-
__all__ = ['OpenMLTask', 'get_task', 'list_tasks', 'OpenMLSplit']
5+
__all__ = ['OpenMLTask', 'get_task', 'list_tasks', 'list_tasks_by_type',
6+
'OpenMLSplit']

openml/tasks/task_functions.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ def get_estimation_procedure_list():
8181
return procs
8282

8383

84-
def list_tasks(task_type_id=1):
85-
"""Return a list of all tasks which are on OpenML.
84+
def list_tasks_by_type(task_type_id):
85+
"""Return a list of all tasks for a given tasks type which are on OpenML.
8686
8787
Parameters
8888
----------
8989
task_type_id : int
9090
ID of the task type as detailed
91-
`here <http://openml.org/api/?f=openml.task.types>`_.
91+
`here <http://www.openml.org/search?type=task_type>`_.
9292
9393
Returns
9494
-------
95-
tasks : list
96-
A list of all tasks. Every task is represented by a
97-
dictionary containing the following information: task id,
95+
list
96+
A list of all tasks of the given task type. Every task is represented by
97+
a dictionary containing the following information: task id,
9898
dataset id, task_type and status. If qualities are calculated for
9999
the associated dataset, some of these are also returned.
100100
"""
@@ -103,9 +103,25 @@ def list_tasks(task_type_id=1):
103103
except:
104104
raise ValueError("Task Type ID is neither an Integer nor can be "
105105
"cast to an Integer.")
106+
return _list_tasks("task/list/type/%d" % task_type_id)
106107

107-
return_code, xml_string = _perform_api_call(
108-
"task/list/type/%d" % task_type_id)
108+
109+
def list_tasks():
110+
"""Return a list of all tasks which are on OpenML.
111+
112+
Returns
113+
-------
114+
list
115+
A list of all tasks. Every task is represented by a
116+
dictionary containing the following information: task id,
117+
dataset id, task_type and status. If qualities are calculated for
118+
the associated dataset, some of these are also returned.
119+
"""
120+
return _list_tasks('task/list')
121+
122+
123+
def _list_tasks(api_call):
124+
return_code, xml_string = _perform_api_call(api_call)
109125
tasks_dict = xmltodict.parse(xml_string)
110126
# Minimalistic check if the XML is useful
111127
assert tasks_dict['oml:tasks']['@xmlns:oml'] == \
@@ -127,7 +143,8 @@ def list_tasks(task_type_id=1):
127143
if input['@name'] == 'estimation_procedure':
128144
task[input['@name']] = proc_dict[int(input['#text'])]['name']
129145
else:
130-
task[input['@name']] = input['#text']
146+
value = input.get('#text')
147+
task[input['@name']] = value
131148

132149
task[input['@name']] = input['#text']
133150

tests/test_task.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@
77

88

99
class TestTask(TestBase):
10+
def _check_task(self, task):
11+
self.assertEqual(type(task), dict)
12+
self.assertGreaterEqual(len(task), 2)
13+
self.assertIn('did', task)
14+
self.assertIsInstance(task['did'], int)
15+
self.assertIn('status', task)
16+
self.assertTrue(is_string(task['status']))
17+
self.assertIn(task['status'],
18+
['in_preparation', 'active', 'deactivated'])
19+
1020
def test_list_tasks(self):
11-
# We can only perform a smoke test here because we test on dynamic
12-
# data from the internet...
13-
def check_task(task):
14-
self.assertEqual(type(task), dict)
15-
self.assertGreaterEqual(len(task), 2)
16-
self.assertIn('did', task)
17-
self.assertIsInstance(task['did'], int)
18-
self.assertIn('status', task)
19-
self.assertTrue(is_string(task['status']))
20-
self.assertIn(task['status'],
21-
['in_preparation', 'active', 'deactivated'])
21+
tasks = openml.tasks.list_tasks()
22+
self.assertGreaterEqual(len(tasks), 2000)
23+
for task in tasks:
24+
self._check_task(task)
2225

23-
# use a small task type as we cant limit tasks.
24-
# TODO inspect the tasks maybe?
25-
tasks = openml.tasks.list_tasks(task_type_id=3)
26+
def test_list_tasks_by_type(self):
27+
tasks = openml.tasks.list_tasks_by_type(task_type_id=3)
2628
self.assertGreaterEqual(len(tasks), 300)
2729
for task in tasks:
28-
check_task(task)
30+
self._check_task(task)
2931

3032
def test_get_task(self):
3133
task = openml.tasks.get_task(1)
32-
print(task)
3334
self.assertTrue(os.path.exists(
3435
os.path.join(os.getcwd(), "tasks", "1", "task.xml")))
3536
self.assertTrue(os.path.exists(

0 commit comments

Comments
 (0)