Skip to content

Conversation

heoh
Copy link
Contributor

@heoh heoh commented Sep 16, 2025

Description

Fix a bug in BaseMaskedArray._cast_pointwise_result with all-NA values results returned object 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 for BooleanDtype 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.

Whether to convert datetime, timedelta, period, interval types.
dtype_if_all_na : np.dtype, ExtensionDtype, or None, default None
Dtype to cast to if we have all-NA or all-None.
dtype_if_all_nat : np.dtype, ExtensionDtype, or None, default None
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

@heoh heoh Sep 20, 2025

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)

@jbrockmendel jbrockmendel merged commit 16f57f4 into pandas-dev:main Sep 22, 2025
41 checks passed
@jbrockmendel
Copy link
Member

thanks @heoh

jzwick pushed a commit to jzwick/pandas that referenced this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: cast_pointwise_result with BooleanDtype and all-NA values

2 participants