33
33
)
34
34
from datafusion .expr import Window
35
35
from datafusion .html_formatter import (
36
+ DataFrameHtmlFormatter ,
36
37
configure_formatter ,
37
38
get_formatter ,
38
39
reset_formatter ,
40
+ reset_styles_loaded_state ,
39
41
)
40
42
from pyarrow .csv import write_csv
41
43
@@ -1514,19 +1516,15 @@ def test_dataframe_repr_html_structure(df) -> None:
1514
1516
# between the <th></th> and <td></td>. We also don't want the closing > on the
1515
1517
# td and th segments because that is where the formatting data is written.
1516
1518
1517
- # Test for headers - this part works fine
1518
1519
headers = ["a" , "b" , "c" ]
1519
1520
headers = [f"<th(.*?)>{ v } </th>" for v in headers ]
1520
1521
header_pattern = "(.*?)" .join (headers )
1521
1522
header_matches = re .findall (header_pattern , output , re .DOTALL )
1522
1523
assert len (header_matches ) == 1
1523
1524
1524
- # The problem is with the body pattern - values are now wrapped in spans
1525
1525
# Update the pattern to handle values that may be wrapped in spans
1526
1526
body_data = [[1 , 4 , 8 ], [2 , 5 , 5 ], [3 , 6 , 8 ]]
1527
1527
1528
- # Create a more flexible pattern that can match both direct values and values
1529
- # in spans
1530
1528
body_lines = [
1531
1529
f"<td(.*?)>(?:<span[^>]*?>)?{ v } (?:</span>)?</td>"
1532
1530
for inner in body_data
@@ -1570,10 +1568,6 @@ def test_dataframe_repr_html_values(df):
1570
1568
1571
1569
def test_html_formatter_shared_styles (df , clean_formatter_state ):
1572
1570
"""Test that shared styles work correctly across multiple tables."""
1573
- from datafusion .html_formatter import (
1574
- configure_formatter ,
1575
- reset_styles_loaded_state ,
1576
- )
1577
1571
1578
1572
# First, ensure we're using shared styles
1579
1573
configure_formatter (use_shared_styles = True )
@@ -1603,7 +1597,6 @@ def test_html_formatter_shared_styles(df, clean_formatter_state):
1603
1597
1604
1598
def test_html_formatter_no_shared_styles (df , clean_formatter_state ):
1605
1599
"""Test that styles are always included when shared styles are disabled."""
1606
- from datafusion .html_formatter import configure_formatter
1607
1600
1608
1601
# Configure formatter to NOT use shared styles
1609
1602
configure_formatter (use_shared_styles = False )
@@ -1621,12 +1614,6 @@ def test_html_formatter_no_shared_styles(df, clean_formatter_state):
1621
1614
1622
1615
def test_html_formatter_manual_format_html (clean_formatter_state ):
1623
1616
"""Test direct usage of format_html method with shared styles."""
1624
- import pyarrow as pa
1625
- from datafusion .html_formatter import (
1626
- DataFrameHtmlFormatter ,
1627
- get_formatter ,
1628
- reset_styles_loaded_state ,
1629
- )
1630
1617
1631
1618
# Create sample data
1632
1619
batch = pa .RecordBatch .from_arrays (
0 commit comments