|
11 | 11 | import pytest
|
12 | 12 |
|
13 | 13 | import pandas._libs.parsers as parser
|
14 |
| -from pandas._libs.parsers import TextReader |
| 14 | +from pandas._libs.parsers import TextReader, is_extension_array_dtype |
15 | 15 |
|
16 |
| -from pandas import DataFrame |
| 16 | +from pandas import DataFrame, array |
17 | 17 | import pandas._testing as tm
|
18 | 18 |
|
19 | 19 | from pandas.io.parsers import (
|
@@ -125,6 +125,30 @@ def test_integer_thousands_alt(self):
|
125 | 125 | expected = DataFrame([123456, 12500])
|
126 | 126 | tm.assert_frame_equal(result, expected)
|
127 | 127 |
|
| 128 | + @pytest.mark.parametrize( |
| 129 | + "dtype", [ |
| 130 | + "uint64", "int64", "uint32", "int32", "uint16", "int16", "uint8", "int8", |
| 131 | + "UInt64", "Int64", "UInt32", "Int32", "UInt16", "Int16", "UInt8", "Int8" |
| 132 | + ] |
| 133 | + ) |
| 134 | + def test_integer_overflow_with_user_dtype(self, dtype): |
| 135 | + dtype = ensure_dtype_objs(dtype) |
| 136 | + is_ext_dtype = is_extension_array_dtype(dtype) |
| 137 | + maxint = np.iinfo(dtype.type if is_ext_dtype else dtype).max |
| 138 | + |
| 139 | + reader = TextReader(StringIO(f"{maxint}"), header=None, dtype=dtype) |
| 140 | + result = reader.read() |
| 141 | + if is_ext_dtype: |
| 142 | + expected = array([maxint], dtype=dtype) |
| 143 | + tm.assert_extension_array_equal(result[0], expected) |
| 144 | + else: |
| 145 | + expected = np.array([maxint], dtype=dtype) |
| 146 | + tm.assert_numpy_array_equal(result[0], expected) |
| 147 | + |
| 148 | + reader = TextReader(StringIO(f"{maxint + 1}"), header=None, dtype=dtype) |
| 149 | + with pytest.raises(Exception): |
| 150 | + reader.read() |
| 151 | + |
128 | 152 | def test_skip_bad_lines(self, capsys):
|
129 | 153 | # too many lines, see #2430 for why
|
130 | 154 | data = "a:b:c\nd:e:f\ng:h:i\nj:k:l:m\nl:m:n\no:p:q:r"
|
|
0 commit comments