Skip to content

ENH: Styler.bar height control #42483

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 8 commits into from
Jul 13, 2021
Merged

Conversation

attack68
Copy link
Contributor

I originally thought the issue was too complicated to code for such a small feature, but turns out it was only one or two lines of coding, so I added it in. Quite a nice addition for visualisations I think.

Screen Shot 2021-07-11 at 17 23 59

@attack68 attack68 changed the title Styler bar height ENH: Styler.bar height control Jul 11, 2021
# Conflicts:
#	pandas/tests/io/formats/style/test_align.py
@@ -2911,7 +2922,13 @@ def css_calc(x, left: float, right: float, align: str):
else:
start, end = z_frac, (x - left) / (right - left)

return css_bar(start * width, end * width, color)
ret = css_bar(start * width, end * width, color)
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens for height / width out of bounds? do we raise, is this tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently still renders, but will get bad results. height is a css artifact though so bad CSS just means it gets ignored by the browser.

What do you want to do? Leave as is? Raise on out-of-bounds? or auto trim bad values to be in the range?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think raising is appropriate (don't have to do here), prob needs a dedicated PR as likely need to audit all of these.

@jreback jreback added the Styler conditional formatting using DataFrame.style label Jul 12, 2021
@jreback jreback added this to the 1.4 milestone Jul 12, 2021
# Conflicts:
#	pandas/tests/io/formats/style/test_bar.py
@jreback
Copy link
Contributor

jreback commented Jul 12, 2021

can you rebase

@attack68
Copy link
Contributor Author

done, note the change to keyword only args.

@jreback jreback merged commit b2188e7 into pandas-dev:master Jul 13, 2021
@jreback
Copy link
Contributor

jreback commented Jul 13, 2021

thanks, IIRC elsewhere you are going to followon with a check for invalid height?

@attack68 attack68 deleted the styler_bar_height branch July 13, 2021 13:40
feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: I wish add a parameter to adjust bar function's height in Styler
2 participants