-
Notifications
You must be signed in to change notification settings - Fork 7
Automatically convert integers to doubles when argument type is double
#823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dece396
`NextflowRunner`: Automatically convert integers to doubles when argu…
rcannood 13d8a1a
add test
rcannood cdefe52
fix test
rcannood 40fb2bb
add fix
rcannood d1787a0
Update CHANGELOG.md
rcannood 7de44c9
simpler casting for integers, longs, doubles, floats, and booleans
rcannood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,10 +106,10 @@ def _checkArgumentType(String stage, Map par, Object value, String errorIdentifi | |
| // do nothing | ||
| } | ||
| } | ||
| if (value instanceof java.math.BigDecimal) { | ||
| if (value instanceof java.math.BigDecimal || value instanceof java.math.BigInteger) { | ||
| value = value.doubleValue() | ||
| } | ||
| if (value instanceof Float) { | ||
| if (value instanceof Float || value instanceof Integer || value instanceof Long) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to resolve this by using a more idiomatic casting mechanism, namely: // ...
} else if (par.type == "double") {
// cast to double if need be
if (value !instanceof Double) {
try {
value = value as Double
} catch (NumberFormatException e) {
expectedClass = "Double"
}
}
} // ...WDYT? |
||
| value = value.toDouble() | ||
| } | ||
| expectedClass = value instanceof Double ? null : "Double" | ||
|
|
||
25 changes: 25 additions & 0 deletions
25
src/test/resources/testnextflowvdsl3/src/integer_as_double/config.vsh.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| functionality: | ||
| name: integer_as_double | ||
| arguments: | ||
| - name: "--input" | ||
| type: file | ||
| required: true | ||
| example: input.txt | ||
| - name: "--output" | ||
| type: file | ||
| required: true | ||
| direction: output | ||
| example: output.txt | ||
| - name: "--double" | ||
| type: double | ||
| required: true | ||
| direction: input | ||
| example: 10.5 | ||
| resources: | ||
| - type: bash_script | ||
| path: script.sh | ||
| platforms: | ||
| - type: native | ||
| - type: docker | ||
| image: nextflow/bash:latest | ||
| - type: nextflow |
15 changes: 15 additions & 0 deletions
15
src/test/resources/testnextflowvdsl3/src/integer_as_double/script.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
|
|
||
| ## VIASH START | ||
| par_input='resources/lines3.txt' | ||
| par_double='10.5' | ||
| par_output='output.txt' | ||
| ## VIASH END | ||
|
|
||
| echo "Copying $par_input to $par_output" | ||
| cp "$par_input" "$par_output" | ||
|
|
||
| echo "Adding $par_double to $par_output" | ||
| echo "Double: $par_double" >> "$par_output" | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.