From 6aee6fbce8f3d7b8c8eae5d8f88fc2282698a6dc Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Mon, 6 Feb 2017 10:50:09 +0800 Subject: [PATCH] Issue #29405: Make total calculation in _guess_delimiter more accurate. --- Lib/csv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/csv.py b/Lib/csv.py index 0349e0bd116..6a8587674fe 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -307,7 +307,7 @@ class Sniffer: 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 @@ class Sniffer: # 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