Skip to content

Commit 96fedbe

Browse files
committed
Incompatible task / flows are uploaded with error message
1 parent e0f4585 commit 96fedbe

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

openml/runs/functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def run_task(task, model):
5050

5151
# execute the run
5252
run = OpenMLRun(task_id=task.task_id, flow_id=None, dataset_id=dataset.dataset_id, model=model)
53-
run.data_content, run.trace_content = _run_task_get_arffcontent(model, task, class_labels)
53+
54+
try:
55+
run.data_content, run.trace_content = _run_task_get_arffcontent(model, task, class_labels)
56+
except AttributeError as message:
57+
run.error_message = str(message)
5458

5559
# now generate the flow
5660
flow = sklearn_to_flow(model)

openml/runs/run.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, task_id, flow_id, dataset_id, setup_string=None,
4343
self.detailed_evaluations = detailed_evaluations
4444
self.data_content = data_content
4545
self.trace_content = trace_content
46+
self.error_message = None
4647
self.task = task
4748
self.flow = flow
4849
self.run_id = run_id
@@ -136,12 +137,13 @@ def publish(self):
136137
if self.flow_id is None:
137138
raise PyOpenMLError("OpenMLRun obj does not contain a flow id. (Should have been added while executing the task.) ");
138139

139-
140-
predictions = arff.dumps(self._generate_arff_dict())
141140
description_xml = self._create_description_xml()
141+
file_elements = {'description': ("description.xml", description_xml)}
142+
143+
if self.error_message is None:
144+
predictions = arff.dumps(self._generate_arff_dict())
145+
file_elements['predictions'] = ("predictions.arff", predictions)
142146

143-
file_elements = {'predictions': ("predictions.arff", predictions),
144-
'description': ("description.xml", description_xml)}
145147
if self.trace_content is not None:
146148
trace_arff = arff.dumps(self._generate_trace_arff_dict(self.model))
147149
file_elements['trace'] = ("trace.arff", trace_arff)
@@ -175,6 +177,7 @@ def _create_description_xml(self):
175177
description = _to_dict(taskid=self.task_id, flow_id=self.flow_id,
176178
setup_string=_create_setup_string(self.model),
177179
parameter_settings=openml_param_settings,
180+
error_message=self.error_message,
178181
tags=tags)
179182
description_xml = xmltodict.unparse(description, pretty=True)
180183
return description_xml
@@ -256,7 +259,7 @@ def _get_version_information():
256259
return [python_version, sklearn_version, numpy_version, scipy_version]
257260

258261

259-
def _to_dict(taskid, flow_id, setup_string, parameter_settings, tags):
262+
def _to_dict(taskid, flow_id, setup_string, error_message, parameter_settings, tags):
260263
""" Creates a dictionary corresponding to the desired xml desired by openML
261264
262265
Parameters
@@ -280,6 +283,8 @@ def _to_dict(taskid, flow_id, setup_string, parameter_settings, tags):
280283
description['oml:run']['@xmlns:oml'] = 'http://openml.org/openml'
281284
description['oml:run']['oml:task_id'] = taskid
282285
description['oml:run']['oml:flow_id'] = flow_id
286+
if error_message is not None:
287+
description['oml:run']['oml:error_message'] = error_message
283288
description['oml:run']['oml:parameter_setting'] = parameter_settings
284289
description['oml:run']['oml:tag'] = tags # Tags describing the run
285290
# description['oml:run']['oml:output_data'] = 0;

tests/test_runs/test_run_functions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def test_run_regression_on_classif_task(self):
3535

3636
clf = LinearRegression()
3737
task = openml.tasks.get_task(task_id)
38-
self.assertRaises(AttributeError, openml.runs.run_task, task=task, model=clf)
38+
run = openml.runs.run_task(task=task, model=clf)
39+
run.publish()
40+
41+
# TODO: download and check whether it really contains the error message
42+
#downloaded_run = openml.runs.get_run(run.run_id)
3943

4044
@mock.patch('openml.flows.sklearn_to_flow')
4145
def test_check_erronous_sklearn_flow_fails(self, sklearn_to_flow_mock):

0 commit comments

Comments
 (0)