Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV Sniffer fails to report mismatch of column counts #42898

Closed
vvrsalob mannequin opened this issue Feb 13, 2006 · 4 comments
Closed

CSV Sniffer fails to report mismatch of column counts #42898

vvrsalob mannequin opened this issue Feb 13, 2006 · 4 comments
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@vvrsalob
Copy link
Mannequin

vvrsalob mannequin commented Feb 13, 2006

BPO 1431091
Nosy @smontanaro

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-03-25.00:59:37.935>
created_at = <Date 2006-02-13.22:47:32.000>
labels = ['extension-modules', 'type-bug']
title = 'CSV Sniffer fails to report mismatch of column counts'
updated_at = <Date 2009-03-25.00:59:37.933>
user = 'https://bugs.python.org/vvrsalob'

bugs.python.org fields:

activity = <Date 2009-03-25.00:59:37.933>
actor = 'skip.montanaro'
assignee = 'andrewmcnamara'
closed = True
closed_date = <Date 2009-03-25.00:59:37.935>
closer = 'skip.montanaro'
components = ['Extension Modules']
creation = <Date 2006-02-13.22:47:32.000>
creator = 'vvrsalob'
dependencies = []
files = []
hgrepos = []
issue_num = 1431091
keywords = []
message_count = 4.0
messages = ['27509', '27510', '57101', '84138']
nosy_count = 4.0
nosy_names = ['skip.montanaro', 'andrewmcnamara', 'vvrsalob', 'tekkaman']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'test needed'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1431091'
versions = ['Python 2.6']

@vvrsalob
Copy link
Mannequin Author

vvrsalob mannequin commented Feb 13, 2006

If one line of a CSV file is missing one or more
commas, the delimiter detection code of the Sniffer
class fails, setting delimiter to an empty string.

This leads to a totally misleading error when using
has_header().

This code shows the problem (Python 2.4.2, FC3 and
Ubuntu Breezy):

import csv

str1 = "a,b,c,d\r\n1,2,foo bar,dead
beef\r\nthis,line,is,ok\r\n"
str2 = "a,b,c,d\r\n1,2,foo bar,dead beef\r\nthis,line
is,not\r\n"

s = csv.Sniffer()

d1 = s.sniff(str1)
d2 = s.sniff(str2)

for line in str1.split('\r\n'):
    print line.count(',')

print d1.delimiter
print s.has_header(str1)

for line in str2.split('\r\n'):
    print line.count(',')

print d2.delimiter
print s.has_header(str2)

@vvrsalob vvrsalob mannequin assigned andrewmcnamara Feb 13, 2006
@vvrsalob vvrsalob mannequin added the extension-modules C modules in the Modules dir label Feb 13, 2006
@vvrsalob vvrsalob mannequin assigned andrewmcnamara Feb 13, 2006
@vvrsalob vvrsalob mannequin added the extension-modules C modules in the Modules dir label Feb 13, 2006
@tekkaman
Copy link
Mannequin

tekkaman mannequin commented Apr 11, 2007

Problem is still there as of Python 2.4.3.

Trying to read in a file whose lines have a different number of fields, I get:

Traceback (most recent call last):
  File "../myscript.py", line 59, in ?
    main()
  File "../myscript.py", line 30, in main
    reader = csv.reader(fin, dialect)
TypeError: bad argument type for built-in operation

where "dialect" has been sniffed by feeding the first two lines to the Sniffer.

What I expect is to either:

  1. get different sized rows, with no exception raised
  2. get a csv.Error instead of the TypeError above

Thanks

@smontanaro
Copy link
Contributor

This appears to work better in 2.5 and 2.6 (it doesn't crash, though it
gets the delimiter wrong) but does indeed fail in 2.4.

@devdanzin devdanzin mannequin added type-bug An unexpected behavior, bug, or error labels Mar 20, 2009
@smontanaro
Copy link
Contributor

Closing as won't fix. There are bound to be limits to how the Sniffer
class works. I'm not sure it's worth the effort necessary to fix this
corner case.

(Andrew, reopen if you want to tackle this.)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant