fix: preserve row boundaries in Table text representation
Closed
AL
9mo ago+53+53+01234567890123456789-45-45-01234567890123456789
Summary
- Fixes #4235 —
partition_xlsx(and CSV, TSV, PPTX)Tableelements lost row boundaries instr(Table)after v0.16.1 - Root cause:
HtmlTable.textused" ".join(self._table.itertext())which flattened all cell text across all rows into a single space-separated string, destroying row structure - Fix:
HtmlTable.textnow joins cells within a row with spaces and joins rows with newlines, restoring the ability to split table text by\nto get logical rows - This was a regression from commit c85f29e6 which replaced
soupparser_fromstring().text_content()(which preserved newlines) with the flatteningitertext()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.textproperty: iterate rows viaiter_rows()and join with\ninstead of flattening all text with spacestest_unstructured/common/test_html_table.py— updated expected text to use newline-separated rowstest_unstructured/partition/test_constants.py— updatedEXPECTED_TEXT*constants to reflect newline-separated row formattest_unstructured/partition/test_xlsx.py— updated direct.text ==assertions for subtable andfind_subtable=Falseteststest_unstructured/partition/test_csv.py— removed unnecessaryclean_extra_whitespacewrappers and unused importtest_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_encodingunrelated to this change) - All 18 TSV tests pass
- Linter and formatter clean (
ruff check+ruff format)