-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
BUG: preserve dtype to bool[pyarrow]
when calling pyarrow backed Series.isna()
#59436
Conversation
bool[pyarrow]
when calling Series.isna()
bool[pyarrow]
when calling pyarrow backed Series.isna()
pandas/core/dtypes/missing.py
Outdated
@@ -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): |
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.
pandas/core/dtypes/missing.py
Outdated
) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
result, index=obj.index, name=obj.name, copy=False | |
new_dtype = "bool[pyarrow]" if isinstance(obj.dtype, ArrowDtype) else None | |
result = obj._constructor(result, index=obj.index, name=obj.name, copy=False, dtype=new_dtype) |
Or something of the sort would be more readable.
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.
You will also need to add a test case to make sure your changes are getting covered on a specific situation.
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.
Since pyarrow operations are implemented as an ExtensionArray, isna
needs to return a numpy array (with it's bool dtype) by defintion https://pandas.pydata.org/docs/reference/api/pandas.api.extensions.ExtensionArray.isna.html#pandas.api.extensions.ExtensionArray.isna
We would need discussion whether to break this API for ArrowExtensionArray
Will apply the changes based on the review within this week. Thanks |
Seems like this breaks some tests on |
Thanks for the PR, but given the issue #59431, this requires more discussion before opening a PR so closing |
isna
on pyarrow backed Series is returning Series withbool
dtype instead ofbool[pyarrow]
#59431 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Test output
Reproducible Example
Before
After