Skip to content

Commit daef69c

Browse files
jbrockmendeljreback
authored andcommitted
BUG: na_logical_op 2D cases (#31263)
1 parent 667bb37 commit daef69c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Diff for: pandas/core/ops/array_ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def na_logical_op(x: np.ndarray, y, op):
277277
assert not (is_bool_dtype(x.dtype) and is_bool_dtype(y.dtype))
278278
x = ensure_object(x)
279279
y = ensure_object(y)
280-
result = libops.vec_binop(x, y, op)
280+
result = libops.vec_binop(x.ravel(), y.ravel(), op)
281281
else:
282282
# let null fall thru
283283
assert lib.is_scalar(y)
@@ -298,7 +298,7 @@ def na_logical_op(x: np.ndarray, y, op):
298298
f"and scalar of type [{typ}]"
299299
)
300300

301-
return result
301+
return result.reshape(x.shape)
302302

303303

304304
def logical_op(

Diff for: pandas/tests/arithmetic/test_array_ops.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import operator
2+
3+
import numpy as np
4+
import pytest
5+
6+
import pandas._testing as tm
7+
from pandas.core.ops.array_ops import na_logical_op
8+
9+
10+
def test_na_logical_op_2d():
11+
left = np.arange(8).reshape(4, 2)
12+
right = left.astype(object)
13+
right[0, 0] = np.nan
14+
15+
# Check that we fall back to the vec_binop branch
16+
with pytest.raises(TypeError, match="unsupported operand type"):
17+
operator.or_(left, right)
18+
19+
result = na_logical_op(left, right, operator.or_)
20+
expected = right
21+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)