|
9 | 9 | from pandas import (
|
10 | 10 | DataFrame,
|
11 | 11 | MultiIndex,
|
| 12 | + Series, |
12 | 13 | option_context,
|
13 | 14 | )
|
14 | 15 |
|
@@ -1003,3 +1004,55 @@ def test_to_html_na_rep_non_scalar_data(datapath):
|
1003 | 1004 | </table>
|
1004 | 1005 | """
|
1005 | 1006 | assert result == expected
|
| 1007 | + |
| 1008 | + |
| 1009 | +@pytest.mark.parametrize("escape_axis_0", [True, False]) |
| 1010 | +@pytest.mark.parametrize("escape_axis_1", [True, False]) |
| 1011 | +def test_format_names(escape_axis_0, escape_axis_1): |
| 1012 | + index = Series(["a", "b"], name=">c_name") |
| 1013 | + columns = Series(["A"], name="col_name>") |
| 1014 | + df = DataFrame([[2.61], [2.69]], index=index, columns=columns) |
| 1015 | + styler = Styler(df) |
| 1016 | + |
| 1017 | + if escape_axis_0: |
| 1018 | + styler.format_names(axis=0, escape="html") |
| 1019 | + expected_index = ">c_name" |
| 1020 | + else: |
| 1021 | + expected_index = ">c_name" |
| 1022 | + |
| 1023 | + if escape_axis_1: |
| 1024 | + styler.format_names(axis=1, escape="html") |
| 1025 | + expected_columns = "col_name>" |
| 1026 | + else: |
| 1027 | + expected_columns = "col_name>" |
| 1028 | + |
| 1029 | + result = styler.to_html(table_uuid="test") |
| 1030 | + expected = dedent( |
| 1031 | + f"""\ |
| 1032 | + <style type="text/css"> |
| 1033 | + </style> |
| 1034 | + <table id="T_test"> |
| 1035 | + <thead> |
| 1036 | + <tr> |
| 1037 | + <th class="index_name level0" >{expected_columns}</th> |
| 1038 | + <th id="T_test_level0_col0" class="col_heading level0 col0" >A</th> |
| 1039 | + </tr> |
| 1040 | + <tr> |
| 1041 | + <th class="index_name level0" >{expected_index}</th> |
| 1042 | + <th class="blank col0" > </th> |
| 1043 | + </tr> |
| 1044 | + </thead> |
| 1045 | + <tbody> |
| 1046 | + <tr> |
| 1047 | + <th id="T_test_level0_row0" class="row_heading level0 row0" >a</th> |
| 1048 | + <td id="T_test_row0_col0" class="data row0 col0" >2.610000</td> |
| 1049 | + </tr> |
| 1050 | + <tr> |
| 1051 | + <th id="T_test_level0_row1" class="row_heading level0 row1" >b</th> |
| 1052 | + <td id="T_test_row1_col0" class="data row1 col0" >2.690000</td> |
| 1053 | + </tr> |
| 1054 | + </tbody> |
| 1055 | + </table> |
| 1056 | + """ |
| 1057 | + ) |
| 1058 | + assert result == expected |
0 commit comments