From d40fe6af8efdde73dfb4409c0461c227180b3206 Mon Sep 17 00:00:00 2001 From: "Christopher M. Cantalupo" Date: Tue, 24 Mar 2020 14:39:46 -0700 Subject: [PATCH] Fix RawReport to handle all scientific notation - Due to error in pyyaml scientific notation floating point numbers without a decimal point are parsed as strings: e.g. "1e+09". - Fix is based on PR: to the pyyaml project. Change-Id: I5cc4afc0d6eecf204b92ba111185d8cc30dc6c5d Signed-off-by: Christopher M. Cantalupo --- scripts/geopmpy/io.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/geopmpy/io.py b/scripts/geopmpy/io.py index 078bebb9e1..c77637393c 100644 --- a/scripts/geopmpy/io.py +++ b/scripts/geopmpy/io.py @@ -1345,7 +1345,20 @@ def __init__(self, path): else: out_fid.write(' {}'.format(line)) out_fid.seek(0) - self._raw_dict = yaml.load(out_fid, Loader=yaml.SafeLoader) + # Fix issue with python yaml module where it is confused + # about floating point numbers of the form "1e+10" where + # the decimal point is missing. + loader = yaml.SafeLoader + loader.add_implicit_resolver( + u'tag:yaml.org,2002:float', + re.compile(ur'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+]?[0-9]+)? + |[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+) + |\.[0-9_]+(?:[eE][-+]?[0-9]+)? + |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]* + |[-+]?\.(?:inf|Inf|INF) + |\.(?:nan|NaN|NAN))$''', re.X), + list(u'-+0123456789.')) + self._raw_dict = yaml.load(out_fid, Loader=loader) def raw_report(self): return copy.deepcopy(self._raw_dict)