summaryrefslogtreecommitdiff
path: root/graphics/py-pytesseract/files/patch-g06e7f807
blob: 71ba847a05ff829b078ad11f07f3134e500783a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
This is obtained from upstream and ADDITIONALLY
changes the try: val = int(row[i]) in upstream int3l@github's version
to int(float(row[i])).   -- Matthias Andree, mandree@FreeBSD.org

From 06e7f8077467950d2f4e0f619fb193730c2d2079 Mon Sep 17 00:00:00 2001
From: int3l <int3l@users.noreply.github.com>
Date: Thu, 27 Jan 2022 16:09:21 +0200
Subject: [PATCH] Fix confidence conversion from str to int

Account for negative values. Fixes #406
---
 pytesseract/pytesseract.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/pytesseract/pytesseract.py b/pytesseract/pytesseract.py
index 984b106..e927e80 100644
--- a/pytesseract/pytesseract.py
+++ b/pytesseract/pytesseract.py
@@ -313,9 +313,14 @@ def file_to_dict(tsv, cell_delimiter, str_col_idx):
             if len(row) <= i:
                 continue
 
-            val = row[i]
-            if row[i].isdigit() and i != str_col_idx:
-                val = int(row[i])
+            if i != str_col_idx:
+                try:
+                    val = int(float(row[i]))
+                except ValueError:
+                    val = row[i]
+            else:
+                val = row[i]
+
             result[head].append(val)
 
     return result