fix: auto-detect single-column CSV files - #881
Closed
harsh-thakkar7 wants to merge 1 commit into
Closed
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
Format detection passed the first bytes to csv.Sniffer().sniff(), which
raises csv.Error('Could not determine delimiter') for files with no
delimiter at all, so a bare single-column list like 'id\n1\n2' could
never be loaded through rows_from_file. Fall back to the default CSV
dialect when sniffing fails so DictReader treats the file as a single
column.
Author
|
Closing this — I don't think this change is mature enough to land right now. Thanks for the project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rows_from_file()fails to auto-detect single-column CSV files. Format detection sniffs the first bytes withcsv.Sniffer().sniff(), which raisescsv.Error: Could not determine delimiterfor any file without a delimiter — so a bare list like this could never be imported:Fix
When sniffing fails to find a delimiter, fall back to the default CSV dialect instead of crashing.
csv.DictReader(with no custom dialect) then loads the file as a single column exactly as expected:Multi-column CSV, TSV and JSON auto-detection are unaffected.
Tests
Added to
tests/test_utils.py:test_rows_from_file_detects_single_column_csv[id... ]— parameterized over a single-column list of words and of integers, assertingFormat.CSVand the one-key rows (both fail before this change).📚 Documentation preview 📚: https://sqlite-utils--881.org.readthedocs.build/en/881/