Skip to content

Commit 994847c

Browse files
committed
Fixed the upload_run method to be more clear.
1 parent bc438d6 commit 994847c

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

openml/apiconnector.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -936,19 +936,13 @@ def upload_flow(self, description, file_path):
936936
raise e
937937
return return_code, dataset_xml
938938

939-
def upload_run(self, files):
940-
file_dictionary = {}
941-
if 'predictions' in files:
942-
try:
943-
for key, value in files.items():
944-
file_dictionary[key] = value
945-
946-
return_code, dataset_xml = self._perform_api_call("/run/", file_dictionary=file_dictionary)
939+
def upload_run(self, prediction_file_path, description_path):
940+
try:
941+
file_dictionary = {'predictions': prediction_file_path, 'description': description_path}
942+
return_code, dataset_xml = self._perform_api_call("/run/", file_dictionary=file_dictionary)
947943

948-
except URLError as e:
949-
# TODO logger.debug
950-
print(e)
951-
raise e
952-
return return_code, dataset_xml
953-
else:
954-
raise ValueError("prediction files doesn't exist")
944+
except URLError as e:
945+
# TODO logger.debug
946+
print(e)
947+
raise e
948+
return return_code, dataset_xml

tests/test_apiconnector.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,16 @@ def test_upload_flow(self):
324324
def test_upload_run(self):
325325
file = urlopen("http://www.openml.org/data/download/224/weka_generated_predictions1977525485999711307.arff")
326326
file_text = file.read()
327-
file_path = os.path.join(self.connector.dataset_cache_dir, "weka_generated_predictions1977525485999711307.arff")
328-
with open(file_path, "wb") as prediction_file:
327+
prediction_file_path = os.path.join(self.connector.dataset_cache_dir, "weka_generated_predictions1977525485999711307.arff")
328+
with open(prediction_file_path, "wb") as prediction_file:
329329
prediction_file.write(file_text)
330330

331331
description_text = '''<oml:run xmlns:oml="http://openml.org/openml"><oml:task_id>59</oml:task_id><oml:flow_id>67</oml:flow_id></oml:run>'''
332332
description_path = os.path.join(self.connector.dataset_cache_dir, "description.xml")
333333
with open(description_path, "w") as description_file:
334334
description_file.write(description_text)
335335

336-
file_dictionary = {'predictions': file_path, 'description': description_path}
337-
338-
return_code, dataset_xml = self.connector.upload_run(file_dictionary)
336+
return_code, dataset_xml = self.connector.upload_run(prediction_file_path, description_path)
339337
self.assertEqual(return_code, 200)
340338

341339

0 commit comments

Comments
 (0)