fix: produce no elements for an empty CSV or TSV file
Merged
BE
23d ago+42+42+01234567890123456789-5-5-0123456789
Summary
- Partitioning an empty (0-byte) or blank-lines-only CSV or TSV file raised a raw
pandas.errors.EmptyDataErrorout ofread_delimited_text(), whilepartition_text(""),partition_md(""),partition_json("")andpartition_html("")all return no elements for empty input (issue #4706). read_delimited_text()now turnspd.errors.EmptyDataErrorinto an empty DataFrame, andpartition_csv()/partition_tsv()return no elements when the frame has no columns. Guarding on the column count rather thanDataFrame.emptykeeps the existing behavior for a header-only file withinclude_header=True, which still produces its one element.- This removes a third-party traceback from pipelines that feed delimited files of unknown provenance into
partition().
Closes #4706
Validation
- New regression tests
test_partition_csv_from_an_empty_file_produces_no_elements,test_partition_csv_from_a_file_of_only_blank_lines_produces_no_elementsand the two TSV counterparts fail onmainwithEmptyDataErrorand pass with this change. pytest test_unstructured/partition/test_csv.py test_unstructured/partition/test_tsv.py— 107 passed, 9 skipped.pytest test_unstructured/file_utils/test_model.py test_unstructured/test_runtime_telemetry.py— 147 passed. (test_auto.pywas not runnable in this environment because the image extra is not installed.)ruff checkandruff format --checkpass on all changed files.
Checklist
- The PR title is a user-facing release-note entry with a conventional commit prefix.
- Apply a category label (
bug): I do not have permission to label; asking a maintainer to apply it.