44import six
55
66from openml ._api_calls import _perform_api_call
7+ from openml .exceptions import OpenMLServerNoResult
78from . import OpenMLFlow
89
910
@@ -70,7 +71,9 @@ def list_flows(offset=None, size=None, tag=None):
7071
7172
7273def flow_exists (name , external_version ):
73- """Retrieves the flow id of the flow uniquely identified by name + external_version.
74+ """Retrieves the flow id.
75+
76+ A flow is uniquely identified by name + external_version.
7477
7578 Parameter
7679 ---------
@@ -93,8 +96,9 @@ def flow_exists(name, external_version):
9396 if not (isinstance (name , six .string_types ) and len (external_version ) > 0 ):
9497 raise ValueError ('Argument \' version\' should be a non-empty string' )
9598
96- xml_response = _perform_api_call ("flow/exists" ,
97- data = {'name' : name , 'external_version' : external_version })
99+ xml_response = _perform_api_call (
100+ "flow/exists" , data = {'name' : name , 'external_version' :
101+ external_version })
98102
99103 result_dict = xmltodict .parse (xml_response )
100104 flow_id = int (result_dict ['oml:flow_exists' ]['oml:id' ])
@@ -105,15 +109,17 @@ def flow_exists(name, external_version):
105109
106110
107111def _list_flows (api_call ):
108- # TODO add proper error handling here!
109- xml_string = _perform_api_call (api_call )
112+ try :
113+ xml_string = _perform_api_call (api_call )
114+ except OpenMLServerNoResult :
115+ return []
110116 flows_dict = xmltodict .parse (xml_string , force_list = ('oml:flow' ,))
111117
112118 # Minimalistic check if the XML is useful
113119 assert type (flows_dict ['oml:flows' ]['oml:flow' ]) == list , \
114120 type (flows_dict ['oml:flows' ])
115121 assert flows_dict ['oml:flows' ]['@xmlns:oml' ] == \
116- 'http://openml.org/openml' , flows_dict ['oml:flows' ]['@xmlns:oml' ]
122+ 'http://openml.org/openml' , flows_dict ['oml:flows' ]['@xmlns:oml' ]
117123
118124 flows = dict ()
119125 for flow_ in flows_dict ['oml:flows' ]['oml:flow' ]:
@@ -190,10 +196,10 @@ def assert_flows_equal(flow1, flow2,
190196 attr2 = getattr (flow2 , key , None )
191197 if key == 'components' :
192198 for name in set (attr1 .keys ()).union (attr2 .keys ()):
193- if not name in attr1 :
199+ if name not in attr1 :
194200 raise ValueError ('Component %s only available in '
195201 'argument2, but not in argument1.' % name )
196- if not name in attr2 :
202+ if name not in attr2 :
197203 raise ValueError ('Component %s only available in '
198204 'argument2, but not in argument1.' % name )
199205 assert_flows_equal (attr1 [name ], attr2 [name ],
0 commit comments