Skip to content

Commit a97c7c3

Browse files
committed
don't convert small floats to scientific notation
1 parent b4fd590 commit a97c7c3

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

cwltool/builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from schema_salad.validate import validate
2929

3030
from ruamel.yaml.comments import CommentedMap
31+
from ruamel.yaml.representer import RoundTripRepresenter
32+
from ruamel.yaml.scalarfloat import ScalarFloat
3133

3234
from .errors import WorkflowException
3335
from .loghandler import _logger
@@ -604,6 +606,9 @@ def tostr(self, value: Union[MutableMapping[str, str], Any]) -> str:
604606
'{} object missing "path": {}'.format(value["class"], value)
605607
)
606608
return value["path"]
609+
elif isinstance(value, ScalarFloat):
610+
rep = RoundTripRepresenter()
611+
return str(rep.represent_scalar_float(value).value)
607612
else:
608613
return str(value)
609614

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"

tests/wf/very-small-float.cwl

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

0 commit comments

Comments
 (0)