BUG: Inconsistency of BooleanArray.__and__ with pd.NA and [pd.NA](fix… #63127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes an inconsistency in how
BooleanArrayhandles logical operations when the right-hand side is a list-like object containingpd.NA. The root cause is in the implementation of_logical_method, where list-like operands are coerced withnp.asarray(other, dtype="bool"). Whenothercontainspd.NA, NumPy attempts to evaluatebool(pd.NA), which always raisesTypeError. This prevents pandas from constructing the appropriate boolean data array and mask that represent missing values in aBooleanArray.The fix replaces the unsafe boolean casting with a safe conversion that preserves
pd.NAvalues. Instead of forcingdtype="bool", the code now converts the input to an object array and passes it throughcoerce_to_array, which correctly constructs both the underlying boolean data and the mask that identifies missing entries. This allows pandas to evaluate expressions likeb & [pd.NA, False]using its normal element-wise logic and return the correct result.BooleanArray.__and__withpd.NAand[pd.NA]#63095(Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.AGENTS.md.