From e310db238bdebff744918494d71aaf2088c2479b Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 17 Sep 2017 15:32:04 +0300 Subject: [PATCH] workflow: extract float before converting Fixes #217 Signed-off-by: Ruslan Kuprieiev --- dvc/git_wrapper.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/dvc/git_wrapper.py b/dvc/git_wrapper.py index 269cc2ac0..943a6f654 100644 --- a/dvc/git_wrapper.py +++ b/dvc/git_wrapper.py @@ -309,15 +309,23 @@ class GitWrapper(GitWrapperI): file_name = os.path.join(settings.config.cache_dir, cache_file_name) full_file_name = os.path.join(self.git_dir_abs, file_name) - if os.path.exists(full_file_name): - lines = open(full_file_name).readlines(2) - if len(lines) != 1: - msg = '[dvc-git] Target file {} with hash {} has wrong format: {} lines were obtained, 1 expected.' - Logger.warn(msg.format(target, hash, len(lines))) - else: - return float(lines[0]) + if not os.path.exists(full_file_name): + return None - return None + lines = open(full_file_name).readlines(2) + if len(lines) != 1: + msg = '[dvc-git] Target file {} with hash {} has wrong format: {} lines were obtained, 1 expected.' + Logger.warn(msg.format(target, hash, len(lines))) + return None + + # Extract float from string. I.e. from 'AUC: 0.596182' + num = re.findall("\d+\.\d+", lines[0]) + if len(num) != 1: + msg = '[dvc-git] Unable to parse metrics from \'{}\' file {}' + Logger.warn(msg.format(lines[0], target)) + return None + + return float(num[0]) @staticmethod def get_merges_map():