fix: preserve numeric text in table HTML metadata

GY
6mo ago
+207-12

Summary

Refs #3871.

This updates table HTML generation so delimited table partitioners preserve numeric-looking cell text in metadata.text_as_html instead of letting pandas serialize numeric columns through DataFrame.to_html().

Changes:

  • read CSV and TSV data as strings with default NA coercion disabled, preserving source lexemes such as 478923, 000001, 000123, 007, 0.000123, and very large integer-like values
  • render CSV/TSV table HTML through a shared htmlify_dataframe() helper backed by htmlify_matrix_of_cell_texts(), avoiding pandas float/scientific-notation formatting
  • preserve dataframe null values as empty table cells instead of serializing them as nan, None, or <NA> text
  • add regression coverage for CSV and TSV metadata.text_as_html, including TSV file-like input and explicit leading-zero identifiers
  • keep the existing partition_html(..., chunking_strategy="by_title") regression guard for numeric table cells, now including explicit leading-zero values

Notes

I still could not reproduce the scientific-notation conversion through current partition_html() alone with a minimal HTML table fixture. I confirmed the current HTML table partition path does not do an HTML -> DataFrame -> to_html() round-trip: TableBlock.iter_elements() builds table data directly from DOM cell text and renders it through htmlify_matrix_of_cell_texts().

The reproducible lossy path is the DataFrame-backed CSV/TSV table serialization path, which matches the pandas to_html() failure mode discussed in #3871.

Testing

python -m pytest -q test_unstructured\common\test_html_table.py test_unstructured\partition\test_csv.py test_unstructured\partition\test_tsv.py
python -m ruff check unstructured\common\html_table.py unstructured\partition\csv.py unstructured\partition\tsv.py test_unstructured\common\test_html_table.py test_unstructured\partition\test_csv.py test_unstructured\partition\test_tsv.py test_unstructured\partition\html\test_partition.py
python -m ruff format --check unstructured\common\html_table.py unstructured\partition\csv.py unstructured\partition\tsv.py test_unstructured\common\test_html_table.py test_unstructured\partition\test_csv.py test_unstructured\partition\test_tsv.py test_unstructured\partition\html\test_partition.py
git diff --check