Skip to content

Commit 994a634

Browse files
PERF: avoid try parse as int64 if user specified uint64
1 parent a3b458a commit 994a634

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pandas/_libs/parsers.pyx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,20 +1176,27 @@ cdef class TextReader:
11761176
return result, na_count
11771177

11781178
elif is_integer_dtype(dtype):
1179-
try:
1180-
result, na_count = _try_int64(self.parser, i, start,
1181-
end, na_filter, na_hashset)
1182-
if user_dtype and na_count is not None:
1183-
if na_count > 0:
1184-
raise ValueError(f"Integer column has NA values in column {i}")
1185-
except OverflowError as err:
1186-
if user_dtype and dtype == 'int64':
1187-
raise err
1179+
do_try_uint64 = False
1180+
if user_dtype and dtype == 'uint64':
1181+
do_try_uint64 = True
1182+
else:
1183+
try:
1184+
result, na_count = _try_int64(self.parser, i, start,
1185+
end, na_filter, na_hashset)
1186+
if user_dtype and na_count is not None:
1187+
if na_count > 0:
1188+
raise ValueError(f"Integer column has NA values in column {i}")
1189+
except OverflowError as err:
1190+
if user_dtype and dtype == 'int64':
1191+
raise err
1192+
do_try_uint64 = True
1193+
1194+
if do_try_uint64:
11881195
result = _try_uint64(self.parser, i, start, end,
11891196
na_filter, na_hashset)
11901197
na_count = 0
11911198

1192-
if result is not None and dtype != 'int64':
1199+
if result is not None and dtype not in ('int64', 'uint64'):
11931200
casted = result.astype(dtype)
11941201
if (casted == result).all():
11951202
result = casted

0 commit comments

Comments
 (0)