Skip to content

Commit 0590df8

Browse files
committed
BUG-23224 Add tests and other requested changes
1 parent 4fd3202 commit 0590df8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pandas/core/arrays/integer.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,12 @@ def coerce_to_array(values, dtype, mask=None, copy=False):
172172
values = np.array(values, copy=copy)
173173
if is_object_dtype(values):
174174
inferred_type = infer_dtype(values)
175-
if inferred_type not in ['floating', 'integer',
176-
'mixed-integer', 'mixed-integer-float']:
177-
if inferred_type is 'mixed' and all(isna(x) for x in values):
178-
values = np.array([np.nan] * len(values)) # GH 23224
179-
else:
180-
raise TypeError(
181-
"{} cannot be converted to an IntegerDtype".format(
182-
values.dtype))
175+
if inferred_type is 'mixed' and isna(values).any():
176+
values = np.array([np.nan] * len(values)) # GH 23224
177+
elif inferred_type not in ['floating', 'integer',
178+
'mixed-integer', 'mixed-integer-float']:
179+
raise TypeError("{} cannot be converted to an IntegerDtype".format(
180+
values.dtype))
183181

184182
elif not (is_integer_dtype(values) or is_float_dtype(values)):
185183
raise TypeError("{} cannot be converted to an IntegerDtype".format(

pandas/tests/arrays/test_integer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ def test_integer_array_constructor_copy():
519519
1,
520520
1.0,
521521
pd.date_range('20130101', periods=2),
522-
np.array(['foo'])])
522+
np.array(['foo']),
523+
[[1, 2], [3, 4]]])
523524
def test_to_integer_array_error(values):
524525
# error in converting existing arrays to IntegerArrays
525526
with pytest.raises(TypeError):
@@ -564,7 +565,8 @@ def test_to_integer_array_float():
564565
'result, expected',
565566
[
566567
(integer_array([None]), integer_array([np.nan])),
567-
(integer_array([None, np.nan]), integer_array([np.nan, np.nan]))])
568+
(integer_array([None, np.nan]), integer_array([np.nan, np.nan])),
569+
(integer_array([np.nan, np.nan]), integer_array([np.nan, np.nan]))])
568570
def test_to_integer_array_none(result, expected):
569571
tm.assert_extension_array_equal(result, expected)
570572

0 commit comments

Comments
 (0)