-
-
Notifications
You must be signed in to change notification settings - Fork 19k
BUG: Fix cast_pointwise_result with all-NA values #62352
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
e764efa
to
7fe3e03
Compare
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.
this is an option, but i think a more performant approach would be to adapt the dtype_if_all_nat
keyword in maybe_convert_objects to support these cases
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 also think that approach is better. I'll think about how I can use it and apply it.
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 tried the approach you suggested. (d5c6cfb)
At first, I wanted to generalize dtype_if_all_nat
to only dtype_if_all_na
. However, I discovered use-case in the sanitize_array()
function that intentionally only handles NaT cases, and I felt that NA and NaT have different purposes in pandas.
So, I created a new parameter called dtype_if_all_na
, which appears similar but is different, and implemented logic specifically for handling NA only.
I don't yet fully understand pandas' dtypes and codes, so my approach could be wrong. Please feel free to review and I'll fix or revert it.
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.
thanks for trying out my idea, but for now let's go with your previous way of doing it
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.
Okay. I think that's also good because the scope of change is narrow.
I will revert the last commit.
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.
can this replace dtype_if_all_nat instead of adding a new arg?
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.
never mind, i now see that isnt viable.
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.
Yes, It seems not easy. the details are above. #62352 (comment)
There will be pros and cons, but I think the logic of _cast_pointwise_result
is that the current version is clearer. (d5c6cfb)
This reverts commit d5c6cfb.
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Description
Fix a bug in
BaseMaskedArray._cast_pointwise_result
with all-NA values results returnedobject
dtype instead of preserving the original dtype.Additional Notes
In the original issue report the behavior was described for
BooleanDtype
. While preparing the fix, I added tests not only forBooleanDtype
but also for integer dtype under the same all-NA condition. I thought it would be reasonable to ensure consistency across multiple ExtensionArray types.If this is out of scope or unnecessary for this PR, please let me know and I will modify the test for only the Boolean case, as reported in the issue.