8000 ENH: `Styler.apply(map)_index` made compatible with `Styler.to_latex` by attack68 · Pull Request #41993 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Styler.apply(map)_index made compatible with Styler.to_latex #41993

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 32 commits into from
Aug 12, 2021
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ece8855
add apply across index
attack68 Jun 9, 2021
a3a88e5
add applymap across index
attack68 Jun 9, 2021
066e4f3
improve docs
attack68 Jun 9, 2021
50dbcc7
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jun 11, 2021
ef5839f
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jun 12, 2021
5e4c1c0
add column header styling and amend tests
attack68 Jun 12, 2021
20ac7e0
doc sharing
attack68 Jun 13, 2021
26c5340
doc fix
attack68 Jun 13, 2021
2437b72
doc fix
attack68 Jun 13, 2021
312a6e6
collapse the cellstyle maps
attack68 Jun 13, 2021
553426f
add basic test
attack68 Jun 13, 2021
f01dfee
add basic test
attack68 Jun 13, 2021
f940165
parametrise tests
attack68 Jun 13, 2021
6f5b46c
test for raises ValueError
attack68 Jun 13, 2021
75cf6ca
test html working
attack68 Jun 13, 2021
d654139
test html working
attack68 Jun 13, 2021
728091a
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jun 14, 2021
17787ef
whats new 1.4.0
attack68 Jun 14, 2021
c9882aa
make apply_header compatible with to_latex
attack68 Jun 14, 2021
248de0d
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jun 20, 2021
bf6cd10
Merge branch 'styler_apply_index_specific' into styler_apply_index_sp…
attack68 Jun 20, 2021
321458e
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jun 29, 2021
3d2e4bd
Merge branch 'styler_apply_index_specific' into styler_apply_index_sp…
attack68 Jun 29, 2021
ed58798
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jul 13, 2021
b58fc55
Merge branch 'styler_apply_index_specific' into styler_apply_index_sp…
attack68 Jul 13, 2021
8d8e88f
update tests
attack68 Jul 14, 2021
e17d766
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Jul 30, 2021
e0cec44
Merge branch 'styler_apply_index_specific' into styler_apply_index_sp…
attack68 Jul 30, 2021
f70bf65
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Aug 6, 2021
42457de
Merge branch 'styler_apply_index_specific' into styler_apply_index_sp…
attack68 Aug 6, 2021
7ede8cc
Merge remote-tracking branch 'upstream/master' into styler_apply_inde…
attack68 Aug 12, 2021
57ce478
format tests
attack68 Aug 12, 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
parametrise tests
  • Loading branch information
attack68 committed Jun 13, 2021
commit f9401659a49cc40b3be8b6dcad03e88f676f864f
31 changes: 12 additions & 19 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,33 +156,26 @@ def test_render_trimming_mi():
assert {"attributes": 'colspan="2"'}.items() <= ctx["head"][0][2].items()


def test_apply_map_header():
@pytest.mark.parametrize("method", ["applymap", "apply"])
@pytest.mark.parametrize("axis", ["index", "columns"])
def test_apply_map_header(method, axis):
df = DataFrame({"A": [0, 0], "B": [1, 1]}, index=["C", "D"])
func = lambda s: ["attr: val" if ("A" in v or "D" in v) else "" for v in s]
func_map = lambda v: "attr: val" if ("A" in v or "D" in v) else ""
func = {
"apply": lambda s: ["attr: val" if ("A" in v or "C" in v) else "" for v in s],
"applymap": lambda v: "attr: val" if ("A" in v or "C" in v) else "",
}

# test execution added to todo
result = df.style.apply_header(func, axis="index")
result = getattr(df.style, f"{method}_header")(func[method], axis=axis)
assert len(result._todo) == 1
assert len(result.ctx_index) == 0
assert len(getattr(result, f"ctx_{axis}")) == 0

# test over index
# test ctx object on compute
result._compute()
result_map = df.style.applymap_header(func_map, axis="index")._compute()
expected = {
(1, 0): [("attr", "val")],
}
assert result.ctx_index == expected
assert result_map.ctx_index == expected

# test over columns
result = df.style.apply_header(func, axis="columns")._compute()
result_map = df.style.applymap_header(func_map, axis="columns")._compute()
expected = {
(0, 0): [("attr", "val")],
}
assert result.ctx_columns == expected
assert result_map.ctx_columns == expected
assert getattr(result, f"ctx_{axis}") == expected


@pytest.mark.parametrize("method", ["apply", "applymap"])
Expand All @@ -192,7 +185,7 @@ def test_apply_map_header_mi(mi_styler, method, axis):
"apply": lambda s: ["attr: val;" if "b" in v else "" for v in s],
"applymap": lambda v: "attr: val" if "b" in v else "",
}
result = getattr(mi_styler, method + "_header")(func[method], axis=axis)._compute()
result = getattr(mi_styler, f"{method}_header")(func[method], axis=axis)._compute()
expected = {(1, 1): [("attr", "val")]}
assert getattr(result, f"ctx_{axis}") == expected

Expand Down
0