[ENH] Use %g (including sci notation) if number of decimals is not set #3574
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.
Issue
Fixes #2692.
Numeric variables are currently printed with three decimals, unless the number is set to another default. The latter most often happens when the data is read from text file (tab, csv, but not Excel). Consequently, values close to 0 are printed as 0. To fix this, some code sets the number of decimals to 7, which defeats the purpose and even doesn't help for values below 1e-7.
Description of changes
%g
is now used for formatting, as suggested by @markotoplak. This will print a reasonable number of decimals or switch to scientific notation.Some code used
Variable.number_of_decimals
to construct own format strings instead of callingVariable.val_to_str
.Variable
now exposesformat_str
, which can be either%g
or%f
with prescribed number of decimals. I tried to hunt down the code where this change was appropriate.The change is backward incompatible in the sense that some outputs changed. Some tests had to be fixed accordingly.
Includes