-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from 1 commit
4fd3202
0590df8
9a2a053
349ca0a
a679c15
14399b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']: | ||
raise TypeError("{} cannot be converted to an IntegerDtype".format( | ||
values.dtype)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
[ | ||
|
There was a problem hiding this comment.
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)