Skip to content

PERF: only output an html id if a style is applied #23019

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
Oct 14, 2018

Conversation

Moisan
Copy link
Contributor

@Moisan Moisan commented Oct 6, 2018

Greatly reduces the amount of id tag in the cells by only assigning one when a style is applied to that cell. If that is the not correct approach for solving #20695, I am open to suggestions.

Also I was confused by the %- tags to handle the whitespaces. Is there a reason the default options to handle whitespace are not used?

@pep8speaks
Copy link

Hello @Moisan! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Oct 6, 2018

Codecov Report

Merging #23019 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23019      +/-   ##
==========================================
+ Coverage    92.2%    92.2%   +<.01%     
==========================================
  Files         169      169              
  Lines       50888    50892       +4     
==========================================
+ Hits        46919    46923       +4     
  Misses       3969     3969
Flag Coverage Δ
#multiple 90.62% <100%> (ø) ⬆️
#single 42.24% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/style.py 96.69% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12a0dc4...1d726a4. Read the comment docs.

@TomAugspurger
Copy link
Contributor

I think this should be a parameter given to the Styler constructor, not something that happens implicitly.

@TomAugspurger TomAugspurger added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Oct 6, 2018
@@ -65,6 +65,8 @@ class Styler(object):
a unique identifier to avoid CSS collisions; generated automatically
caption: str, default None
caption to attach to the table
all_ids: bool, default False
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps cell_ids is a bit more descriptive?

Copy link
Contributor

Choose a reason for hiding this comment

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

And the default should be True (backwards compatible)

@@ -65,6 +65,8 @@ class Styler(object):
a unique identifier to avoid CSS collisions; generated automatically
caption: str, default None
caption to attach to the table
all_ids: bool, default False
if True, each cell will have an ``id`` attribute in their HTML tag.
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalize if.

Could you include the form these take? I believe it's T_<uuid>_row<i>_col<j> for values in the table.

"display_value": formatter(value),
"is_visible": (c not in hidden_columns)}
# only add an id if the cell has a style
if self.all_ids or \
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be if self.cell_ids I think. We don't want a special case for the number of styles.

<tr>
{%- for c in r %}
{%- if c.is_visible != False %}
{%- if c.id: %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not that familiar with jinja, but presumably there's a way to deduplicate this a bit? I worry about these two cases drifting apart in the future.

</tr>
{%- endblock tr %}
{% block before_rows %}{% endblock before_rows %}
{% for r in body %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does removing the opening - change the whitespace? Or was it redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it was redundant.

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 so too.

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Just removed a backslash.

Ping on green.

@Moisan
Copy link
Contributor Author

Moisan commented Oct 14, 2018

@TomAugspurger ping

@TomAugspurger TomAugspurger merged commit 2afe02a into pandas-dev:master Oct 14, 2018
@Moisan Moisan deleted the reduce_html_ids branch October 14, 2018 20:52
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
* PERF: only output an html id if a style is applied

* Add a parameter to Styler constructor

* Use cell_ids instead of all_ids and set default to True

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

Successfully merging this pull request may close these issues.

Huge html with df.style.render to due css duplications
3 participants