Skip to content

Commit 4ce6d82

Browse files
committed
Added check_flow_exists method which allows you to retrieve the flow id based on the flow's name and description
1 parent 02d7049 commit 4ce6d82

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

openml/apiconnector.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,3 +946,30 @@ def upload_run(self, prediction_file_path, description_path):
946946
print(e)
947947
raise e
948948
return return_code, dataset_xml
949+
950+
def check_flow_exists(self, name, version):
951+
"""
952+
Retrieves the flow id of the flow uniquely identified by name+version.
953+
Returns flow id if such a flow exists,
954+
returns -1 if flow does not exists,
955+
returns -2 if there was not a well-formed response from the server
956+
http://www.openml.org/api_docs/#!/flow/get_flow_exists_name_version
957+
"""
958+
# Perhaps returns the -1/-2 business with proper raising of exceptions?
959+
960+
if not (type(name) is str and len(name) > 0):
961+
raise ValueError('Parameter \'name\' should be a non-empty string')
962+
if not (type(version) is str and len(version) > 0):
963+
raise ValueError('Parameter \'version\' should be a non-empty string')
964+
965+
try:
966+
return_code, xml_response = self._perform_api_call("/flow/exists/%s/%s" % (name, version))
967+
flow_id = -2
968+
if return_code == 200:
969+
xml_dict = xmltodict.parse(xml_response)
970+
flow_id = xml_dict['oml:flow_exists']['oml:id']
971+
except URLError as e:
972+
# TODO logger.debug
973+
print(e)
974+
raise e
975+
return return_code, xml_response, flow_id

0 commit comments

Comments
 (0)