Skip to content

Commit be8e57a

Browse files
committed
merge master
1 parent 3b1d4f1 commit be8e57a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ ExtensionArray
11901190
- Fixed bug where the constructor of :class:`DataFrame` with ``dtype='string'`` would fail (:issue:`27953`, :issue:`33623`)
11911191
- Bug where :class:`DataFrame` column set to scalar extension type was considered an object type rather than the extension type (:issue:`34832`)
11921192
- Fixed bug in :meth:`IntegerArray.astype` to correctly copy the mask as well (:issue:`34931`).
1193+
- Bug in creating nullable integer ``Series`` while using large-ish integers with ``NaN`` values (:issue:`30268`)
11931194

11941195
Other
11951196
^^^^^

pandas/core/arrays/integer.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ def coerce_to_array(
227227
mask = mask.copy()
228228
return values, mask
229229

230-
values = np.array(values, copy=copy)
230+
typ = dtype.numpy_dtype()
231+
values = np.asarray(values, dtype=typ)
232+
if copy and hasattr(values, 'dtype'):
233+
values = values.copy()
234+
231235
if is_object_dtype(values):
232236
inferred_type = lib.infer_dtype(values, skipna=True)
233237
if inferred_type == "empty":
@@ -239,6 +243,7 @@ def coerce_to_array(
239243
"mixed-integer",
240244
"integer-na",
241245
"mixed-integer-float",
246+
"boolean",
242247
]:
243248
raise TypeError(f"{values.dtype} cannot be converted to an IntegerDtype")
244249

pandas/tests/arrays/integer/test_construction.py

+16
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,19 @@ def test_to_integer_array(values, to_dtype, result_dtype):
197197
assert result.dtype == result_dtype()
198198
expected = integer_array(values, dtype=result_dtype())
199199
tm.assert_extension_array_equal(result, expected)
200+
201+
202+
def test_construction_large_numbers():
203+
# issue 30268
204+
values = [9999999999999999, 123123123123123123, 10000000000000543, np.nan]
205+
expected = pd.Series(
206+
IntegerArray(
207+
np.array(
208+
[9999999999999999, 123123123123123123, 10000000000000543, 0],
209+
dtype="int64",
210+
),
211+
np.array([False, False, False, True]),
212+
)
213+
)
214+
result = pd.Series(values, dtype="Int64")
215+
tm.assert_series_equal(result, expected, check_exact=True)

0 commit comments

Comments
 (0)