Skip to content

CSV dialect sniffer gets wrong dialect (excel) when tab delimited csv file has been truncated #110128

Closed as not planned

Description

@g-yziquel

Bug report

Bug description:

CSV dialect sniffer gets wrong dialect (excel) when tab delimited csv file has long header fields.

This issue is lifted up here as it was initially raised in the jc cli github repo. Here:

kellyjonbrazil/jc#465

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Linked PRs

Activity

  1. sunmy2019 commented on Sep 29, 2023

    @sunmy2019
    Member

    You'd better provide a repro code that only utilizes Python stdlib.


    You raised a problem with csv.Sniffer.sniff. You think one of its sniff results is inaccurate.

    But, it's just a guess. And guess cannot be perfect.

    What new algo will you raise and how will it affect the current use case?

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Sep 29, 2023
  3. g-yziquel commented on Sep 29, 2023

    @g-yziquel
    Author

    Sure. Any more accurate sniffer is arguably not to be provided out of the box by the stdlib.

    It remains that one of its sniffs is inaccurate, and I could reproduce it with the stdlib. (If that would be genuinely welcome).

    I would however be very wary of making changes to the sniffing algo without a series of tests on a corpus of such CSV files.

    As of today, I have no clue as to how this should be done. But I do believe the CSV files I gave should, in an ideal world, be part of such a testing corpus.

    Feel free to close the issue. I raised it out of personal ethos. If it's just noise to you, please do close it.

  4. ws-garcia commented on Jan 5, 2025

    @ws-garcia

    Hi @g-yziquel, the research on the subject is on its way! Please take a look to the Table Uniformity Method (TUM), also implemented in Python using the built-in csv module.

  5. serhiy-storchaka commented on Jul 21, 2026

    @serhiy-storchaka
    Member

    The problem is not the length of the header fields, but the truncation of the sample: jc sniffs a fixed-size prefix, and the old code counted the incomplete last row as a real one, so the tab was no longer consistent and sniff() raised csv.Error. DummyData.Right.csv is 1024 bytes and fits in the sample entirely, DummyData.Wrong.csv is 1046 bytes and does not; the "right" file fails too if the sample is cut at 512 bytes.

    Fixed in 3.16 by the csv.Sniffer rewrite (gh-83273): the last row is not counted if the sample can be cut off in the middle of it. The maintenance branches are still affected, and a targeted fix for them is welcome.

  6. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Jul 21, 2026
  7. removed their assignment
    on Jul 21, 2026
  8. changed the title [-]CSV dialect sniffer gets wrong dialect (excel) when tab delimited csv file has long header fields[/-] [+]CSV dialect sniffer gets wrong dialect (excel) when tab delimited csv file has been truncated[/+] on Jul 21, 2026
  9. added a commit that references this issue on Aug 1, 2026
  10. encukou commented on Oct 13, 2026

    @encukou
    Member

    @serhiy-storchaka: Myself, I'd leave long-standing behaviour alone in bugfix releases, rather than change it with fixes that aren't in main.
    @hugovk, what's your opinion?

  11. hugovk commented on Oct 29, 2026

    @hugovk
    Member

    Agreed, let's keep the existing behaviour for 3.15 and 3.14.

    The larger #153694 rewrite fixes it for 3.16 (and we decided not to backport that #153694 (comment)).

    Thanks anyway!

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

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesstdlibStandard 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