Skip to content

Commit 60372ea

Browse files
committed
FIX #152 do not return status code
1 parent 32026b4 commit 60372ea

10 files changed

Lines changed: 25 additions & 36 deletions

File tree

openml/_api_calls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _read_url_files(url, data=None, file_dictionary=None, file_elements=None):
8484
if 'Content-Encoding' not in response.headers or \
8585
response.headers['Content-Encoding'] != 'gzip':
8686
warnings.warn('Received uncompressed content from OpenML for %s.' % url)
87-
return response.status_code, response.text
87+
return response.text
8888

8989

9090
def _read_url(url, data=None):
@@ -101,4 +101,4 @@ def _read_url(url, data=None):
101101
if 'Content-Encoding' not in response.headers or \
102102
response.headers['Content-Encoding'] != 'gzip':
103103
warnings.warn('Received uncompressed content from OpenML for %s.' % url)
104-
return response.status_code, response.text
104+
return response.text

openml/datasets/dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ def publish(self):
318318
if self.data_file is not None:
319319
file_dictionary['dataset'] = self.data_file
320320

321-
return_code, return_value = _perform_api_call(
322-
"/data/", file_dictionary=file_dictionary,
323-
file_elements=file_elements)
321+
return_value = _perform_api_call("/data/", file_dictionary=file_dictionary,
322+
file_elements=file_elements)
324323

325324
self.dataset_id = int(xmltodict.parse(return_value)['oml:upload_data_set']['oml:id'])
326325
return self

openml/datasets/functions.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def list_datasets(offset=None, size=None, tag=None):
159159

160160
def _list_datasets(api_call):
161161
# TODO add proper error handling here!
162-
return_code, xml_string = _perform_api_call(api_call)
162+
xml_string = _perform_api_call(api_call)
163163
datasets_dict = xmltodict.parse(xml_string)
164164

165165
# Minimalistic check if the XML is useful
@@ -301,8 +301,7 @@ def _get_dataset_description(did_cache_dir, dataset_id):
301301
try:
302302
return _get_cached_dataset_description(dataset_id)
303303
except (OpenMLCacheException):
304-
return_code, dataset_xml = _perform_api_call(
305-
"data/%d" % dataset_id)
304+
dataset_xml = _perform_api_call("data/%d" % dataset_id)
306305

307306
with io.open(description_file, "w", encoding='utf8') as fh:
308307
fh.write(dataset_xml)
@@ -347,7 +346,7 @@ def _get_dataset_arff(did_cache_dir, description):
347346
pass
348347

349348
url = description['oml:url']
350-
return_code, arff_string = _read_url(url)
349+
arff_string = _read_url(url)
351350

352351
with io.open(output_file_path, "w", encoding='utf8') as fh:
353352
fh.write(arff_string)
@@ -382,8 +381,7 @@ def _get_dataset_features(did_cache_dir, dataset_id):
382381
with io.open(features_file, encoding='utf8') as fh:
383382
features_xml = fh.read()
384383
except (OSError, IOError):
385-
return_code, features_xml = _perform_api_call(
386-
"data/features/%d" % dataset_id)
384+
features_xml = _perform_api_call("data/features/%d" % dataset_id)
387385

388386
with io.open(features_file, "w", encoding='utf8') as fh:
389387
fh.write(features_xml)
@@ -417,8 +415,7 @@ def _get_dataset_qualities(did_cache_dir, dataset_id):
417415
with io.open(qualities_file, encoding='utf8') as fh:
418416
qualities_xml = fh.read()
419417
except (OSError, IOError):
420-
return_code, qualities_xml = _perform_api_call(
421-
"data/qualities/%d" % dataset_id)
418+
qualities_xml = _perform_api_call("data/qualities/%d" % dataset_id)
422419

423420
with io.open(qualities_file, "w", encoding='utf8') as fh:
424421
fh.write(qualities_xml)

openml/flows/flow.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ def publish(self):
335335

336336
xml_description = self._to_xml()
337337
file_elements = {'description': xml_description}
338-
return_code, return_value = _perform_api_call(
339-
"flow/", file_elements=file_elements)
338+
return_value = _perform_api_call("flow/", file_elements=file_elements)
340339
self.flow_id = int(xmltodict.parse(return_value)['oml:upload_flow']['oml:id'])
341340
return self
342341

