From 9b09e9b65d1cba0ea4be5bb7ae4af7f3ac7bbbfd Mon Sep 17 00:00:00 2001 From: Carton He Date: Sun, 6 Dec 2020 23:25:05 +0800 Subject: [PATCH] fix ValueError when converting empty string KM to float in sgf parser Some sgfs has "KM" property with empty value, this could cause ValueError exception. --- katrain/core/sgf_parser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/katrain/core/sgf_parser.py b/katrain/core/sgf_parser.py index 7f284a4..5b03656 100644 --- a/katrain/core/sgf_parser.py +++ b/katrain/core/sgf_parser.py @@ -192,7 +192,12 @@ class SGFNode: @property def komi(self) -> float: """Retrieves the root's KM property, or 6.5 if missing""" - return float(self.root.get_property("KM", 6.5)) + try: + km = float(self.root.get_property("KM", 6.5)) + except ValueError: + km = 6.5 + + return km @property def ruleset(self) -> str: