Skip to content

Simple csv file can't be parsed correctly because of Sniffer() parameters #622

Description

@lap1nou

Greetings,

First of all, thank you for the work you are doing on this library.

I have the following CSV file, where the delimiter is a colon : :

test:test2
value1:value2

I'm now using the tablib library to import it:

tmp = open('test.csv', 'r')
tmp2 = tablib.Dataset().load(tmp, format='csv')

But the file is wrongly parsed, because the csv library did not sniffed the delimiter correctly:

test:test2   
-------------
value1:value2

I saw that you are passing 2048 bytes of samples to be sniffed (

csv.Sniffer().sniff(stream.read(2048), delimiters=delimiter or cls.DEFAULT_DELIMITER)
), I now tested to manually sniff the CSV using only the first line:

dialect = csv.Sniffer().sniff(tmp.readline())

The delimiter is now indeed recognized as a colon :.

My question is: shouldn't you pass the first line to sniff only (using readline()) ? Or maybe fallback on the actual behaviour only if the headers is not present in the file ?

Related issue: #502

Regards

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions