|
1 | 1 | """HTML formatting utilities for DataFusion DataFrames.""" |
2 | 2 |
|
| 3 | +import sys |
3 | 4 | from typing import Dict, Optional, Any, Union, List, Callable, Type, Protocol |
4 | 5 |
|
5 | 6 |
|
@@ -140,6 +141,14 @@ def format_html( |
140 | 141 | Returns: |
141 | 142 | HTML string representation of the data |
142 | 143 | """ |
| 144 | + print("DEBUG format_html: Called with batches:", len(batches) if batches else 0) |
| 145 | + print( |
| 146 | + f"DEBUG format_html: Type formatters registered: {len(self._type_formatters)}" |
| 147 | + ) |
| 148 | + print( |
| 149 | + f"DEBUG format_html: Has custom cell builder: {self._custom_cell_builder is not None}" |
| 150 | + ) |
| 151 | + |
143 | 152 | if not batches: |
144 | 153 | return "No data to display" |
145 | 154 |
|
@@ -215,16 +224,25 @@ def _build_table_body(self, batches: list, table_uuid: str) -> List[str]: |
215 | 224 | for col_idx, column in enumerate(batch.columns): |
216 | 225 | # Get the raw value from the column |
217 | 226 | raw_value = self._get_cell_value(column, row_idx) |
| 227 | + print( |
| 228 | + f"DEBUG row {row_count}, col {col_idx}: raw_value = {raw_value} ({type(raw_value).__name__})" |
| 229 | + ) |
218 | 230 |
|
219 | 231 | # Always check for type formatters first to format the value |
220 | 232 | formatted_value = self._format_cell_value(raw_value) |
| 233 | + print( |
| 234 | + f"DEBUG row {row_count}, col {col_idx}: formatted_value = {formatted_value}" |
| 235 | + ) |
221 | 236 |
|
222 | 237 | # Then apply either custom cell builder or standard cell formatting |
223 | 238 | if self._custom_cell_builder: |
224 | 239 | # Pass both the raw value and formatted value to let the builder decide |
225 | 240 | cell_html = self._custom_cell_builder( |
226 | 241 | raw_value, row_count, col_idx, table_uuid |
227 | 242 | ) |
| 243 | + print( |
| 244 | + f"DEBUG custom cell builder returned: {cell_html[:50]}..." |
| 245 | + ) |
228 | 246 | html.append(cell_html) |
229 | 247 | else: |
230 | 248 | # Standard cell formatting with formatted value |
@@ -273,7 +291,10 @@ def _format_cell_value(self, value: Any) -> str: |
273 | 291 | # Check for custom type formatters |
274 | 292 | for type_cls, formatter in self._type_formatters.items(): |
275 | 293 | if isinstance(value, type_cls): |
276 | | - return formatter(value) |
| 294 | + print(f"DEBUG formatter match for {type_cls.__name__}: {value}") |
| 295 | + result = formatter(value) |
| 296 | + print(f"DEBUG formatter returned: {result}") |
| 297 | + return result |
277 | 298 |
|
278 | 299 | # If no formatter matched, return string representation |
279 | 300 | return str(value) |
@@ -383,6 +404,10 @@ def get_formatter() -> DataFrameHtmlFormatter: |
383 | 404 | Returns: |
384 | 405 | The global HTML formatter instance |
385 | 406 | """ |
| 407 | + print(f"DEBUG get_formatter: returning instance id={id(_default_formatter)}") |
| 408 | + print( |
| 409 | + f"DEBUG get_formatter: type formatters: {len(_default_formatter._type_formatters)}" |
| 410 | + ) |
386 | 411 | return _default_formatter |
387 | 412 |
|
388 | 413 |
|
|
0 commit comments