Skip to content

BUG: format small floats correctly (GH9764) #9806

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 5 commits into from
Apr 6, 2015
Merged

BUG: format small floats correctly (GH9764) #9806

merged 5 commits into from
Apr 6, 2015

Conversation

tomazberisa
Copy link
Contributor

closes #9764

In order to display a number from range (0,1) in decimal format with N significant digits (and not in scientific format), the number needs to be greater than or equal to 1e(-N+1), not 1e-N.

Did not test for range of display.precision, as this does not seem to current practice.

Did not include tests as they would imply an output format which might change in the future.

Values from range [1e-7, 5e-7] (for display.precision=7) not displaying 0 anymore
@shoyer
Copy link
Member

shoyer commented Apr 3, 2015

This should have a test to verify that your fix works. We use unit tests to verify our public API, but they're also for internal usage. The test will guarantee that nobody breaks this behavior without thinking carefully about it, even if we're not going to guarantee the output format to our users.

@tomazberisa
Copy link
Contributor Author

Sure, test added to branch.


# In case default display precision changes:
saved_option=pd.get_option('display.precision')
pd.set_option('display.precision', 7)
Copy link
Member

Choose a reason for hiding this comment

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

Can you set this with the context manager pd.option_context() instead? That's safer than setting a global variable.

@shoyer
Copy link
Member

shoyer commented Apr 3, 2015

looks pretty good -- could you add a line to the bug fix section of the release notes for v0.16.1?

@jreback
Copy link
Contributor

jreback commented Apr 3, 2015

also prob needs a test with mixed (meaning a really small number and a normal sized float). further this prob needs a quick way (eg vectorizes) to figure out whether to do this formatting (eg see how Timedelta does it for example) otherwise perf on a big array may be a problem

@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Apr 4, 2015
@jreback jreback added this to the 0.16.1 milestone Apr 4, 2015
@tomazberisa
Copy link
Contributor Author

@shoyer Thanks for comments - updated. I have also noticed that some of my commit msgs were not 100% in line with the contribution recommendations, so I've updated them.

@jreback
Copy link
Contributor

jreback commented Apr 5, 2015

ok this lgtm

@jreback jreback changed the title BUG: Fix for #9764 BUG: format small floats correctly (GH9764) Apr 5, 2015
shoyer added a commit that referenced this pull request Apr 6, 2015
BUG: format small floats correctly (GH9764)
@shoyer shoyer merged commit 1fafe76 into pandas-dev:master Apr 6, 2015
@shoyer
Copy link
Member

shoyer commented Apr 6, 2015

Thanks @tomazberisa!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Displaying DataFrame with values from range [1e-7, 5e-7] shows 0 in some situations.
3 participants