Skip to content

Commit e264c9e

Browse files
committed
ADD /task/list/tag/{tag} api call
1 parent b430c73 commit e264c9e

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

doc/progress.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ API call implemented tested properly test
2424

2525
/task/{task} yes yes
2626
/task/list yes yes
27-
/task/list/type/{id}
28-
/task/list/tag/{tag}
27+
/task/list/type/{id} yes yes
28+
/task/list/tag/{tag} yes yes
2929
/task {POST}
3030
/task/tag
3131
/task/untag

openml/tasks/__init__.py

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

56
__all__ = ['OpenMLTask', 'get_task', 'list_tasks', 'list_tasks_by_type',
6-
'OpenMLSplit']
7+
'list_tasks_by_tag', 'OpenMLSplit']

openml/tasks/task_functions.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ def list_tasks_by_type(task_type_id):
106106
return _list_tasks("task/list/type/%d" % task_type_id)
107107

108108

109+
def list_tasks_by_tag(tag):
110+
"""Return all tasks having the given tag
111+
112+
Parameters
113+
----------
114+
tag : str
115+
116+
Returns
117+
-------
118+
list
119+
A list of all tasks having a give tag. Every task is represented by
120+
a dictionary containing the following information: task id,
121+
dataset id, task_type and status. If qualities are calculated for
122+
the associated dataset, some of these are also returned.
123+
"""
124+
return _list_tasks("task/list/tag/%s" % tag)
125+
126+
109127
def list_tasks():
110128
"""Return a list of all tasks which are on OpenML.
111129
@@ -124,9 +142,18 @@ def _list_tasks(api_call):
124142
return_code, xml_string = _perform_api_call(api_call)
125143
tasks_dict = xmltodict.parse(xml_string)
126144
# Minimalistic check if the XML is useful
127-
assert tasks_dict['oml:tasks']['@xmlns:oml'] == \
128-
'http://openml.org/openml'
129-
assert type(tasks_dict['oml:tasks']['oml:task']) == list
145+
if 'oml:tasks' not in tasks_dict:
146+
raise ValueError('Error in return XML, does not contain "oml:runs": %s'
147+
% str(tasks_dict))
148+
elif '@xmlns:oml' not in tasks_dict['oml:tasks']:
149+
raise ValueError('Error in return XML, does not contain '
150+
'"oml:runs"/@xmlns:oml: %s'
151+
% str(tasks_dict))
152+
elif tasks_dict['oml:tasks']['@xmlns:oml'] != 'http://openml.org/openml':
153+
raise ValueError('Error in return XML, value of '
154+
'"oml:runs"/@xmlns:oml is not '
155+
'"http://openml.org/openml": %s'
156+
% str(tasks_dict))
130157

131158
tasks = []
132159
procs = get_estimation_procedure_list()

tests/examples/test_OpenMLDemo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_notebook(self):
4545
msg = 'Error executing the notebook "%s". ' % notebook_filename
4646
msg += 'See notebook "%s" for the traceback.\n\n' % notebook_filename_out
4747
msg += e.traceback
48-
self.fail(msg)
48+
self.fail(msg)
4949
finally:
5050
with open(notebook_filename_out, mode='wt') as f:
5151
nbformat.write(nb, f)

tests/test_task.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def test_list_tasks_by_type(self):
2929
for task in tasks:
3030
self._check_task(task)
3131

32+
def test_list_tasks_by_tag(self):
33+
tasks = openml.tasks.list_tasks_by_tag('basic')
34+
self.assertGreaterEqual(len(tasks), 57)
35+
for task in tasks:
36+
self._check_task(task)
37+
3238
def test_get_task(self):
3339
task = openml.tasks.get_task(1)
3440
self.assertTrue(os.path.exists(

0 commit comments

Comments
 (0)