Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RawReport to handle all scientific notation
Browse files Browse the repository at this point in the history
- 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:
  <yaml/pyyaml#174>
  to the pyyaml project.

Change-Id: I5cc4afc0d6eecf204b92ba111185d8cc30dc6c5d
Signed-off-by: Christopher M. Cantalupo <christopher.m.cantalupo@intel.com>
cmcantalupo committed Mar 25, 2020
1 parent e5f8ba9 commit d40fe6a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/geopmpy/io.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d40fe6a

Please sign in to comment.