Skip to content

Commit 539dd49

Browse files
committed
floats on command-line always in decimal notation
Never in scientific notation
1 parent b4fd590 commit 539dd49

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

cwltool/builder.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import copy
33
import logging
44
import math
5-
from typing import ( # pylint: disable=unused-import
5+
from decimal import Decimal
6+
from typing import (
67
IO,
78
TYPE_CHECKING,
89
Any,
@@ -28,6 +29,8 @@
2829
from schema_salad.validate import validate
2930

3031
from ruamel.yaml.comments import CommentedMap
32+
from ruamel.yaml.representer import RoundTripRepresenter
33+
from ruamel.yaml.scalarfloat import ScalarFloat
3134

3235
from .errors import WorkflowException
3336
from .loghandler import _logger
@@ -604,6 +607,12 @@ def tostr(self, value: Union[MutableMapping[str, str], Any]) -> str:
604607
'{} object missing "path": {}'.format(value["class"], value)
605608
)
606609
return value["path"]
610+
elif isinstance(value, ScalarFloat):
611+
rep = RoundTripRepresenter()
612+
dec_value = Decimal(rep.represent_scalar_float(value).value)
613+
if "E" in str(dec_value):
614+
return str(dec_value.quantize(1))
615+
return str(dec_value)
607616
else:
608617
return str(value)
609618

tests/test_examples.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,3 +1829,14 @@ def test_res_req_expr_float_1_2() -> None:
18291829
assert exit_code == 0, stderr
18301830
assert json.loads(stdout)["result"]["outdirSize"] >= 708
18311831
assert json.loads(stdout)["result"]["tmpdirSize"] >= 708
1832+
1833+
1834+
def test_very_small_and_large_floats() -> None:
1835+
"""Confirm that very small or large numbers are not transformed into scientific notation."""
1836+
exit_code, stdout, stderr = get_main_output(
1837+
[
1838+
get_data("tests/wf/floats_small_and_large.cwl"),
1839+
]
1840+
)
1841+
assert exit_code == 0, stderr
1842+
assert json.loads(stdout)["result"] == "0.00001 0.0000123 123000 1230000"

tests/wf/floats_small_and_large.cwl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand: echo
4+
requirements:
5+
InlineJavascriptRequirement: {}
6+
7+
inputs:
8+
annotation_prokka_evalue:
9+
type: float
10+
default: 0.00001
11+
inputBinding: {}
12+
13+
annotation_prokka_evalue2:
14+
type: float
15+
default: 1.23e-05
16+
inputBinding: {}
17+
18+
annotation_prokka_evalue3:
19+
type: float
20+
default: 1.23e5
21+
inputBinding: {}
22+
23+
annotation_prokka_evalue4:
24+
type: float
25+
default: 1230000
26+
inputBinding: {}
27+
28+
29+
arguments: [ -n ]
30+
31+
stdout: dump
32+
33+
outputs:
34+
result:
35+
type: string
36+
outputBinding:
37+
glob: dump
38+
loadContents: true
39+
outputEval: $(self[0].contents)

0 commit comments

Comments
 (0)