Skip to content

csv.Sniffer.sniff() raises Could not determine delimiter when the sample contains a field larger than field_size_limit() #157678

Description

@lpyu001

Bug report

Bug description:

Summary

csv.Sniffer().sniff() raises csv.Error: Could not determine delimiter for a sample whose first row contains a field longer than the current csv.field_size_limit() (131072 by default), even when every following row is consistently delimited.

Reproduction Code

import csv 
 
sample = 'a,"' + 'x' * 200_000 + '",b\n' + 'c,d,e\n' * 50 
print(csv.Sniffer().sniff(sample).delimiter) 

Actual Behavior

Traceback (most recent call last): 
  File "repro.py", line 4, in <module> 
    print(csv.Sniffer().sniff(sample).delimiter) 
          ~~~~~~~~~~~~~~~~~~~^^^^^^^^ 
  File "Lib/csv.py", line 384, in sniff 
    raise Error("Could not determine delimiter") 
_csv.Error: Could not determine delimiter 

Expected Behavior

sniff() should return a dialect with `delimiter=','

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions