diff -r b382206aeb2b Lib/csv.py --- a/Lib/csv.py Fri Feb 03 11:08:45 2017 +0800 +++ b/Lib/csv.py Sat Feb 04 14:10:34 2017 +0800 @@ -307,7 +307,7 @@ charFrequency = {} modes = {} delims = {} - start, end = 0, min(chunkLength, len(data)) + start, end = 0, chunkLength while start < len(data): iteration += 1 for line in data[start:end]: @@ -336,7 +336,7 @@ # build a list of possible delimiters modeList = modes.items() - total = float(chunkLength * iteration) + total = float(min(chunkLength * iteration, len(data))) # (rows of consistent data) / (number of rows) = 100% consistency = 1.0 # minimum consistency threshold