Skip to content

Fix rows_from_file() crash on empty or whitespace-only input#809

Open
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-rows-from-file-empty-input
Open

Fix rows_from_file() crash on empty or whitespace-only input#809
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-rows-from-file-empty-input

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Jul 21, 2026

Copy link
Copy Markdown

When rows_from_file() is called without an explicit format on an empty or whitespace-only file, the auto-detect path calls csv.Sniffer().sniff("") which raises csv.Error: Could not determine delimiter. The fix adds an early return of an empty iterator when the peeked bytes are empty after stripping, and a regression test covers both the empty-file and whitespace-only cases. Fixes #808

When no format is specified, the auto-detect path calls csv.Sniffer().sniff()
on the first bytes of the file. For empty or whitespace-only files, strip()
produces an empty byte string, causing sniff("") to raise csv.Error.

Return an empty iterator early when first_bytes is empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rows_from_file() crashes with csv.Error on empty or whitespace-only files

2 participants