Skip to content

csv.Sniffer().sniff() Hangs on Single-Column Data #98820

Description

@jackdesert

Using single-column quoted csv file of this format:

"one-one"
"two-two"
"three-three"
...

If the file is small (say 3,000 rows), it generates an error: _csv.Error: Could not determine delimiter
But if the file is large (say 30,000 rows) the process appears to hang.

Here is a code sample that reproduces this behavior:

import csv
from uuid import uuid4

items = []

items = [f'"{uuid4()}"' for _ in range(30_000)]
print('1. Created uuids')

csv_data = '\n'.join(items)
print('2. Joined')

with open('output', 'w') as h:
    h.write(csv_data)
print('3. Wrote output')

sniffer = csv.Sniffer()

# This is the line than hangs
dialect = sniffer.sniff(csv_data, delimiters=',:|\t')
print(f'4. Sniffed delimiter "{dialiect.delimiter}"')

Metadata

Metadata

Labels

performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

Fields

No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions