|
15 | 15 | import pytest
|
16 | 16 |
|
17 | 17 | from pandas._libs.tslib import Timestamp
|
| 18 | +from pandas.compat import is_platform_linux |
18 | 19 | from pandas.errors import DtypeWarning, EmptyDataError, ParserError
|
19 | 20 | import pandas.util._test_decorators as td
|
20 | 21 |
|
@@ -1258,15 +1259,14 @@ def test_float_parser(all_parsers):
|
1258 | 1259 | tm.assert_frame_equal(result, expected)
|
1259 | 1260 |
|
1260 | 1261 |
|
1261 |
| -def test_scientific_no_exponent(all_parsers): |
| 1262 | +def test_scientific_no_exponent(all_parsers_all_precisions): |
1262 | 1263 | # see gh-12215
|
1263 | 1264 | df = DataFrame.from_dict({"w": ["2e"], "x": ["3E"], "y": ["42e"], "z": ["632E"]})
|
1264 | 1265 | data = df.to_csv(index=False)
|
1265 |
| - parser = all_parsers |
| 1266 | + parser, precision = all_parsers_all_precisions |
1266 | 1267 |
|
1267 |
| - for precision in parser.float_precision_choices: |
1268 |
| - df_roundtrip = parser.read_csv(StringIO(data), float_precision=precision) |
1269 |
| - tm.assert_frame_equal(df_roundtrip, df) |
| 1268 | + df_roundtrip = parser.read_csv(StringIO(data), float_precision=precision) |
| 1269 | + tm.assert_frame_equal(df_roundtrip, df) |
1270 | 1270 |
|
1271 | 1271 |
|
1272 | 1272 | @pytest.mark.parametrize("conv", [None, np.int64, np.uint64])
|
@@ -1350,6 +1350,35 @@ def test_numeric_range_too_wide(all_parsers, exp_data):
|
1350 | 1350 | tm.assert_frame_equal(result, expected)
|
1351 | 1351 |
|
1352 | 1352 |
|
| 1353 | +@pytest.mark.parametrize("neg_exp", [-617, -100000, -99999999999999999]) |
| 1354 | +def test_very_negative_exponent(all_parsers_all_precisions, neg_exp): |
| 1355 | + # GH#38753 |
| 1356 | + parser, precision = all_parsers_all_precisions |
| 1357 | + data = f"data\n10E{neg_exp}" |
| 1358 | + result = parser.read_csv(StringIO(data), float_precision=precision) |
| 1359 | + expected = DataFrame({"data": [0.0]}) |
| 1360 | + tm.assert_frame_equal(result, expected) |
| 1361 | + |
| 1362 | + |
| 1363 | +@pytest.mark.parametrize("exp", [999999999999999999, -999999999999999999]) |
| 1364 | +def test_too_many_exponent_digits(all_parsers_all_precisions, exp, request): |
| 1365 | + # GH#38753 |
| 1366 | + parser, precision = all_parsers_all_precisions |
| 1367 | + data = f"data\n10E{exp}" |
| 1368 | + result = parser.read_csv(StringIO(data), float_precision=precision) |
| 1369 | + if precision == "round_trip": |
| 1370 | + if exp == 999999999999999999 and is_platform_linux(): |
| 1371 | + mark = pytest.mark.xfail(reason="GH38794, on Linux gives object result") |
| 1372 | + request.node.add_marker(mark) |
| 1373 | + |
| 1374 | + value = np.inf if exp > 0 else 0.0 |
| 1375 | + expected = DataFrame({"data": [value]}) |
| 1376 | + else: |
| 1377 | + expected = DataFrame({"data": [f"10E{exp}"]}) |
| 1378 | + |
| 1379 | + tm.assert_frame_equal(result, expected) |
| 1380 | + |
| 1381 | + |
1353 | 1382 | @pytest.mark.parametrize("iterator", [True, False])
|
1354 | 1383 | def test_empty_with_nrows_chunksize(all_parsers, iterator):
|
1355 | 1384 | # see gh-9535
|
|
0 commit comments