]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #29405: Make total calculation in _guess_delimiter more accurate.
authorXiang Zhang <angwerzx@126.com>
Mon, 6 Feb 2017 02:50:09 +0000 (10:50 +0800)
committerXiang Zhang <angwerzx@126.com>
Mon, 6 Feb 2017 02:50:09 +0000 (10:50 +0800)
Lib/csv.py

index 0349e0bd1162c4bd6bc7ea3a387e7fbee2e7d873..6a8587674fe02b837fc7568ebafbc1df8189030c 100644 (file)
@@ -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