Skip to content

Commit c80eda9

Browse files
authored
Merge pull request #8 from jcrivenaes/fix-floats
Fix floats
2 parents 50b1c16 + e6705dd commit c80eda9

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ universal = 1
33

44
[flake8]
55
exclude = docs
6+
max-line-length = 88
7+
extend-ignore =
8+
# See https://github.com/PyCQA/pycodestyle/issues/373
9+
E203,
610

711
[aliases]
812
test = pytest

src/fmu/config/_configparserfmu_ipl.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _freeform_handle_entry(variable, myvalue, myvalues, dtype, template):
398398
# inner function
399399
def _fixtheentry(variable, myval, subtype, count=None, template=False):
400400

401-
logger.info("Fix freeform entry %s", variable)
401+
logger.info("Fix freeform entry %s (subtype %s)", variable, subtype)
402402
tmpvalue = str(myval)
403403
if "~" in tmpvalue:
404404
val, var = tmpvalue.split("~")
@@ -414,6 +414,13 @@ def _fixtheentry(variable, myval, subtype, count=None, template=False):
414414
if val in ("False", "no", "NO", "No", "false", "FALSE"):
415415
val = "FALSE"
416416

417+
if subtype == "Float":
418+
logger.info("Input float value is %s (%s)", val, variable)
419+
if "e" in str(val).lower():
420+
val = "{0:E}".format(float(val))
421+
422+
logger.info("Updated float value is %s (%s)", val, variable)
423+
417424
if subtype == "String":
418425
val = '"{}"'.format(val)
419426
if var:

src/fmu/config/configparserfmu.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import datetime
2020
import json
2121

22+
import pdb
23+
2224
# for ordered dicts!
2325
from collections import OrderedDict, Counter
2426

@@ -208,7 +210,7 @@ def to_yaml(
208210
209211
>>> config.to_yaml('global_variables', destination='../')
210212
"""
211-
213+
logger.info("To YAML")
212214
if not destination and not template:
213215
raise ValueError(
214216
"Both destination and template are None."
@@ -233,6 +235,8 @@ def to_yaml(
233235
mystream = re.sub(r"\s+~", "~", mystream)
234236
mystream = re.sub(r"~\s+", "~", mystream)
235237

238+
# pdb.set_trace()
239+
236240
cfg1 = self._get_dest_form(mystream)
237241
cfg2 = self._get_tmpl_form(mystream)
238242

@@ -622,7 +626,9 @@ def _get_required_form(stream, template=False, ipl=False):
622626
def _get_tmpl_form(stream):
623627
"""Get template form (<...> if present, not numbers)."""
624628

625-
pattern = "-*[a-zA-Z0-9.]+~"
629+
pattern = "\\-*[\\-a-zA-Z0-9.]+~"
630+
631+
# pdb.set_trace()
626632

627633
if isinstance(stream, list):
628634
logger.info("STREAM is a list object")
@@ -646,7 +652,8 @@ def _get_tmpl_form(stream):
646652
def _get_dest_form(stream):
647653
"""Get destination form (numbers, not <...>)"""
648654

649-
pattern = "~<.+?>"
655+
logger.info("TRY DEST %s", stream)
656+
pattern = "~.*<.+?>"
650657

651658
if isinstance(stream, list):
652659
logger.info("STREAM is a list object")
@@ -662,4 +669,5 @@ def _get_dest_form(stream):
662669
else:
663670
raise ValueError("Input for templateconversion neither string " "or list")
664671

672+
logger.info("DEST %s", result)
665673
return result

0 commit comments

Comments
 (0)