Skip to content

Commit bcecb10

Browse files
committed
updated filter functionality
1 parent b954723 commit bcecb10

2 files changed

Lines changed: 72 additions & 5 deletions

File tree

openml/evaluations/functions.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,64 @@
33
from .._api_calls import _perform_api_call
44
from ..evaluations import OpenMLEvaluation
55

6-
def list_evaluations(function, task_id):
6+
def list_runs(function, offset=None, size=None, id=None, task=None, setup=None,
7+
flow=None, uploader=None, tag=None):
8+
"""List all run-evaluation pairs matching all of the given filters.
9+
10+
Perform API call `/evaluation/function{function}/{filters}
11+
12+
Parameters
13+
----------
14+
function : str
15+
the evaluation function. e.g., predictive_accuracy
16+
offset : int, optional
17+
the number of runs to skip, starting from the first
18+
size : int, optional
19+
the maximum number of runs to show
20+
21+
id : list, optional
22+
23+
task : list, optional
24+
25+
setup: list, optional
26+
27+
flow : list, optional
28+
29+
uploader : list, optional
30+
31+
tag : str, optional
32+
33+
Returns
34+
-------
35+
list
36+
List of found evaluations.
37+
"""
38+
39+
api_call = "evaluation/list/function/%s" %function
40+
if offset is not None:
41+
api_call += "/offset/%d" % int(offset)
42+
if size is not None:
43+
api_call += "/limit/%d" % int(size)
44+
if id is not None:
45+
api_call += "/run/%s" % ','.join([str(int(i)) for i in id])
46+
if task is not None:
47+
api_call += "/task/%s" % ','.join([str(int(i)) for i in task])
48+
if setup is not None:
49+
api_call += "/setup/%s" % ','.join([str(int(i)) for i in setup])
50+
if flow is not None:
51+
api_call += "/flow/%s" % ','.join([str(int(i)) for i in flow])
52+
if uploader is not None:
53+
api_call += "/uploader/%s" % ','.join([str(int(i)) for i in uploader])
54+
if tag is not None:
55+
api_call += "/tag/%s" % tag
56+
57+
return _list_evaluations(api_call)
58+
59+
60+
def _list_evaluations(api_call):
761
"""Helper function to parse API calls which are lists of runs"""
862

9-
xml_string = _perform_api_call("evaluation/list/function/%s/task/%d" %(function, task_id))
63+
xml_string = _perform_api_call(api_call)
1064

1165
evals_dict = xmltodict.parse(xml_string)
1266
# Minimalistic check if the XML is useful

tests/test_evaluations/test_evaluation_functions.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55

66
class TestEvaluationFunctions(TestBase):
77

8-
def test_evaluation_list(self):
8+
def test_evaluation_list_filter_task(self):
99
openml.config.server = self.production_server
1010

1111
task_id = 7312
1212

13-
res = openml.evaluations.list_evaluations("predictive_accuracy", task_id)
13+
evaluations = openml.evaluations.list_evaluations("predictive_accuracy", task_id=[task_id])
1414

15-
self.assertGreater(len(res), 100)
15+
self.assertGreater(len(evaluations), 100)
16+
for run_id in evaluations.keys():
17+
self.assertEquals(evaluations[run_id].task_id, task_id)
1618

19+
20+
def test_evaluation_list_filter_uploader(self):
21+
openml.config.server = self.production_server
22+
23+
uploader_id = 16
24+
25+
evaluations = openml.evaluations.list_evaluations("predictive_accuracy", uploader=[uploader_id])
26+
27+
self.assertGreater(len(evaluations), 100)
28+
for run_id in evaluations.keys():
29+
self.assertEquals(evaluations[run_id].uploader, uploader_id)

0 commit comments

Comments
 (0)