mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-43625: Enhance csv sniffer has_headers() to be more accurate (GH-26939)
This commit is contained in:
parent
e3f877c32d
commit
ceea579ccc
4 changed files with 56 additions and 8 deletions
12
Lib/csv.py
12
Lib/csv.py
|
@ -409,14 +409,10 @@ class Sniffer:
|
|||
continue # skip rows that have irregular number of columns
|
||||
|
||||
for col in list(columnTypes.keys()):
|
||||
|
||||
for thisType in [int, float, complex]:
|
||||
try:
|
||||
thisType(row[col])
|
||||
break
|
||||
except (ValueError, OverflowError):
|
||||
pass
|
||||
else:
|
||||
thisType = complex
|
||||
try:
|
||||
thisType(row[col])
|
||||
except (ValueError, OverflowError):
|
||||
# fallback to length of string
|
||||
thisType = len(row[col])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue