@@ -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,14 +103,57 @@ 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_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+
127+ def list_tasks ():
128+ """Return a list of all tasks which are on OpenML.
129+
130+ Returns
131+ -------
132+ list
133+ A list of all tasks. Every task is represented by a
134+ dictionary containing the following information: task id,
135+ dataset id, task_type and status. If qualities are calculated for
136+ the associated dataset, some of these are also returned.
137+ """
138+ return _list_tasks ('task/list' )
139+
140+
141+ def _list_tasks (api_call ):
142+ return_code , xml_string = _perform_api_call (api_call )
109143 tasks_dict = xmltodict .parse (xml_string )
110144 # Minimalistic check if the XML is useful
111- assert tasks_dict ['oml:tasks' ]['@xmlns:oml' ] == \
112- 'http://openml.org/openml'
113- 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 ))
114157
115158 tasks = []
116159 procs = get_estimation_procedure_list ()
@@ -127,7 +170,8 @@ def list_tasks(task_type_id=1):
127170 if input ['@name' ] == 'estimation_procedure' :
128171 task [input ['@name' ]] = proc_dict [int (input ['#text' ])]['name' ]
129172 else :
130- task [input ['@name' ]] = input ['#text' ]
173+ value = input .get ('#text' )
174+ task [input ['@name' ]] = value
131175
132176 task [input ['@name' ]] = input ['#text' ]
133177
0 commit comments