Skip to content

Commit c8b45e0

Browse files
JustinZhengBCjreback
authored andcommitted
BUG GH23224 Allow integer_array to be initialized with all None (#23237)
1 parent 9308c7c commit c8b45e0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pandas/core/arrays/integer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ def coerce_to_array(values, dtype, mask=None, copy=False):
173173
values = np.array(values, copy=copy)
174174
if is_object_dtype(values):
175175
inferred_type = lib.infer_dtype(values)
176-
if inferred_type not in ['floating', 'integer',
177-
'mixed-integer', 'mixed-integer-float']:
176+
if inferred_type is 'mixed' and isna(values).any():
177+
values = np.empty(len(values))
178+
values.fill(np.nan)
179+
elif inferred_type not in ['floating', 'integer',
180+
'mixed-integer', 'mixed-integer-float']:
178181
raise TypeError("{} cannot be converted to an IntegerDtype".format(
179182
values.dtype))
180183

pandas/tests/arrays/test_integer.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ def test_integer_array_constructor():
527527

528528
@pytest.mark.parametrize('a, b', [
529529
([1, None], [1, np.nan]),
530-
pytest.param([None], [np.nan],
531-
marks=pytest.mark.xfail(reason='GH-23224',
532-
strict=True)),
530+
([None], [np.nan]),
531+
([None, np.nan], [np.nan, np.nan]),
532+
([np.nan, np.nan], [np.nan, np.nan]),
533533
])
534534
def test_integer_array_constructor_none_is_nan(a, b):
535535
result = integer_array(a)
@@ -559,7 +559,8 @@ def test_integer_array_constructor_copy():
559559
1,
560560
1.0,
561561
pd.date_range('20130101', periods=2),
562-
np.array(['foo'])])
562+
np.array(['foo']),
563+
[[1, 2], [3, 4]]])
563564
def test_to_integer_array_error(values):
564565
# error in converting existing arrays to IntegerArrays
565566
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)