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

[ENH] Use %g (including sci notation) if number of decimals is not set #3574

Merged
merged 2 commits into from
Feb 15, 2019

Conversation

janezd
Copy link
Contributor

@janezd janezd commented Feb 2, 2019

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
  • When number of decimals is not set (as in regression coefficients, variables constructed by PCA...), %g is now used for formatting, as suggested by @markotoplak. This will print a reasonable number of decimals or switch to scientific notation.
  • When the number of decimals is set, nothing changes.

Some code used Variable.number_of_decimals to construct own format strings instead of calling Variable.val_to_str. Variable now exposes format_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
  • Code changes
  • Tests

@codecov
Copy link

codecov bot commented Feb 2, 2019

Codecov Report

Merging #3574 into master will decrease coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #3574      +/-   ##
==========================================
- Coverage   83.97%   83.96%   -0.01%     
==========================================
  Files         370      370              
  Lines       66941    66944       +3     
==========================================
- Hits        56215    56212       -3     
- Misses      10726    10732       +6

@janezd janezd changed the title Use %g (including sci notation) if number of decimals is not set [ENH] Use %g (including sci notation) if number of decimals is not set Feb 2, 2019
@markotoplak
Copy link
Member

markotoplak commented Feb 15, 2019

I suspected problems with saving into a file and reloading it, because %g sometimes skips decimals. I found none: our file saving is smart enough to directly use .value, not __str__. :)

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.

Small values
2 participants