-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF: check can_hold_element instead of try/except #27298
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
Conversation
Confirm that the try/except behavior for fillna is equivalent to checking _can_hold_element
@@ -2275,7 +2271,13 @@ def _can_hold_element(self, element): | |||
tipo = maybe_infer_dtype_type(element) | |||
if tipo is not None: | |||
return tipo == _NS_DTYPE or tipo == np.int64 | |||
return is_integer(element) or isinstance(element, datetime) or isna(element) | |||
if isinstance(element, datetime): |
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.
in followup, can you make these elif
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.
Sure
@@ -2627,6 +2629,8 @@ def _can_hold_element(self, element): | |||
tipo = maybe_infer_dtype_type(element) | |||
if tipo is not None: | |||
return issubclass(tipo.type, (np.timedelta64, np.int64)) | |||
if element is NaT: |
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.
same
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.
though maybe just add this one below on 2634
if you can update to those comments, otherwise lgtm. |
Follow up coming shortly, let’s make elif change there |
thanks @jbrockmendel if you can do those followups in next PRs |
_can_hold_element
is not well-documented, and in local testing it does not match my intution of "we could doself.values[:] = element
without raising". But adding two assertions infillna
does work in all the tests:(at least after patching the
DatetimeBlock
andTimedeltaBlock
implementations)