8000 wip REF: redirect `df.to_html` to Styler if new kwargs are used. by attack68 · Pull Request #45090 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

wip REF: redirect df.to_html to Styler if new kwargs are used. #45090

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

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5b61597
render links
attack68 Dec 24, 2021
fe8dd37
tests
attack68 Dec 24, 2021
11f20eb
whats new
attack68 Dec 24, 2021
a7b3c59
multipl links test
attack68 Dec 24, 2021
bf9b9c2
add LaTeX. chg to `hyperlinks` instead of `render_links`
attack68 Dec 25, 2021
ea9c6a6
whats new update
attack68 Dec 25, 2021
d331a82
extend docs
attack68 Dec 25, 2021
1abc6d9
html deprecation implementation.
attack68 Dec 25, 2021
143f629
add tests, remove conflicting args input
attack68 Dec 27, 2021
b47ac53
Merge remote-tracking branch 'upstream/master' into styler_df_to_html2
attack68 Dec 28, 2021
e8bd87b
rewrite the docs adding deprecations.
attack68 Dec 29, 2021
1fff52a
rewrite the docs adding deprecations.
attack68 Dec 29, 2021
e8f576b
rewrite the docs adding deprecations.
attack68 Dec 29, 2021
1c4528e
rewrite the docs adding deprecations.
attack68 Dec 29, 2021
a43e0a5
rewrite the docs adding deprecations.
attack68 Dec 30, 2021
7057c50
doc warnings
attack68 Jan 2, 2022
182157c
whats new
attack68 Jan 2, 2022
e81dd8b
Merge remote-tracking branch 'upstream/master' into styler_df_to_html2
attack68 Jan 2, 2022
5bf5727
whats new
attack68 Jan 2, 2022
5e2f2a3
fix doc string errors
attack68 Jan 2, 2022
fe2b222
mypy fix
attack68 Jan 2, 2022
c6b74c5
skip no jinja2
attack68 Jan 2, 2022
cf7e5e0
tests for conditional warning based on arg input
attack68 Jan 2, 2022
0972a2c
Merge remote-tracking branch 'upstream/master' into styler_df_to_html2
attack68 Jan 2, 2022
e57c26a
use conventional sphinx links
attack68 Jan 3, 2022
68918aa
fix docstring error
attack68 Jan 3, 2022
4cfc9bf
Merge remote-tracking branch 'upstream/master' into styler_df_to_html2
attack68 Jan 4, 2022
60b81c4
Merge remote-tracking branch 'upstream/master' into styler_df_to_html2
attack68 Jan 5, 2022
a37747f
push to 1.5.0
attack68 Jan 5, 2022
568a92c
push to 1.5.0
attack68 Jan 5, 2022
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
add tests, remove conflicting args input
  • Loading branch information
attack68 committed Dec 27, 2021
commit 143f629f0557b266af5ab5489018133ce17deafc
15 changes: 0 additions & 15 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3299,21 +3299,6 @@ def _to_html_via_styler(

if header is False:
styler.hide(axis=1)
elif isinstance(header, list):
# use styler format to output the column name aliases
if len(header) != len(styler.columns):
raise ValueError(
f"`header` gave {len(header)} aliases for {len(styler.columns)} "
f"columns."
)

def disp(x, v): # use partial to create a distinct, in loop runtime func
return f"{v}"

for i, val in enumerate(header):
styler._display_funcs_columns[(0, i)] = functools.partial(disp, v=val)
if isinstance(styler.columns, MultiIndex):
styler.hide(axis=1, level=list(range(1, styler.columns.nlevels)))
if not index:
styler.hide(axis=0)
if index_names is False or index_names in ["none", "columns"]:
Expand Down
38 changes: 38 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,41 @@ def test_to_html_float_format_object_col(datapath):
result = df.to_html(float_format=lambda x: f"{x:,.0f}")
expected = expected_html(datapath, "gh40024_expected_output")
assert result == expected


#####
# Tests for Styler Implementation of DataFrame.to_html:
# styler implementation has its own tests.
# these test only the parsing of the kwargs to df.to_html and the appropriate action.
#####


@pytest.mark.parametrize("header", [True])
@pytest.mark.parametrize("index_names", [True])
@pytest.mark.parametrize("index", [True])
def test_to_html_styler_header(header, index_names, index):
df = DataFrame([[1]], index=["I"], columns=["C"])
df.columns.name, df.index.name = "Cname", "Iname"
result = df.to_html(
caption="styler_implementation",
index=index,
header=header,
index_names=index_names,
)

assert ("<th >Cname</th>" in result) is index_names
assert ("<th >Iname</th>" in result) is index_names
assert ("<th >C</th>" in result) is header
assert ("<th >I</th>" in result) is index

# check that the styler implementation was called..
assert result != df.to_html(index=index, header=header, index_name=index_names)


def test_to_html_styler_columns_header():
df_base = DataFrame([[1]], index=["I"], columns=["C"])
df = DataFrame([[1, 1]], index=["I"], columns=["C", "D"])

# test column subset is applied
result = df.to_html(caption="styler_implementation", columns=["C"])
assert result == df_base.to_html(caption="styler_implementation")
0