Skip to content

Commit 2d9b694

Browse files
committed
feat: add method to check if styles are loaded and enhance schema validation in DataFrameHtmlFormatter
1 parent 0f1b1e4 commit 2d9b694

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

python/datafusion/html_formatter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ def set_custom_header_builder(self, builder: Callable[[Any], str]) -> None:
160160
"""
161161
self._custom_header_builder = builder
162162

163+
@classmethod
164+
def is_styles_loaded(cls) -> bool:
165+
"""Check if HTML styles have been loaded in the current session.
166+
167+
This method is primarily intended for debugging UI rendering issues
168+
related to style loading.
169+
170+
Returns:
171+
True if styles have been loaded, False otherwise
172+
173+
Example:
174+
>>> from datafusion.html_formatter import DataFrameHtmlFormatter
175+
>>> DataFrameHtmlFormatter.is_styles_loaded()
176+
False
177+
"""
178+
return cls._styles_loaded
179+
163180
def format_html(
164181
self,
165182
batches: list,
@@ -180,10 +197,25 @@ def format_html(
180197
181198
Returns:
182199
HTML string representation of the data
200+
201+
Raises:
202+
TypeError: If schema is invalid and no batches are provided
183203
"""
184204
if not batches:
185205
return "No data to display"
186206

207+
# Validate schema
208+
if schema is None or not hasattr(schema, "__iter__"):
209+
if batches:
210+
import warnings
211+
212+
warnings.warn(
213+
"Schema not provided or invalid. Using schema from first batch."
214+
)
215+
schema = batches[0].schema
216+
else:
217+
raise TypeError("Schema must be provided when batches list is empty")
218+
187219
# Generate a unique ID if none provided
188220
table_uuid = table_uuid or f"df-{id(batches)}"
189221

0 commit comments

Comments
 (0)