Skip to content

Commit 6a76485

Browse files
majiayu000claude
andcommitted
BUG: Fix NA comparison inconsistency for object dtype Series
Fix `comp_method_OBJECT_ARRAY` to return `BooleanArray` when input contains `pd.NA` values, ensuring NA is properly propagated in comparison results instead of returning `False`. Previously, when comparing an object dtype Series containing `pd.NA` with a scalar, the vectorized comparison would return `False` for NA positions instead of `<NA>`. Closes #63328 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 35803bc commit 6a76485

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pandas/core/ops/array_ops.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def fill_binop(left, right, fill_value):
114114

115115
def comp_method_OBJECT_ARRAY(op, x, y):
116116
from pandas._libs import missing as libmissing
117+
117118
from pandas.core.arrays import BooleanArray
118119

119120
if isinstance(y, list):
@@ -137,11 +138,8 @@ def comp_method_OBJECT_ARRAY(op, x, y):
137138
# GH#63328: Check if there are pd.NA values in the input and return
138139
# BooleanArray to properly propagate NA in comparisons
139140
x_has_na = any(val is libmissing.NA for val in x.ravel())
140-
y_has_na = (
141-
is_scalar(y) and y is libmissing.NA
142-
) or (
143-
isinstance(y, np.ndarray)
144-
and any(val is libmissing.NA for val in y.ravel())
141+
y_has_na = (is_scalar(y) and y is libmissing.NA) or (
142+
isinstance(y, np.ndarray) and any(val is libmissing.NA for val in y.ravel())
145143
)
146144

147145
if x_has_na or y_has_na:

0 commit comments

Comments
 (0)