Skip to content

Commit 1625548

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

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

cwltool/builder.py

Lines changed: 7 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,9 @@ 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+
return str(Decimal(rep.represent_scalar_float(value).value))
607613
else:
608614
return str(value)
609615

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_floats() -> None:
1835+
"""Confirm that very small numbers are not transformed into scientific notation."""
1836+
exit_code, stdout, stderr = get_main_output(
1837+
[
1838+
get_data("tests/wf/very-small-float.cwl"),
1839+
]
1840+
)
1841+
assert exit_code == 0, stderr
1842+
assert json.loads(stdout)["result"] == "0.00001 0.0000123"

tests/wf/very-small-float.cwl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
arguments: [ -n ]
19+
20+
stdout: dump
21+
22+
outputs:
23+
result:
24+
type: string
25+
outputBinding:
26+
glob: dump
27+
loadContents: true
28+
outputEval: $(self[0].contents)

0 commit comments

Comments
 (0)