Skip to content

Commit 8262c0e

Browse files
committed
can read description files
1 parent f3f6739 commit 8262c0e

1 file changed

Lines changed: 40 additions & 39 deletions

File tree

openml/runs/functions.py

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,20 @@ def _create_run_from_xml(xml):
588588
New run object representing run_xml.
589589
"""
590590
run = xmltodict.parse(xml)["oml:run"]
591-
run_id = int(run['oml:run_id'])
592-
uploader = int(run['oml:uploader'])
593-
uploader_name = run['oml:uploader_name']
591+
run_id = int(run['oml:run_id']) if 'oml:run_id' in run else None
592+
uploader = int(run['oml:uploader']) if 'oml:uploader' in run else None
593+
uploader_name = run['oml:uploader_name'] if 'oml:uploader_name' in run else None
594594
task_id = int(run['oml:task_id'])
595-
task_type = run['oml:task_type']
595+
task_type = run['oml:task_type'] if 'oml:task_type' in run else None
596596
if 'oml:task_evaluation_measure' in run:
597597
task_evaluation_measure = run['oml:task_evaluation_measure']
598598
else:
599599
task_evaluation_measure = None
600600

601601
flow_id = int(run['oml:flow_id'])
602-
flow_name = run['oml:flow_name']
603-
setup_id = int(run['oml:setup_id'])
604-
setup_string = run['oml:setup_string']
602+
flow_name = run['oml:flow_name'] if 'oml:flow_name' in run else None
603+
setup_id = int(run['oml:setup_id']) if 'oml:setup_id' in run else None
604+
setup_string = run['oml:setup_string'] if 'oml:setup_string' in run else None
605605

606606
parameters = dict()
607607
if 'oml:parameter_settings' in run:
@@ -611,15 +611,16 @@ def _create_run_from_xml(xml):
611611
value = parameter_dict['oml:value']
612612
parameters[key] = value
613613

614-
dataset_id = int(run['oml:input_data']['oml:dataset']['oml:did'])
614+
dataset_id = int(run['oml:input_data']['oml:dataset']['oml:did']) if 'oml:input_data' in run else None
615615

616616
files = dict()
617617
evaluations = dict()
618618
fold_evaluations = defaultdict(lambda: defaultdict(dict))
619619
sample_evaluations = defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))
620620
if 'oml:output_data' not in run:
621621
raise ValueError('Run does not contain output_data (OpenML server error?)')
622-
else:
622+
623+
if 'oml:file' in 'oml:output_data':
623624
if isinstance(run['oml:output_data']['oml:file'], dict):
624625
# only one result.. probably due to an upload error
625626
file_dict = run['oml:output_data']['oml:file']
@@ -631,40 +632,40 @@ def _create_run_from_xml(xml):
631632
else:
632633
raise TypeError(type(run['oml:output_data']['oml:file']))
633634

634-
if 'oml:evaluation' in run['oml:output_data']:
635-
# in normal cases there should be evaluations, but in case there
636-
# was an error these could be absent
637-
for evaluation_dict in run['oml:output_data']['oml:evaluation']:
638-
key = evaluation_dict['oml:name']
639-
if 'oml:value' in evaluation_dict:
640-
value = float(evaluation_dict['oml:value'])
641-
elif 'oml:array_data' in evaluation_dict:
642-
value = evaluation_dict['oml:array_data']
643-
else:
644-
raise ValueError('Could not find keys "value" or "array_data" '
645-
'in %s' % str(evaluation_dict.keys()))
646-
if '@repeat' in evaluation_dict and '@fold' in evaluation_dict and '@sample' in evaluation_dict:
647-
repeat = int(evaluation_dict['@repeat'])
648-
fold = int(evaluation_dict['@fold'])
649-
sample = int(evaluation_dict['@sample'])
650-
repeat_dict = sample_evaluations[key]
651-
fold_dict = repeat_dict[repeat]
652-
sample_dict = fold_dict[fold]
653-
sample_dict[sample] = value
654-
elif '@repeat' in evaluation_dict and '@fold' in evaluation_dict:
655-
repeat = int(evaluation_dict['@repeat'])
656-
fold = int(evaluation_dict['@fold'])
657-
repeat_dict = fold_evaluations[key]
658-
fold_dict = repeat_dict[repeat]
659-
fold_dict[fold] = value
660-
else:
661-
evaluations[key] = value
635+
if 'oml:evaluation' in run['oml:output_data']:
636+
# in normal cases there should be evaluations, but in case there
637+
# was an error these could be absent
638+
for evaluation_dict in run['oml:output_data']['oml:evaluation']:
639+
key = evaluation_dict['oml:name']
640+
if 'oml:value' in evaluation_dict:
641+
value = float(evaluation_dict['oml:value'])
642+
elif 'oml:array_data' in evaluation_dict:
643+
value = evaluation_dict['oml:array_data']
644+
else:
645+
raise ValueError('Could not find keys "value" or "array_data" '
646+
'in %s' % str(evaluation_dict.keys()))
647+
if '@repeat' in evaluation_dict and '@fold' in evaluation_dict and '@sample' in evaluation_dict:
648+
repeat = int(evaluation_dict['@repeat'])
649+
fold = int(evaluation_dict['@fold'])
650+
sample = int(evaluation_dict['@sample'])
651+
repeat_dict = sample_evaluations[key]
652+
fold_dict = repeat_dict[repeat]
653+
sample_dict = fold_dict[fold]
654+
sample_dict[sample] = value
655+
elif '@repeat' in evaluation_dict and '@fold' in evaluation_dict:
656+
repeat = int(evaluation_dict['@repeat'])
657+
fold = int(evaluation_dict['@fold'])
658+
repeat_dict = fold_evaluations[key]
659+
fold_dict = repeat_dict[repeat]
660+
fold_dict[fold] = value
661+
else:
662+
evaluations[key] = value
662663

663-
if 'description' not in files:
664+
if 'description' not in files and run_id is not None:
664665
raise ValueError('No description file for run %d in run '
665666
'description XML' % run_id)
666667

667-
if 'predictions' not in files:
668+
if 'predictions' not in files and run_id is not None:
668669
# JvR: actually, I am not sure whether this error should be raised.
669670
# a run can consist without predictions. But for now let's keep it
670671
raise ValueError('No prediction files for run %d in run '

0 commit comments

Comments
 (0)