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

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

Comments

Projects
None yet
3 participants
Contributor

xflr6 commented Jan 25, 2016

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

jreback added this to the Next Major Release milestone Jan 25, 2016

Contributor

jreback commented Jan 25, 2016

looks a bit buggy, want to do a PR?

Contributor

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?

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

Contributor

xflr6 commented Jan 25, 2016

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

Contributor

TomAugspurger commented Jan 25, 2016

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

Contributor

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 milestone: 0.18.0, Next Major Release Jan 28, 2016

@TomAugspurger TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Feb 7, 2016

@TomAugspurger TomAugspurger ENH: display_format for style
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 #12134 (spurious 0)
and #12125 (KeyError from using iloc improperly)

cherry pick test from #12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
aee0d90

@TomAugspurger TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Feb 12, 2016

@TomAugspurger TomAugspurger ENH: display_format for style
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 #12134 (spurious 0)
and #12125 (KeyError from using iloc improperly)

cherry pick test from #12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
a3c38fe

jreback closed this in cf8b7f8 Feb 12, 2016

@HHammond HHammond added a commit to HHammond/pandas that referenced this issue Feb 13, 2016

@TomAugspurger @HHammond TomAugspurger + HHammond ENH: display_format for style
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 #12134 (spurious 0)
and #12125 (KeyError from using iloc improperly)

cherry pick test from #12126

only allow str formatting for now

fix tests for new spec

formatter callable

update notebook
a15248a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment