python / python/cpython

The CSV file delimiter found with csv.Sniffer() is interpreted incorrectly

Open
#119,123 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.13 3.14 3.15 stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Python script:

import csv

with open("file.csv") as f:
    dialect = csv.Sniffer().sniff(f.read(), delimiters=",;")
    print(dialect.delimiter)

file.csv:

id;has_data;has_info;is_sort;a;b;c;d;cost;group;sub_group;merge
1;False;False;False;True;;;;62.25;['345'];['10'];UNKNOWN
2;False;False;False;True;;;;54.00;['235'];['256'];UNKNOWN
3;False;False;False;True;;;;237.00;['567'];['ALL'];UNKNOWN
4;False;False;False;True;;;;46.50;['112', '112'];['765', '766'];UNKNOWN
5;False;False;False;True;;;;237.00;['468'];['ALL'];UNKNOWN
6;False;False;False;True;;;;13.27;['510'];['23'];UNKNOWN

It outputs , instead ;

CPython versions tested on:

3.11

Operating systems tested on:

Windows

Linked PRs
  • gh-134219

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied script with csv.Sniffer().sniff() and the sample file.csv, then trace the delimiter-detection entry point. Done means the sample consistently reports ';' rather than ',', with a regression test covering the reported input.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.