Skip to content

Commit 1b6e3a2

Browse files
committed
fix: make read_csv be able to read large numbers into float
1 parent 5cc3240 commit 1b6e3a2

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

pandas/_libs/parsers.pyx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,9 @@ cdef class TextReader:
10811081
np.dtype("object"), i, start, end, 0,
10821082
0, na_hashset, na_fset)
10831083
except OverflowError:
1084-
col_res, na_count = self._convert_with_dtype(
1085-
np.dtype("object"), i, start, end, na_filter,
1086-
0, na_hashset, na_fset)
1087-
1084+
# Try other dtypes that can accommodate large numbers.
1085+
# (e.g. float and string)
1086+
pass
10881087
if col_res is not None:
10891088
break
10901089

pandas/tests/io/parser/common/test_float.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,28 @@ def test_too_many_exponent_digits(all_parsers_all_precisions, exp, request):
7777
expected = DataFrame({"data": [f"10E{exp}"]})
7878

7979
tm.assert_frame_equal(result, expected)
80+
81+
82+
@pytest.mark.parametrize(
83+
"value, expected_value",
84+
[
85+
("18446744073709551616.5", (1 << 64) + 0.5),
86+
("18446744073709551616", float(1 << 64)),
87+
],
88+
ids=["2pow64_plus_half", "2pow64"],
89+
)
90+
def test_small_int_big_number(
91+
all_parsers_all_precisions, value, expected_value, request
92+
):
93+
# GH#51295
94+
parser, precision = all_parsers_all_precisions
95+
if parser.engine == "python" and value == "18446744073709551616":
96+
mark = pytest.mark.xfail(reason="Still need to work on Python parser")
97+
request.applymarker(mark)
98+
data = f"""data
99+
42
100+
{value}"""
101+
result = parser.read_csv(StringIO(data), float_precision=precision)
102+
expected = DataFrame({"data": [42.0, expected_value]})
103+
104+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)