test_array_ops.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import operator
  2. import numpy as np
  3. import pytest
  4. import pandas._testing as tm
  5. from pandas.core.ops.array_ops import (
  6. comparison_op,
  7. na_logical_op,
  8. )
  9. def test_na_logical_op_2d():
  10. left = np.arange(8).reshape(4, 2)
  11. right = left.astype(object)
  12. right[0, 0] = np.nan
  13. # Check that we fall back to the vec_binop branch
  14. with pytest.raises(TypeError, match="unsupported operand type"):
  15. operator.or_(left, right)
  16. result = na_logical_op(left, right, operator.or_)
  17. expected = right
  18. tm.assert_numpy_array_equal(result, expected)
  19. def test_object_comparison_2d():
  20. left = np.arange(9).reshape(3, 3).astype(object)
  21. right = left.T
  22. result = comparison_op(left, right, operator.eq)
  23. expected = np.eye(3).astype(bool)
  24. tm.assert_numpy_array_equal(result, expected)
  25. # Ensure that cython doesn't raise on non-writeable arg, which
  26. # we can get from np.broadcast_to
  27. right.flags.writeable = False
  28. result = comparison_op(left, right, operator.ne)
  29. tm.assert_numpy_array_equal(result, ~expected)