Skip to content

BUG: na_logical_op with 2D inputs #31263

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

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/ops/array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def na_logical_op(x: np.ndarray, y, op):
assert not (is_bool_dtype(x.dtype) and is_bool_dtype(y.dtype))
x = ensure_object(x)
y = ensure_object(y)
result = libops.vec_binop(x, y, op)
result = libops.vec_binop(x.ravel(), y.ravel(), op)
else:
# let null fall thru
assert lib.is_scalar(y)
Expand All @@ -298,7 +298,7 @@ def na_logical_op(x: np.ndarray, y, op):
f"and scalar of type [{typ}]"
)

return result
return result.reshape(x.shape)


def logical_op(
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/arithmetic/test_array_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import operator

import numpy as np
import pytest

import pandas._testing as tm
from pandas.core.ops.array_ops import na_logical_op


def test_na_logical_op_2d():
left = np.arange(8).reshape(4, 2)
right = left.astype(object)
right[0, 0] = np.nan

# Check that we fall back to the vec_binop branch
with pytest.raises(TypeError, match="unsupported operand type"):
operator.or_(left, right)

result = na_logical_op(left, right, operator.or_)
expected = right
tm.assert_numpy_array_equal(result, expected)