-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: preserve dtype to bool[pyarrow]
when calling pyarrow backed Series.isna()
#59436
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 4 commits
2710225
85b3ff3
c099d9b
afa2380
c30fb98
3b15abc
9aac9a8
d602fc7
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -28,6 +28,7 @@ | |||||||
is_string_or_object_np_dtype, | ||||||||
) | ||||||||
from pandas.core.dtypes.dtypes import ( | ||||||||
ArrowDtype, | ||||||||
CategoricalDtype, | ||||||||
DatetimeTZDtype, | ||||||||
ExtensionDtype, | ||||||||
|
@@ -206,7 +207,18 @@ def _isna(obj): | |||||||
elif isinstance(obj, ABCSeries): | ||||||||
result = _isna_array(obj._values) | ||||||||
# box | ||||||||
result = obj._constructor(result, index=obj.index, name=obj.name, copy=False) | ||||||||
if isinstance(obj.dtype, ArrowDtype): | ||||||||
result = obj._constructor( | ||||||||
result, | ||||||||
index=obj.index, | ||||||||
name=obj.name, | ||||||||
copy=False, | ||||||||
dtype="bool[pyarrow]", | ||||||||
) | ||||||||
else: | ||||||||
result = obj._constructor( | ||||||||
result, index=obj.index, name=obj.name, copy=False | ||||||||
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.
Suggested change
Or something of the sort would be more readable. 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 will also need to add a test case to make sure your changes are getting covered on a specific situation. |
||||||||
) | ||||||||
return result | ||||||||
elif isinstance(obj, ABCDataFrame): | ||||||||
return obj.isna() | ||||||||
|
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 would usually recommend to avoid any additional nested if statements, it makes it extra verbose and harder to read.
If you look at the signature of the constructor you can choose to pass
dtype=None
if you want to let pandas handle the type internally.