8000 API: Add `Styler.to_html`, for saving output to HTML file by attack68 · Pull Request #40312 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 42 commits into from
May 26, 2021
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4799d86
json on styler
attack68 Sep 28, 2020
2eb5702
Merge remote-tracking branch 'upstream/master' into json_styler
attack68 Feb 24, 2021
a0bcbd1
meth: to_html
attack68 Feb 25, 2021
5135a91
Merge remote-tracking branch 'upstream/master' into json_styler
attack68 Mar 8, 2021
3e9903d
remove_json
attack68 Mar 8, 2021
766b758
html tests
attack68 Mar 8, 2021
e558a6a
html tests
attack68 Mar 8, 2021
00f8a6e
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Mar 12, 2021
2c440ed
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Mar 21, 2021
dd6785e
to_html parameters
attack68 Mar 22, 2021
e8d0629
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 1, 2021
42cefe6
remove formatting code fro to_html
attack68 Apr 1, 2021
80097cb
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 14, 2021
10f007c
reduce pr scope to simpler initial additions
attack68 Apr 14, 2021
c876bf6
move html tests to html
attack68 Apr 14, 2021
1e5061a
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 15, 2021
130fba4
use dedent
attack68 Apr 15, 2021
5079922
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 18, 2021
339ca37
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 20, 2021
c701d3d
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 21, 2021
3f074aa
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 22, 2021
e1818f2
refactor template inheritance
attack68 Apr 23, 2021
eeeaf54
template inheritance
attack68 Apr 23, 2021
b14e7af
improve tests
attack68 Apr 24, 2021
2a48f4d
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 26, 2021
dda33de
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 26, 2021
b55db71
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 27, 2021
a5c0ec7
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 Apr 29, 2021
1d3ba20
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 1, 2021
4e4c76d
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 6, 2021
f43961d
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 7, 2021
a3ce1ef
make keyword only: simialar to Styler.to_latex()
attack68 May 7, 2021
8899fb5
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 9, 2021
8375f99
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 14, 2021
f5b84fa
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 17, 2021
66ba741
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 18, 2021
d2e2731
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 20, 2021
792ab44
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 22, 2021
2575058
doc comments
attack68 May 22, 2021
c0bc29c
change default doctyoe_html from True to False
attack68 May 22, 2021
489030f
Merge remote-tracking branch 'upstream/master' into styler_to_html
attack68 May 24, 2021
2d996ce
whats new
attack68 May 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use dedent
  • Loading branch information
attack68 committed Apr 15, 2021
commit 130fba49e9d97457ba6a725bb899e7f33e60225e
181 changes: 95 additions & 86 deletions pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import textwrap
from textwrap import dedent

import pytest

Expand Down Expand Up @@ -36,33 +36,36 @@ def test_html_template_extends_options():
def test_exclude_styles():
s = Styler(DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"]))
result = s.to_html(exclude_styles=True)
expected = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table>
<thead>
<tr>
<th >&nbsp;</th>
<th >A</th>
</tr>
</thead>
<tbody>
<tr>
<th >a</th>
<td >2.610000</td>
</tr>
<tr>
<th >b</th>
<td >2.690000</td>
</tr>
</tbody>
</table>
</body>
</html>
"""
expected = dedent(
"""\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table>
<thead>
<tr>
<th >&nbsp;</th>
<th >A</th>
</tr>
</thead>
<tbody>
<tr>
<th >a</th>
<td >2.610000</td>
</tr>
<tr>
<th >b</th>
<td >2.690000</td>
</tr>
</tbody>
</table>
</body>
</html>
"""
)
assert result == expected


Expand All @@ -79,34 +82,37 @@ def test_w3_html_format():
.format("{:.1f}")
.set_caption("A comprehensive test")
)
expected = """<style type="text/css">
#T__ th {
att2: v2;
}
#T__row0_col0, #T__row1_col0 {
att1: v1;
}
</style>
<table id="T__" class="my-cls1" style="attr3:v3;">
<caption>A comprehensive test</caption>
<thead>
<tr>
<th class="blank level0" >&nbsp;</th>
<th class="col_heading level0 col0" >A</th>
</tr>
</thead>
<tbody>
<tr>
<th id="T__level0_row0" class="row_heading level0 row0" >a</th>
<td id="T__row0_col0" class="data row0 col0 my-cls2" >2.6</td>
</tr>
<tr>
<th id="T__level0_row1" class="row_heading level0 row1" >b</th>
<td id="T__row1_col0" class="data row1 col0" >2.7</td>
</tr>
</tbody>
</table>
"""
expected = dedent(
"""\
<style type="text/css">
#T__ th {
att2: v2;
}
#T__row0_col0, #T__row1_col0 {
att1: v1;
}
</style>
<table id="T__" class="my-cls1" style="attr3:v3;">
<caption>A comprehensive test</caption>
<thead>
<tr>
<th class="blank level0" >&nbsp;</th>
<th class="col_heading level0 col0" >A</th>
</tr>
</thead>
<tbody>
<tr>
<th id="T__level0_row0" class="row_heading level0 row0" >a</th>
<td id="T__row0_col0" class="data row0 col0 my-cls2" >2.6</td>
</tr>
<tr>
<th id="T__level0_row1" class="row_heading level0 row1" >b</th>
<td id="T__row1_col0" class="data row1 col0" >2.7</td>
</tr>
</tbody>
</table>
"""
)
assert expected == s.render()


Expand All @@ -130,35 +136,38 @@ def test_rowspan_w3():
def test_styles():
s = Styler(DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"]), uuid="abc")
result = s.to_html()
expected = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<table id="T_abc_">
<thead>
<tr>
<th class="blank level0" >&nbsp;</th>
<th class="col_heading level0 col0" >A</th>
</tr>
</thead>
<tbody>
<tr>
<th id="T_abc_level0_row0" class="row_heading level0 row0" >a</th>
<td id="T_abc_row0_col0" class="data row0 col0" >2.610000</td>
</tr>
<tr>
<th id="T_abc_level0_row1" class="row_heading level0 row1" >b</th>
<td id="T_abc_row1_col0" class="data row1 col0" >2.690000</td>
</tr>
</tbody>
</table>
</body>
</html>
"""
expected = dedent(
"""\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<table id="T_abc_">
<thead>
<tr>
<th class="blank level0" >&nbsp;</th>
<th class="col_heading level0 col0" >A</th>
</tr>
</thead>
<tbody>
<tr>
<th id="T_abc_level0_row0" class="row_heading level0 row0" >a</th>
<td id="T_abc_row0_col0" class="data row0 col0" >2.610000</td>
</tr>
<tr>
<th id="T_abc_level0_row1" class="row_heading level0 row1" >b</th>
<td id="T_abc_row1_col0" class="data row1 col0" >2.690000</td>
</tr>
</tbody>
</table>
</body>
</html>
"""
)
assert result == expected


Expand Down Expand Up @@ -194,7 +203,7 @@ def test_block_names(tpl_styles, tpl_basic):
def test_from_custom_template(tmpdir):
p = tmpdir.mkdir("templates").join("myhtml.tpl")
p.write(
textwrap.dedent(
dedent(
"""\
{% extends "html.tpl" %}
{% block table %}
Expand Down
0