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

__str__ for gvars with nan mean or sdev doesn't crash #1

Merged
merged 1 commit into from
Mar 7, 2017

Conversation

dchackett
Copy link
Contributor

Currently, GVar will raise an exception when attempting to print (or otherwise render to string) a GVar with a nan for either its mean or sdev. For example, any of
>>> print gv.gvar(float('nan'), float('nan'))
>>> print gv.gvar(1, float('nan'))
>>> print gv.gvar(float('nan'), 1)
will raise exceptions.

The issue is in the helper function GVar.__str__.ndec, specifically line 92:
ans = int(ans)
which raises an exception when ans is nan.

This change defines behavior for when the mean and/or sdev are nan, such that

>>> print gv.gvar(float('nan'), float('nan'))
nan(nan)
>>> print gv.gvar(1, float('nan'))
1 +- nan
>>> print gv.gvar(float('nan'), 1)
nan +- 1

Versus simply printing 'nan', this output format makes it easy to differentiate between a simple float nan or a GVar nan. It can be diagnostically useful to know if one of the mean or sdev are not nan, hence the 'nan +- 1' and '1 +- nan' output formats.

All GVar tests run by 'make tests' pass. All non-GSL lsqfit tests run by 'make tests' also pass.

@gplepage
Copy link
Owner

gplepage commented Mar 7, 2017

Good idea. Thanks.

@gplepage gplepage merged commit 30978d2 into gplepage:master Mar 7, 2017
@r-nepton r-nepton mentioned this pull request Apr 17, 2018
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