Skip to content

Commit eff74f6

Browse files
committed
small changes requested by @mfeurer
1 parent 4b46d5a commit eff74f6

7 files changed

Lines changed: 28 additions & 26 deletions

File tree

openml/exceptions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ class PyOpenMLError(Exception):
22
def __init__(self, message):
33
super(PyOpenMLError, self).__init__(message)
44

5-
# class for when something is really wrong on the server (result did not parse to dict)
65
class OpenMLServerError(PyOpenMLError):
7-
"""Server didn't respond 200, contains unparsed error."""
6+
"""class for when something is really wrong on the server
7+
(result did not parse to dict), contains unparsed error."""
8+
89
def __init__(self, message):
910
message = "OpenML Server error: " + message
1011
super(OpenMLServerError, self).__init__(message)
1112

12-
# class for when the result of the server was not 200 (e.g., listing call w/o results)
13+
#
1314
class OpenMLServerException(OpenMLServerError):
14-
"""Server didn't respond 200."""
15+
"""exception for when the result of the server was
16+
not 200 (e.g., listing call w/o results). """
17+
1518
def __init__(self, code, message, additional=None):
1619
self.code = code
1720
self.additional = additional

openml/flows/functions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def list_flows(offset=None, size=None, tag=None):
7070
return _list_flows(api_call)
7171

7272

73-
def flow_exists(name, version):
74-
"""Retrieves the flow id of the flow uniquely identified by name+version.
73+
def flow_exists(name, external_version):
74+
"""Retrieves the flow id of the flow uniquely identified by name + external_version.
7575
7676
Parameter
7777
---------
@@ -91,18 +91,18 @@ def flow_exists(name, version):
9191
"""
9292
if not (isinstance(name, six.string_types) and len(name) > 0):
9393
raise ValueError('Argument \'name\' should be a non-empty string')
94-
if not (isinstance(name, six.string_types) and len(version) > 0):
94+
if not (isinstance(name, six.string_types) and len(external_version) > 0):
9595
raise ValueError('Argument \'version\' should be a non-empty string')
9696

9797
xml_response = _perform_api_call("flow/exists",
98-
data={'name': name, 'external_version': version})
98+
data={'name': name, 'external_version': external_version})
9999

100100
result_dict = xmltodict.parse(xml_response)
101101
flow_id = int(result_dict['oml:flow_exists']['oml:id'])
102102
if flow_id > 0:
103103
return flow_id
104104
else:
105-
return False;
105+
return False
106106

107107

108108
def _list_flows(api_call):

openml/runs/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525

26-
def run_task(task, model):
26+
def run_task(task, model, avoid_duplicate_runs=True):
2727
"""Performs a CV run on the dataset of the given task, using the split.
2828
2929
Parameters
@@ -46,12 +46,12 @@ def run_task(task, model):
4646
# TODO why doesn't this accept a flow as input? - this would make this more flexible!
4747
flow = sklearn_to_flow(model)
4848

49-
# returns flow id if the flow exists on the server, -1 otherwise
49+
# returns flow id if the flow exists on the server, False otherwise
5050
flow_id = flow_exists(flow.name, flow.external_version)
5151

5252
# skips the run if it already exists and the user opts for this in the config file.
5353
# also, if the flow is not present on the server, the check is not needed.
54-
if config.avoid_duplicate_runs and flow_id:
54+
if avoid_duplicate_runs and flow_id:
5555
flow = get_flow(flow_id)
5656
setup_id = setup_exists(flow, model)
5757
ids = _run_exists(task.task_id, setup_id)

openml/setups/functions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ def setup_exists(downloaded_flow, sklearn_model):
1111
---------
1212
1313
downloaded_flow : flow
14-
the openml flow object (should be downloaded from server.
15-
Otherwise also give flow id parameter)
14+
the openml flow object (should be downloaded from server)
1615
sklearn_model : BaseEstimator
1716
The base estimator that was used to create the flow. Will
1817
be used to extract parameter settings from.
1918
2019
Returns
2120
-------
22-
setup_id : int s
21+
setup_id : int
2322
setup id iff exists, False otherwise
2423
'''
2524

@@ -29,7 +28,7 @@ def setup_exists(downloaded_flow, sklearn_model):
2928
file_elements = {'description': ('description.arff',description)}
3029

3130
result = openml._api_calls._perform_api_call('/setup/exists/',
32-
file_elements = file_elements)
31+
file_elements=file_elements)
3332
result_dict = xmltodict.parse(result)
3433
setup_id = int(result_dict['oml:setup_exists']['oml:id'])
3534
if setup_id > 0:

tests/test_flows/test_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ def test_illegal_flow(self):
176176
('classif', sklearn.tree.DecisionTreeClassifier())])
177177
self.assertRaises(ValueError, openml.flows.sklearn_to_flow, illegal)
178178

179-
def test_nonexiting_flow_exists(self):
179+
def test_nonexisting_flow_exists(self):
180180
name = get_sentinel() + get_sentinel()
181181
version = get_sentinel()
182182

183183
flow_id = openml.flows.flow_exists(name, version)
184-
self.assertEquals(flow_id, False)
184+
self.assertFalse(flow_id)
185185

186-
def test_exiting_flow_exists(self):
186+
def test_existing_flow_exists(self):
187187
# create a flow
188188
sentinel = get_sentinel()
189189
nb = sklearn.naive_bayes.GaussianNB()

tests/test_runs/test_run_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestRun(TestBase):
2727

2828
def _perform_run(self, task_id, num_instances, clf):
2929
task = openml.tasks.get_task(task_id)
30-
run = openml.runs.run_task(task, clf)
30+
run = openml.runs.run_task(task, clf, openml.config.avoid_duplicate_runs)
3131
run_ = run.publish()
3232
self.assertEqual(run_, run)
3333
self.assertIsInstance(run.dataset_id, int)

tests/test_setups/test_setup_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import openml.exceptions
77
from openml.testing import TestBase
88

9+
from sklearn.ensemble import BaggingClassifier
10+
from sklearn.tree import DecisionTreeClassifier
11+
912
if sys.version_info[0] >= 3:
1013
from unittest import mock
1114
else:
@@ -27,8 +30,7 @@ def get_sentinel():
2730
class TestRun(TestBase):
2831

2932
def test_nonexisting_setup_exists(self):
30-
from sklearn.tree import DecisionTreeClassifier
31-
# first publish a nonexiting flow
33+
# first publish a non-existing flow
3234
sentinel = get_sentinel()
3335
dectree = DecisionTreeClassifier()
3436
flow = openml.flows.sklearn_to_flow(dectree)
@@ -38,12 +40,10 @@ def test_nonexisting_setup_exists(self):
3840
# although the flow exists, we can be sure there are no
3941
# setups (yet) as it hasn't been ran
4042
setup_id = openml.setups.setup_exists(flow, dectree)
41-
self.assertEquals(setup_id, False)
43+
self.assertFalse(setup_id)
4244

4345

4446
def test_existing_setup_exists(self):
45-
from sklearn.ensemble import BaggingClassifier
46-
from sklearn.tree import DecisionTreeClassifier
4747
# first publish a nonexiting flow
4848
bagging = BaggingClassifier(DecisionTreeClassifier(max_depth=5,
4949
min_samples_split=3),
@@ -57,7 +57,7 @@ def test_existing_setup_exists(self):
5757
# although the flow exists, we can be sure there are no
5858
# setups (yet) as it hasn't been ran
5959
setup_id = openml.setups.setup_exists(flow, bagging)
60-
self.assertEquals(setup_id, False)
60+
self.assertFalse(setup_id)
6161

6262
# now run the flow on an easy task:
6363
task = openml.tasks.get_task(115) #diabetes

0 commit comments

Comments
 (0)