Skip to content

Commit 643d12c

Browse files
committed
Apply code formatting (ruff, isort, clang-format)
1 parent 4bc51be commit 643d12c

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

pandas/_libs/src/parser/tokenizer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,12 +1512,13 @@ double xstrtod(const char *str, char **endptr, char decimal, char sci,
15121512
int n = 0;
15131513
// Prevent integer overflow by capping exponent value
15141514
// DBL_MAX_EXP is typically 1024, so we use a safe upper bound
1515-
const int MAX_EXPONENT_DIGITS = 4; // Allows up to 9999
1515+
const int MAX_EXPONENT_DIGITS = 4; // Allows up to 9999
15161516
while (isdigit_ascii(*p)) {
15171517
if (num_digits < MAX_EXPONENT_DIGITS) {
15181518
n = n * 10 + (*p - '0');
15191519
}
1520-
// Continue consuming digits even after cap to maintain correct parsing position
1520+
// Continue consuming digits even after cap to maintain correct parsing
1521+
// position
15211522
num_digits++;
15221523
p++;
15231524
}
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
"""
22
Test for issue #63089 - read_csv segfault with large exponent
33
"""
4+
45
import io
6+
57
import pandas as pd
6-
import pytest
78

89

910
class TestIssue63089:
1011
def test_large_exponent_no_segfault(self):
1112
"""Test that extremely large exponents don't cause segfault."""
1213
# This previously caused SIGSEGV due to integer overflow
1314
# when parsing the exponent
14-
result = pd.read_csv(io.StringIO("""h
15-
4e492493924924"""))
16-
15+
result = pd.read_csv(
16+
io.StringIO("""h
17+
4e492493924924""")
18+
)
19+
1720
# Should parse as infinity or large float, not crash
1821
assert len(result) == 1
19-
assert 'h' in result.columns
22+
assert "h" in result.columns
2023
# The value should be infinity since the exponent is way too large
2124
import numpy as np
22-
assert np.isinf(result['h'].iloc[0]) or result['h'].iloc[0] > 1e308
23-
25+
26+
assert np.isinf(result["h"].iloc[0]) or result["h"].iloc[0] > 1e308
27+
2428
def test_various_large_exponents(self):
2529
"""Test various edge cases with large exponents."""
2630
test_cases = [
2731
"1e999999999", # Very large positive exponent
28-
"1e-999999999", # Very large negative exponent
32+
"1e-999999999", # Very large negative exponent
2933
"2.5e123456789", # Large exponent with decimal
3034
]
31-
35+
3236
for test_val in test_cases:
3337
csv_data = f"col\n{test_val}"
3438
result = pd.read_csv(io.StringIO(csv_data))
3539
# Should not crash, result should be inf, 0, or valid float
3640
assert len(result) == 1
37-
assert not pd.isna(result['col'].iloc[0]) or True # Just don't crash
41+
assert not pd.isna(result["col"].iloc[0]) or True # Just don't crash

reproduce_issue_63089.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import io
2+
23
import pandas as pd
34

45
print("Testing issue #63089...")
56
try:
6-
result = pd.read_csv(io.StringIO("""h
7-
4e492493924924"""))
7+
result = pd.read_csv(
8+
io.StringIO("""h
9+
4e492493924924""")
10+
)
811
print("Success! Result:")
912
print(result)
1013
except Exception as e:

0 commit comments

Comments
 (0)