Skip to content
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

nmparser: guard against NaN for all incoming floats #334

Merged
merged 2 commits into from
Oct 22, 2024
Merged

Conversation

kyleam
Copy link
Collaborator

@kyleam kyleam commented Oct 8, 2024

@callistosp reported a case where bbi nonmem summary --json fails to encode the result:

FATA[0000] json: unsupported value: NaN

To avoid this and related errors, this PR makes all spots that parse floats replace NaN with DefaultFloat64.

@kyleam kyleam requested a review from seth127 October 8, 2024 20:17
-0.0805722,
4.1303
],
"omega": [
0.0964407,
-999999999,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something, but I'm unclear why these golden files are changing to now included NaN's (or, more specifically -999 aka DefaultFloat64). I understand the motivation, but I don't see where we change any test files to now expect NaN in these spots. Thanks in advance for explaining.

Copy link
Collaborator Author

@kyleam kyleam Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have explained that somewhere. I tweaked the integration/nmless/testdata/bbi_summary/acop-nan/acop-nan.ext input to introduce NaNs in a bunch of spots. That was an existing test case related to NaNs, but only set the objective function values to NaN in the lst file (75d8f5c, 2022-06-23).

So the golden file changes are coming from me adjusting the input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the commit message to include this:

For testing, piggyback on top of summary's existing acop-nan test case by setting many values in its ext file to NaN.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks for the explanation.

NONMEM output may contain NaN values for floats.  Since fc3af5b
(nmparser: map NaN's to DefaultFloat64 too, 2022-06-23), the nmparser
code has guarded against NaNs in spots that use the strToFloat helper.
However, that doesn't cover the places that invoke strconv.ParseFloat
directly.  That's a problem because the summary command will error
when trying to encode an NaN to JSON.

Adjust all the remaining strconv.ParseFloat calls to guard against
NaN.  Simply using strToFloat in all these spots isn't a good option
because that silently replaces errors with DefaultFloat64.  Add a new
helper that maps NaN to DefaultFloat64 but, unlike strToFloat, relays
any errors.

If a spot does something with the error [*], use the new helper. On
the other hand, if a spot ignores the error, use strToFloat.

For testing, piggyback on top of summary's existing acop-nan test case
by setting many values in its ext file to NaN.

Thanks to @callistosp for reporting the original failure case.

[*] Unfortunately the spots that process the error panic, while
    ideally they would bubble up the error as a return value.  Still,
    using strToFloat is a step in the wrong direction.
@kyleam kyleam merged commit ac02b54 into main Oct 22, 2024
4 checks passed
@kyleam kyleam deleted the summary-more-nan branch October 22, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants