Skip to content

BUG GH23224 Allow integer_array to be initialized with all None #23237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ def coerce_to_array(values, dtype, mask=None, copy=False):
inferred_type = infer_dtype(values)
if inferred_type not in ['floating', 'integer',
'mixed-integer', 'mixed-integer-float']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don’t recall if we are checking for exactly ndim == 1 right after we convert to ndarray

can u add this as well ( and some tests)

raise TypeError("{} cannot be converted to an IntegerDtype".format(
values.dtype))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this before the

if inferred_type not in

and make that an elif

if inferred_type is 'mixed' and all(isna(x) for x in values):
values = np.array([np.nan] * len(values)) # GH 23224
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use

isna(values).any() as we always return an. array

else:
raise TypeError(
"{} cannot be converted to an IntegerDtype".format(
values.dtype))

elif not (is_integer_dtype(values) or is_float_dtype(values)):
raise TypeError("{} cannot be converted to an IntegerDtype".format(
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/arrays/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,15 @@ def test_to_integer_array_float():
assert result.dtype == Int64Dtype()


@pytest.mark.parametrize(
'result, expected',
[
(integer_array([None]), integer_array([np.nan])),
(integer_array([None, np.nan]), integer_array([np.nan, np.nan]))])
def test_to_integer_array_none(result, expected):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u also try an array of all np.nan

tm.assert_extension_array_equal(result, expected)


@pytest.mark.parametrize(
'values, to_dtype, result_dtype',
[
Expand Down