@@ -351,7 +350,7 @@ def _ensure_flow_exists(self):
351350
flow_id : int
352351
Flow id on the server.
353352
"""
354-
_, _, flow_id = _check_flow_exists(self.name, self.external_version)
353+
_, flow_id = _check_flow_exists(self.name, self.external_version)
355354
# TODO add numpy and scipy version!
356355

357356
if int(flow_id) == -1:
@@ -385,15 +384,12 @@ def _check_flow_exists(name, version):
385384
if not (type(version) is str and len(version) > 0):
386385
raise ValueError('Argument \'version\' should be a non-empty string')
387386

388-
return_code, xml_response = _perform_api_call(
389-
"flow/exists", data={'name': name, 'external_version': version})
390-
# TODO check with latest version of code if this raises an exception
391-
if return_code != 200:
392-
# fixme raise appropriate error
393-
raise ValueError("api call failed: %s" % xml_response)
387+
xml_response = _perform_api_call("flow/exists",
388+
data={'name': name, 'external_version': version})
389+
394390
xml_dict = xmltodict.parse(xml_response)
395391
flow_id = xml_dict['oml:flow_exists']['oml:id']
396-
return return_code, xml_response, flow_id
392+
return xml_response, flow_id
397393

398394

399395
def _add_if_nonempty(dic, key, value):

openml/flows/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_flow(flow_id):
1818
except:
1919
raise ValueError("Flow ID must be an int, got %s." % str(flow_id))
2020

21-
return_code, flow_xml = _perform_api_call("flow/%d" % flow_id)
21+
flow_xml = _perform_api_call("flow/%d" % flow_id)
2222

2323
flow_dict = xmltodict.parse(flow_xml)
2424
flow = OpenMLFlow._from_dict(flow_dict)
@@ -71,7 +71,7 @@ def list_flows(offset=None, size=None, tag=None):
7171

7272
def _list_datasets(api_call):
7373
# TODO add proper error handling here!
74-
return_code, xml_string = _perform_api_call(api_call)
74+
xml_string = _perform_api_call(api_call)
7575
flows_dict = xmltodict.parse(xml_string)
7676

7777
# Minimalistic check if the XML is useful

openml/runs/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def get_run(run_id):
159159
return _get_cached_run(run_id)
160160
except (OpenMLCacheException):
161161
try:
162-
return_code, run_xml = _perform_api_call("run/%d" % run_id)
162+
run_xml = _perform_api_call("run/%d" % run_id)
163163
except (URLError, UnicodeEncodeError) as e:
164164
# TODO logger.debug
165165
print(e)
@@ -328,7 +328,7 @@ def list_runs(offset=None, size=None, id=None, task=None,
328328
def _list_runs(api_call):
329329
"""Helper function to parse API calls which are lists of runs"""
330330

331-
return_code, xml_string = _perform_api_call(api_call)
331+
xml_string = _perform_api_call(api_call)
332332

333333
runs_dict = xmltodict.parse(xml_string)
334334
# Minimalistic check if the XML is useful

openml/runs/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ def publish(self):
146146
trace_arff = arff.dumps(self._generate_trace_arff_dict(self.model))
147147
file_elements['trace'] = ("trace.arff", trace_arff)
148148

149-
return_code, return_value = _perform_api_call(
150-
"/run/", file_elements=file_elements)
149+
return_value = _perform_api_call("/run/", file_elements=file_elements)
151150
run_id = int(xmltodict.parse(return_value)['oml:upload_run']['oml:run_id'])
152151
self.run_id = run_id
153152
return self

openml/tasks/functions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def _get_estimation_procedure_list():
5858
task type id, name, type, repeats, folds, stratified.
5959
"""
6060

61-
return_code, xml_string = _perform_api_call(
62-
"estimationprocedure/list")
61+
xml_string = _perform_api_call("estimationprocedure/list")
6362
procs_dict = xmltodict.parse(xml_string)
6463
# Minimalistic check if the XML is useful
6564
if 'oml:estimationprocedures' not in procs_dict:
@@ -128,7 +127,7 @@ def list_tasks(task_type_id=None, offset=None, size=None, tag=None):
128127

129128

130129
def _list_tasks(api_call):
131-
return_code, xml_string = _perform_api_call(api_call)
130+
xml_string = _perform_api_call(api_call)
132131
with open('/tmp/list_tasks.xml', 'w') as fh:
133132
fh.write(xml_string)
134133
tasks_dict = xmltodict.parse(xml_string)
@@ -203,8 +202,7 @@ def get_task(task_id):
203202
except (OSError, IOError):
204203

205204
try:
206-
return_code, task_xml = _perform_api_call(
207-
"task/%d" % task_id)
205+
task_xml = _perform_api_call("task/%d" % task_id)
208206
except (URLError, UnicodeEncodeError) as e:
209207
print(e)
210208
raise e

openml/tasks/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _download_split(self, cache_file):
7171
except (OSError, IOError):
7272
split_url = self.estimation_procedure["data_splits_url"]
7373
try:
74-
return_code, split_arff = _read_url(split_url)
74+
split_arff = _read_url(split_url)
7575
except (URLError, UnicodeEncodeError) as e:
7676
print(e, split_url)
7777
raise e

tests/test_flows/test_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_from_xml_to_xml(self):
105105
# Get the raw xml thing
106106
# TODO maybe get this via get_flow(), which would have to be refactored to allow getting only the xml dictionary
107107
for flow_id in [1185, 1244, 1196, 1112, ]:
108-
flow_xml = _perform_api_call("flow/%d" % flow_id)[1]
108+
flow_xml = _perform_api_call("flow/%d" % flow_id)
109109
flow_dict = xmltodict.parse(flow_xml)
110110

111111
flow = openml.OpenMLFlow._from_dict(flow_dict)

0 commit comments

Comments
 (0)