-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Add Styler.to_html
, for saving output to HTML file
#40312
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
Conversation
# Conflicts: # pandas/tests/io/formats/style/test_style.py
# Conflicts: # pandas/io/formats/style.py
Styler.to_html
can ultimately replace DataFrame.to_html
Styler.to_html
can ultimately replace DataFrame.to_html
Styler.to_html
can ultimately replace DataFrame.to_html
Styler.to_html
, for saving output to HTML file
pandas/io/formats/style.py
Outdated
encoding : str, optional | ||
Character encoding setting for file output, and HTML meta tags, | ||
defaults to "utf-8" if None. | ||
doctype_html : bool, default True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the utility of these last 2 options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctype_html
specifies whether to output a properly formed HTML document with appropriate <html>
, <body>
and <head>
tags, or just the <style>
and <table>
tags.
exclude_styles
provides an option in keeping with DataFrame.to_html()
and it excludes all HTML classes
and HTML ids
and the <style>
tag. (It is also more performant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great very minor comment, ping on green.
exclude_styles: bool = False, | ||
): | ||
""" | ||
Write Styler to a file, buffer or string in HTML-CSS format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a versionadded 1.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
------- | ||
str or None | ||
If `buf` is None, returns the result as a string. Otherwise returns `None`. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a See Also back to DataFrame.to_html (or are we deprecating this in this PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't deprecate yet. working towards but needs a gap analysis: there are some things mising.
@jreback ping: greenish, failure unrelated |
# Conflicts: # pandas/io/formats/style.py
thanks @attack68 |
Styler.to_html
methodThis PR adds the above method to
Styler
.This is a minimal introduction with limited arguments to provide just the core file io functionality and basic options, either to write a fully structured HTML file or just the
Styler.render
output. It is very easier to extend in follow ons.Jinja 2 template inheritance
Due to the more complex logic, the jinja2 templates were split into smaller components:
<style>
html element<table>
element including (or excluding) style identifiersIt is more performant to have a separate temple that excludes styling elements by about 33%, rather than include the logic in a single template. I think it is easier to maintain as well.
Tests
A new
test_to_html.py
file is added. Some tests are moved fromtest_style.py
if they more relate to HTML generation. Some new tests are added.Objective
Ultimately the medium-term aim is to deprecate
DataFrame.to_html
.Styler
is currently faster at rendering HTML thanDataFrame.to_html
(#39972), and this is further improved in this PR.There is a standalone purpose for wanting to create HTML to file from Styler.
This PR complements
Styler.to_latex
whose aim is also to deprecateDataFrame.to_latex
.