Add a delimiters parameter to the csv.Sniffer constructor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
csv.Sniffer.sniff() accepts an optional delimiters argument which restricts the set of characters that can be guessed as a delimiter. has_header() has no such argument, so the restriction cannot be applied to it.
I propose to add an optional delimiters parameter to the constructor, so that it applies to the sniffer rather than to a single call:
sniffer = csv.Sniffer(',;\t')
if sniffer.has_header(sample):
...
dialect = sniffer.sniff(sample)
It is used by both sniff() and has_header(). The delimiters argument of sniff(), if given, still takes precedence.
The given delimiters are also preferred in that order if several of them split the sample equally well: csv.Sniffer(';,') guesses ';' where csv.Sniffer(',;') guesses ','.
Linked PRs
- gh-155060
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the csv.Sniffer constructor, sniff(), and has_header() entry points described in the issue, then inspect the existing CSV tests for their current behavior. Done means the constructor's delimiters restriction is used by both methods, sniff() can override it, and equal candidates follow the supplied delimiter order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100