Skip to content

Commit 6b4cedb

Browse files
committed
fix: early return on non numeric chars
1 parent 380e6ec commit 6b4cedb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pandas/_libs/parsers.pyx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,14 +1357,33 @@ cdef class TextReader:
13571357

13581358
coliter_setup(&it, self.parser, col, start)
13591359

1360+
ignored_chars = b" +-"
1361+
digits = b"0123456789"
1362+
float_indicating_chars = {self.parser.decimal, b"e", b"E"}
1363+
13601364
for i in range(lines):
13611365
COLITER_NEXT(it, word)
13621366

13631367
if na_filter and kh_get_str_starts_item(na_hashset, word):
13641368
continue
13651369

1366-
if self.parser.decimal in word or b"e" in word or b"E" in word:
1367-
return True
1370+
found_first_digit = False
1371+
for c in word:
1372+
if not found_first_digit and c in ignored_chars:
1373+
continue
1374+
elif not found_first_digit and c not in digits:
1375+
# word isn't numeric
1376+
return False
1377+
elif not found_first_digit:
1378+
found_first_digit = True
1379+
elif c in float_indicating_chars:
1380+
# preceding chars indicates numeric and
1381+
# current char indicates float
1382+
return True
1383+
elif c not in digits:
1384+
# previous characters indicates numeric
1385+
# current character shows otherwise
1386+
return False
13681387

13691388
return False
13701389

0 commit comments

Comments
 (0)