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
Show file tree
Hide file tree
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
move html tests to html
  • Loading branch information
attack68 committed Apr 14, 2021
commit c876bf664769c0de65af34475dedbf2d69a6eae2
17 changes: 17 additions & 0 deletions pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ def test_w3_html_format():
assert expected == s.render()


def test_colspan_w3():
# GH 36223
df = DataFrame(data=[[1, 2]], columns=[["l0", "l0"], ["l1a", "l1b"]])
s = Styler(df, uuid="_", cell_ids=False)
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' in s.render()


def test_rowspan_w3():
# GH 38533
df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]])
s = Styler(df, uuid="_", cell_ids=False)
assert (
'<th id="T___level0_row0" class="row_heading '
'level0 row0" rowspan="2">l0</th>' in s.render()
)


def test_styles():
s = Styler(DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"]), uuid="abc")
result = s.to_html()
Expand Down
79 changes: 0 additions & 79 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import re
import textwrap

import numpy as np
import pytest
Expand Down Expand Up @@ -1254,21 +1253,6 @@ def test_column_and_row_styling(self):
)
assert "#T__ .row0 {\n color: blue;\n}" in s.render()

def test_colspan_w3(self):
# GH 36223
df = DataFrame(data=[[1, 2]], columns=[["l0", "l0"], ["l1a", "l1b"]])
s = Styler(df, uuid="_", cell_ids=False)
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' in s.render()

def test_rowspan_w3(self):
# GH 38533
df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]])
s = Styler(df, uuid="_", cell_ids=False)
assert (
'<th id="T___level0_row0" class="row_heading '
'level0 row0" rowspan="2">l0</th>' in s.render()
)

@pytest.mark.parametrize("len_", [1, 5, 32, 33, 100])
def test_uuid_len(self, len_):
# GH 36345
Expand All @@ -1289,49 +1273,6 @@ def test_uuid_len_raises(self, len_):
with pytest.raises(TypeError, match=msg):
Styler(df, uuid_len=len_, cell_ids=False).render()

def test_w3_html_format(self):
s = (
Styler(
DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"]),
uuid_len=0,
)
.set_table_styles([{"selector": "th", "props": "att2:v2;"}])
.applymap(lambda x: "att1:v1;")
.set_table_attributes('class="my-cls1" style="attr3:v3;"')
.set_td_classes(DataFrame(["my-cls2"], index=["a"], columns=["A"]))
.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>
"""
assert expected == s.render()

@pytest.mark.parametrize(
"slc",
[
Expand Down Expand Up @@ -1418,23 +1359,3 @@ def test_non_reducing_multi_slice_on_multiindex(self, slice_):
expected = df.loc[slice_]
result = df.loc[non_reducing_slice(slice_)]
tm.assert_frame_equal(result, expected)


def test_from_custom_template(tmpdir):
p = tmpdir.mkdir("templates").join("myhtml.tpl")
p.write(
textwrap.dedent(
"""\
{% extends "html.tpl" %}
{% block table %}
<h1>{{ table_title|default("My Table") }}</h1>
{{ super() }}
{% endblock table %}"""
)
)
result = Styler.from_custom_template(str(tmpdir.join("templates")), "myhtml.tpl")
assert issubclass(result, Styler)
assert result.env is not Styler.env
assert result.template_html is not Styler.template_html
styler = result(DataFrame({"A": [1, 2]}))
assert styler.render()