Skip to content

Commit df89fe6

Browse files
committed
Add automatic conversion to lists of XML list items in xmltodict call
1 parent 6c25b86 commit df89fe6

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

openml/datasets/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def list_datasets(offset=None, size=None, tag=None):
179179
def _list_datasets(api_call):
180180
# TODO add proper error handling here!
181181
xml_string = _perform_api_call(api_call)
182-
datasets_dict = xmltodict.parse(xml_string)
182+
datasets_dict = xmltodict.parse(xml_string, force_list=('oml:dataset',))
183183

184184
# Minimalistic check if the XML is useful
185185
assert type(datasets_dict['oml:data']['oml:dataset']) == list, \
@@ -416,7 +416,7 @@ def _get_dataset_features(did_cache_dir, dataset_id):
416416
with io.open(features_file, "w", encoding='utf8') as fh:
417417
fh.write(features_xml)
418418

419-
features = xmltodict.parse(features_xml)["oml:data_features"]
419+
features = xmltodict.parse(features_xml, force_list=('oml:feature',))["oml:data_features"]
420420

421421
return features
422422

@@ -452,7 +452,7 @@ def _get_dataset_qualities(did_cache_dir, dataset_id):
452452
with io.open(qualities_file, "w", encoding='utf8') as fh:
453453
fh.write(qualities_xml)
454454

455-
qualities = xmltodict.parse(qualities_xml)['oml:data_qualities']
455+
qualities = xmltodict.parse(qualities_xml, force_list=('oml:quality',))['oml:data_qualities']
456456

457457
return qualities
458458

openml/flows/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def flow_exists(name, external_version):
107107
def _list_flows(api_call):
108108
# TODO add proper error handling here!
109109
xml_string = _perform_api_call(api_call)
110-
flows_dict = xmltodict.parse(xml_string)
110+
flows_dict = xmltodict.parse(xml_string, force_list=('oml:flow',))
111111

112112
# Minimalistic check if the XML is useful
113113
assert type(flows_dict['oml:flows']['oml:flow']) == list, \

openml/tasks/functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def list_tasks(task_type_id=None, offset=None, size=None, tag=None):
128128

129129
def _list_tasks(api_call):
130130
xml_string = _perform_api_call(api_call)
131-
tasks_dict = xmltodict.parse(xml_string)
131+
tasks_dict = xmltodict.parse(xml_string, force_list=('oml:task',))
132132
# Minimalistic check if the XML is useful
133133
if 'oml:tasks' not in tasks_dict:
134134
raise ValueError('Error in return XML, does not contain "oml:runs": %s'
@@ -143,6 +143,9 @@ def _list_tasks(api_call):
143143
'"http://openml.org/openml": %s'
144144
% str(tasks_dict))
145145

146+
assert type(tasks_dict['oml:tasks']['oml:task']) == list, \
147+
type(tasks_dict['oml:tasks'])
148+
146149
tasks = dict()
147150
procs = _get_estimation_procedure_list()
148151
proc_dict = dict((x['id'], x) for x in procs)

0 commit comments

Comments
 (0)