fix: preserve row boundaries in Table text representation

Closed
AL
9mo ago
+53-45

Summary

  • Fixes #4235 — partition_xlsx (and CSV, TSV, PPTX) Table elements lost row boundaries in str(Table) after v0.16.1
  • Root cause: HtmlTable.text used " ".join(self._table.itertext()) which flattened all cell text across all rows into a single space-separated string, destroying row structure
  • Fix: HtmlTable.text now joins cells within a row with spaces and joins rows with newlines, restoring the ability to split table text by \n to get logical rows
  • This was a regression from commit c85f29e6 which replaced soupparser_fromstring().text_content() (which preserved newlines) with the flattening itertext() approach
  • Chunking code is unaffected — it already does its own text extraction independently via iter_cell_texts()

Files changed

  • unstructured/common/html_table.py — HtmlTable.text property: iterate rows via iter_rows() and join with \n instead of flattening all text with spaces
  • test_unstructured/common/test_html_table.py — updated expected text to use newline-separated rows
  • test_unstructured/partition/test_constants.py — updated EXPECTED_TEXT* constants to reflect newline-separated row format
  • test_unstructured/partition/test_xlsx.py — updated direct .text == assertions for subtable and find_subtable=False tests
  • test_unstructured/partition/test_csv.py — removed unnecessary clean_extra_whitespace wrappers and unused import
  • test_unstructured/partition/test_tsv.py — updated header test assertion

Test plan

  • All 74 XLSX tests pass
  • All 24 html_table unit tests pass
  • All CSV tests pass (1 pre-existing failure in test_partition_csv_with_encoding unrelated to this change)
  • All 18 TSV tests pass
  • Linter and formatter clean (ruff check + ruff format)