File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,21 +61,17 @@ def _list_evaluations(api_call):
6161
6262 xml_string = _perform_api_call (api_call )
6363
64- evals_dict = xmltodict .parse (xml_string )
64+ evals_dict = xmltodict .parse (xml_string , force_list = ( 'oml:evaluation' ,) )
6565 # Minimalistic check if the XML is useful
6666 if 'oml:evaluations' not in evals_dict :
6767 raise ValueError ('Error in return XML, does not contain "oml:evaluations": %s'
6868 % str (evals_dict ))
6969
70- if isinstance (evals_dict ['oml:evaluations' ]['oml:evaluation' ], list ):
71- evals_list = evals_dict ['oml:evaluations' ]['oml:evaluation' ]
72- elif isinstance (evals_dict ['oml:evaluations' ]['oml:evaluation' ], dict ):
73- evals_list = [evals_dict ['oml:evaluations' ]['oml:evaluation' ]]
74- else :
75- raise TypeError ()
70+ assert type (evals_dict ['oml:evaluations' ]['oml:evaluation' ]) == list , \
71+ type (evals_dict ['oml:evaluations' ])
7672
7773 evals = dict ()
78- for eval_ in evals_list :
74+ for eval_ in evals_dict [ 'oml:evaluations' ][ 'oml:evaluation' ] :
7975 run_id = int (eval_ ['oml:run_id' ])
8076 array_data = None
8177 if 'oml:array_data' in eval_ :
Original file line number Diff line number Diff line change @@ -854,7 +854,7 @@ def _list_runs(api_call):
854854
855855 xml_string = _perform_api_call (api_call )
856856
857- runs_dict = xmltodict .parse (xml_string )
857+ runs_dict = xmltodict .parse (xml_string , force_list = ( 'oml:run' ,) )
858858 # Minimalistic check if the XML is useful
859859 if 'oml:runs' not in runs_dict :
860860 raise ValueError ('Error in return XML, does not contain "oml:runs": %s'
@@ -869,15 +869,11 @@ def _list_runs(api_call):
869869 '"http://openml.org/openml": %s'
870870 % str (runs_dict ))
871871
872- if isinstance (runs_dict ['oml:runs' ]['oml:run' ], list ):
873- runs_list = runs_dict ['oml:runs' ]['oml:run' ]
874- elif isinstance (runs_dict ['oml:runs' ]['oml:run' ], dict ):
875- runs_list = [runs_dict ['oml:runs' ]['oml:run' ]]
876- else :
877- raise TypeError ()
872+ assert type (runs_dict ['oml:runs' ]['oml:run' ]) == list , \
873+ type (runs_dict ['oml:runs' ])
878874
879875 runs = dict ()
880- for run_ in runs_list :
876+ for run_ in runs_dict [ 'oml:runs' ][ 'oml:run' ] :
881877 run_id = int (run_ ['oml:run_id' ])
882878 run = {'run_id' : run_id ,
883879 'task_id' : int (run_ ['oml:task_id' ]),
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ def _list_setups(api_call):
116116
117117 xml_string = openml ._api_calls ._perform_api_call (api_call )
118118
119- setups_dict = xmltodict .parse (xml_string )
119+ setups_dict = xmltodict .parse (xml_string , force_list = ( 'oml:setup' ,) )
120120 # Minimalistic check if the XML is useful
121121 if 'oml:setups' not in setups_dict :
122122 raise ValueError ('Error in return XML, does not contain "oml:setups": %s'
@@ -131,15 +131,11 @@ def _list_setups(api_call):
131131 '"http://openml.org/openml": %s'
132132 % str (setups_dict ))
133133
134- if isinstance (setups_dict ['oml:setups' ]['oml:setup' ], list ):
135- setups_list = setups_dict ['oml:setups' ]['oml:setup' ]
136- elif isinstance (setups_dict ['oml:setups' ]['oml:setup' ], dict ):
137- setups_list = [setups_dict ['oml:setups' ]['oml:setup' ]]
138- else :
139- raise TypeError ()
134+ assert type (setups_dict ['oml:setups' ]['oml:setup' ]) == list , \
135+ type (setups_dict ['oml:setups' ])
140136
141137 setups = dict ()
142- for setup_ in setups_list :
138+ for setup_ in setups_dict [ 'oml:setups' ][ 'oml:setup' ] :
143139 # making it a dict to give it the right format
144140 current = _create_setup_from_xml ({'oml:setup_parameters' : setup_ })
145141 setups [current .setup_id ] = current
You can’t perform that action at this time.
0 commit comments