Skip to content

Commit a7a2a9c

Browse files
committed
refactor: streamline imports and enhance HTML formatter integration in tests
- Removed redundant import of `configure_formatter` in `__init__.py`. - Added `configure_formatter` to `__all__` in `__init__.py` for better module exposure. - Cleaned up import statements in `html_formatter.py` for clarity. - Consolidated import statements in `test_dataframe.py` for improved readability. - Simplified the `reset_formatter` fixture by removing unnecessary imports and comments.
1 parent 9495e90 commit a7a2a9c

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

python/datafusion/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
Expr,
4646
WindowFrame,
4747
)
48+
from .html_formatter import configure_formatter
4849
from .io import read_avro, read_csv, read_json, read_parquet
4950
from .plan import ExecutionPlan, LogicalPlan
5051
from .record_batch import RecordBatch, RecordBatchStream
5152
from .udf import Accumulator, AggregateUDF, ScalarUDF, WindowUDF, udaf, udf, udwf
52-
from .html_formatter import configure_formatter
5353

5454
__version__ = importlib_metadata.version(__name__)
5555

@@ -77,6 +77,7 @@
7777
"col",
7878
"column",
7979
"common",
80+
"configure_formatter",
8081
"expr",
8182
"functions",
8283
"lit",
@@ -91,7 +92,6 @@
9192
"udf",
9293
"udwf",
9394
"unparser",
94-
"configure_formatter",
9595
]
9696

9797

python/datafusion/html_formatter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""HTML formatting utilities for DataFusion DataFrames."""
22

3-
import sys
4-
from typing import Dict, Optional, Any, Union, List, Callable, Type, Protocol
3+
from typing import Any, Callable, Dict, List, Optional, Protocol, Type
54

65

76
class CellFormatter(Protocol):

python/tests/test_dataframe.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@
2828
column,
2929
literal,
3030
)
31-
from datafusion import functions as f
31+
from datafusion import (
32+
functions as f,
33+
)
3234
from datafusion.expr import Window
35+
from datafusion.html_formatter import (
36+
_default_formatter,
37+
configure_formatter,
38+
)
3339
from pyarrow.csv import write_csv
3440

3541

@@ -659,28 +665,18 @@ def test_window_frame_defaults_match_postgres(partitioned_df):
659665
@pytest.fixture
660666
def reset_formatter():
661667
"""Reset the HTML formatter after each test."""
662-
from datafusion.html_formatter import configure_formatter
663-
664-
# Store original formatter configuration
665-
from datafusion.html_formatter import _default_formatter
666668

667669
original = _default_formatter
668670

669671
# Give the test a fresh formatter
670672
configure_formatter()
671673

672674
yield
673-
674-
# Completely reset to original state after test
675-
from datafusion.html_formatter import _default_formatter
676-
677675
globals()["_default_formatter"] = original
678676

679677

680678
def test_html_formatter_configuration(df, reset_formatter):
681679
"""Test configuring the HTML formatter with different options."""
682-
from datafusion.html_formatter import configure_formatter
683-
684680
# Configure with custom settings
685681
configure_formatter(
686682
max_cell_length=5,
@@ -700,7 +696,6 @@ def test_html_formatter_configuration(df, reset_formatter):
700696

701697
def test_html_formatter_custom_style_provider(df, reset_formatter):
702698
"""Test using custom style providers with the HTML formatter."""
703-
from datafusion.html_formatter import configure_formatter, StyleProvider
704699

705700
class CustomStyleProvider:
706701
def get_cell_style(self) -> str:
@@ -753,7 +748,7 @@ def custom_cell_builder(value, row, col, table_id):
753748
num_value = int(value)
754749
if num_value > 5: # Values > 5 get green background
755750
return f'<td style="background-color: #d9f0d3">{value}</td>'
756-
elif num_value < 3: # Values < 3 get light blue background
751+
if num_value < 3: # Values < 3 get light blue background
757752
return f'<td style="background-color: #d3e9f0">{value}</td>'
758753
except (ValueError, TypeError):
759754
pass
@@ -804,7 +799,6 @@ def test_html_formatter_complex_customization(df, reset_formatter):
804799
"""Test combining multiple customization options together."""
805800
from datafusion.html_formatter import (
806801
configure_formatter,
807-
StyleProvider,
808802
get_formatter,
809803
)
810804

0 commit comments

Comments
 (0)