8000 refactor: improve HTML formatting logic in DataFrame by separating da… · kosiew/datafusion-python@2c3bd60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c3bd60

Browse files
committed
refactor: improve HTML formatting logic in DataFrame by separating data collection and schema retrieval for clarity
refactor: enhance reset_formatter fixture to preserve original formatter configuration during tests
1 parent 0f98b38 commit 2c3bd60

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

python/datafusion/dataframe.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,15 @@ def _repr_html_(self) -> str:
156156
# Import here to avoid circular imports
157157
from datafusion.html_formatter import get_formatter
158158

159-
# Always get the latest formatter
159+
# Always get the latest formatter instance
160160
formatter = get_formatter()
161161

162-
# Format the data using the latest formatter
163-
return formatter.format_html(self.collect(), self.schema())
162+
# Get data and schema
163+
batches = self.collect()
164+
schema = self.schema()
165+
166+
# Format the data using our formatter
167+
return formatter.format_html(batches, schema)
164168

165169
def describe(self) -> DataFrame:
166170
"""Return the statistics for this DataFrame.

python/tests/test_dataframe.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,20 @@ def reset_formatter():
661661
"""Reset the HTML formatter after each test."""
662662
from datafusion.html_formatter import configure_formatter
663663

664+
# Store original formatter configuration
665+
from datafusion.html_formatter import _default_formatter
666+
667+
original = _default_formatter
668+
669+
# Give the test a fresh formatter
670+
configure_formatter()
671+
664672
yield
665-
configure_formatter() # Reset to defaults after test
673+
674+
# Completely reset to original state after test
675+
from datafusion.html_formatter import _default_formatter
676+
677+
globals()["_default_formatter"] = original
666678

667679

668680
def test_html_formatter_configuration(df, reset_formatter):

0 commit comments

Comments
 (0)
0