fix: produce no elements for an empty CSV or TSV file

Merged
BE
23d ago
+42-5

Summary

  • Partitioning an empty (0-byte) or blank-lines-only CSV or TSV file raised a raw pandas.errors.EmptyDataError out of read_delimited_text(), while partition_text(""), partition_md(""), partition_json("") and partition_html("") all return no elements for empty input (issue #4706).
  • read_delimited_text() now turns pd.errors.EmptyDataError into an empty DataFrame, and partition_csv()/partition_tsv() return no elements when the frame has no columns. Guarding on the column count rather than DataFrame.empty keeps the existing behavior for a header-only file with include_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_elements and the two TSV counterparts fail on main with EmptyDataError and 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.py was not runnable in this environment because the image extra is not installed.)
  • ruff check and ruff format --check pass 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.