@@ -140,8 +140,8 @@ def test_multiple_render(self):
140
140
s = Styler (self .df , uuid_len = 0 ).applymap (lambda x : "color: red;" , subset = ["A" ])
141
141
s .render () # do 2 renders to ensure css styles not duplicated
142
142
assert (
143
- '<style type="text/css" >\n #T__row0_col0,#T__row1_col0{\n '
144
- "color: red;\n } </style>" in s .render ()
143
+ '<style type="text/css">\n #T__row0_col0, #T__row1_col0 {\n '
144
+ " color: red;\n } \n </style>" in s .render ()
145
145
)
146
146
147
147
def test_render_empty_dfs (self ):
@@ -1794,11 +1794,11 @@ def test_column_and_row_styling(self):
1794
1794
df = DataFrame (data = [[0 , 1 ], [1 , 2 ]], columns = ["A" , "B" ])
1795
1795
s = Styler (df , uuid_len = 0 )
1796
1796
s = s .set_table_styles ({"A" : [{"selector" : "" , "props" : [("color" , "blue" )]}]})
1797
- assert "#T__ .col0 {\n color: blue;\n }" in s .render ()
1797
+ assert "#T__ .col0 {\n color: blue;\n }" in s .render ()
1798
1798
s = s .set_table_styles (
1799
1799
{0 : [{"selector" : "" , "props" : [("color" , "blue" )]}]}, axis = 1
1800
1800
)
1801
- assert "#T__ .row0 {\n color: blue;\n }" in s .render ()
1801
+ assert "#T__ .row0 {\n color: blue;\n }" in s .render ()
1802
1802
1803
1803
def test_colspan_w3 (self ):
1804
1804
# GH 36223
@@ -1855,12 +1855,12 @@ def test_tooltip_render(self, ttips):
1855
1855
s = Styler (df , uuid_len = 0 ).set_tooltips (ttips ).render ()
1856
1856
1857
1857
# test tooltip table level class
1858
- assert "#T__ .pd-t {\n visibility: hidden;\n " in s
1858
+ assert "#T__ .pd-t {\n visibility: hidden;\n " in s
1859
1859
1860
1860
# test 'Min' tooltip added
1861
1861
assert (
1862
- "#T__ #T__row0_col0:hover .pd-t {\n visibility: visible;\n } "
1863
- + ' #T__ #T__row0_col0 .pd-t::after {\n content: "Min";\n }'
1862
+ "#T__ #T__row0_col0:hover .pd-t {\n visibility: visible;\n } \n "
1863
+ + '#T__ #T__row0_col0 .pd-t::after {\n content: "Min";\n }'
1864
1864
in s
1865
1865
)
1866
1866
assert (
@@ -1871,8 +1871,8 @@ def test_tooltip_render(self, ttips):
1871
1871
1872
1872
# test 'Max' tooltip added
1873
1873
assert (
1874
- "#T__ #T__row0_col1:hover .pd-t {\n visibility: visible;\n } "
1875
- + ' #T__ #T__row0_col1 .pd-t::after {\n content: "Max";\n }'
1874
+ "#T__ #T__row0_col1:hover .pd-t {\n visibility: visible;\n } \n "
1875
+ + '#T__ #T__row0_col1 .pd-t::after {\n content: "Max";\n }'
1876
1876
in s
1877
1877
)
1878
1878
assert (
@@ -1892,16 +1892,16 @@ def test_tooltip_reindex(self):
1892
1892
index = [0 , 2 ],
1893
1893
)
1894
1894
s = Styler (df , uuid_len = 0 ).set_tooltips (DataFrame (ttips )).render ()
1895
- assert '#T__ #T__row0_col0 .pd-t::after {\n content: "Mi";\n }' in s
1896
- assert '#T__ #T__row0_col2 .pd-t::after {\n content: "Ma";\n }' in s
1897
- assert '#T__ #T__row2_col0 .pd-t::after {\n content: "Mu";\n }' in s
1898
- assert '#T__ #T__row2_col2 .pd-t::after {\n content: "Mo";\n }' in s
1895
+ assert '#T__ #T__row0_col0 .pd-t::after {\n content: "Mi";\n }' in s
1896
+ assert '#T__ #T__row0_col2 .pd-t::after {\n content: "Ma";\n }' in s
1897
+ assert '#T__ #T__row2_col0 .pd-t::after {\n content: "Mu";\n }' in s
1898
+ assert '#T__ #T__row2_col2 .pd-t::after {\n content: "Mo";\n }' in s
1899
1899
1900
1900
def test_tooltip_ignored (self ):
1901
1901
# GH 21266
1902
1902
df = DataFrame (data = [[0 , 1 ], [2 , 3 ]])
1903
1903
s = Styler (df ).set_tooltips_class ("pd-t" ).render () # no set_tooltips()
1904
- assert '<style type="text/css" >\n </style>' in s
1904
+ assert '<style type="text/css">\n </style>' in s
1905
1905
assert '<span class="pd-t"></span>' not in s
1906
1906
1907
1907
def test_tooltip_class (self ):
@@ -1913,11 +1913,8 @@ def test_tooltip_class(self):
1913
1913
.set_tooltips_class (name = "other-class" , properties = [("color" , "green" )])
1914
1914
.render ()
1915
1915
)
1916
- assert "#T__ .other-class {\n color: green;\n " in s
1917
- assert (
1918
- '#T__ #T__row0_col0 .other-class::after {\n content: "tooltip";\n '
1919
- in s
1920
- )
1916
+ assert "#T__ .other-class {\n color: green;\n " in s
1917
+ assert '#T__ #T__row0_col0 .other-class::after {\n content: "tooltip";\n ' in s
1921
1918
1922
1919
# GH 39563
1923
1920
s = (
@@ -1926,10 +1923,50 @@ def test_tooltip_class(self):
1926
1923
.set_tooltips_class (name = "other-class" , properties = "color:green;color:red;" )
1927
1924
.render ()
1928
1925
)
1929
- assert (
1930
- "#T__ .other-class {\n color: green;\n color: red;\n "
1931
- in s
1926
+ assert "#T__ .other-class {\n color: green;\n color: red;\n }" in s
1927
+
1928
+ def test_w3_html_format (self ):
1929
+ s = (
1930
+ Styler (
1931
+ DataFrame ([[2.61 ], [2.69 ]], index = ["a" , "b" ], columns = ["A" ]),
1932
+ uuid_len = 0 ,
1933
+ )
1934
+ .set_table_styles ([{"selector" : "th" , "props" : "att2:v2;" }])
1935
+ .applymap (lambda x : "att1:v1;" )
1936
+ .set_table_attributes ('class="my-cls1" style="attr3:v3;"' )
1937
+ .set_td_classes (DataFrame (["my-cls2" ], index = ["a" ], columns = ["A" ]))
1938
+ .format ("{:.1f}" )
1939
+ .set_caption ("A comprehensive test" )
1932
1940
)
1941
+ expected = """<style type="text/css">
1942
+ #T__ th {
1943
+ att2: v2;
1944
+ }
1945
+ #T__row0_col0, #T__row1_col0 {
1946
+ att1: v1;
1947
+ }
1948
+ </style>
1949
+ <table id="T__" class="my-cls1" style="attr3:v3;">
1950
+ <caption>A comprehensive test</caption>
1951
+ <thead>
1952
+ <tr>
1953
+ <th class="blank level0" ></th>
1954
+ <th class="col_heading level0 col0" >A</th>
1955
+ </tr>
1956
+ </thead>
1957
+ <tbody>
1958
+ <tr>
1959
+ <th id="T__level0_row0" class="row_heading level0 row0" >a</th>
1960
+ <td id="T__row0_col0" class="data row0 col0 my-cls2" >2.6</td>
1961
+ </tr>
1962
+ <tr>
1963
+ <th id="T__level0_row1" class="row_heading level0 row1" >b</th>
1964
+ <td id="T__row1_col0" class="data row1 col0" >2.7</td>
1965
+ </tr>
1966
+ </tbody>
1967
+ </table>
1968
+ """
1969
+ assert expected == s .render ()
1933
1970
1934
1971
1935
1972
@td .skip_if_no_mpl
0 commit comments