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

style.set_precision(0) displays spurious .0 #12134

Closed
xflr6 opened this issue Jan 25, 2016 · 6 comments
Closed

style.set_precision(0) displays spurious .0 #12134

xflr6 opened this issue Jan 25, 2016 · 6 comments
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@xflr6
Copy link
Contributor

xflr6 commented Jan 25, 2016

The expected display format would be as in [2]:
screenshot

@jreback jreback added Bug Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap Difficulty Novice labels Jan 25, 2016
@jreback jreback added this to the Next Major Release milestone Jan 25, 2016
@jreback
Copy link
Contributor

jreback commented Jan 25, 2016

looks a bit buggy, want to do a PR?

@xflr6
Copy link
Contributor Author

xflr6 commented Jan 25, 2016

Okay, I guess the Jinja2 docs recommend to do this by changing this to something like this:

{% if c.value is number %}
    {% if precision %}
        {{c.value|round(precision)}}
     {% else %}
         {{c.value|round|int}}
     {% endif %}
{% else %}

Okay to put another branch like this into the inner loop?

@jreback
Copy link
Contributor

jreback commented Jan 25, 2016

I think that is ok, the rendering time is not usually an issue (unless you are rendering millions of lines, which itself is an issue anyhow).

@TomAugspurger

@xflr6
Copy link
Contributor Author

xflr6 commented Jan 25, 2016

{{c.value|round|int}} fails with nan and inf, so the submitted PR uses percent-formatting

@TomAugspurger
Copy link
Contributor

Sorry, I didn't see this until now. I've got branch that is changing how the display formatting works, which is going to conflict with your PR in #12137. I believe I've fixed this bug in the change (here if you want to take a look at the relevant bit). I'm going to clean that up and submit sometime this week.

It boils down to using formatting like

In [4]: '{:0g}'.format(100.0)
Out[4]: '100'

when your precision is 0

@xflr6
Copy link
Contributor Author

xflr6 commented Jan 25, 2016

No problem, more control over formatting is nice, stepping back.

Does this unify rendering of NaNs (IIRC df.style displays nan and normal html rendering NaN)?

@jreback jreback modified the milestones: 0.18.0, Next Major Release Jan 28, 2016
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Feb 7, 2016
Closes pandas-dev#11692
Closes pandas-dev#12134
Closes pandas-dev#12125

This adds a `.format` method to Styler for formatting the display value
(the actual text) of each scalar value.

In the processes of cleaning up the template, I close pandas-dev#12134 (spurious 0)
and pandas-dev#12125 (KeyError from using iloc improperly)

cherry pick test from pandas-dev#12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Feb 12, 2016
Closes pandas-dev#11692
Closes pandas-dev#12134
Closes pandas-dev#12125

This adds a `.format` method to Styler for formatting the display value
(the actual text) of each scalar value.

In the processes of cleaning up the template, I close pandas-dev#12134 (spurious 0)
and pandas-dev#12125 (KeyError from using iloc improperly)

cherry pick test from pandas-dev#12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
HHammond pushed a commit to HHammond/pandas that referenced this issue Feb 13, 2016
Closes pandas-dev#11692
Closes pandas-dev#12134
Closes pandas-dev#12125

This adds a `.format` method to Styler for formatting the display value
(the actual text) of each scalar value.

In the processes of cleaning up the template, I close pandas-dev#12134 (spurious 0)
and pandas-dev#12125 (KeyError from using iloc improperly)

cherry pick test from pandas-dev#12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants