def test_object_comparison_2d(): left = np.arange(9).reshape(3, 3).astype(object) right = left.T result = comparison_op(left, right, operator.eq) expected = np.eye(3).astype(bool) tm.assert_numpy_array_equal(result, expected) # Ensure that cython doesn't raise on non-writeable arg, which # we can get from np.broadcast_to right.flags.writeable = False result = comparison_op(left, right, operator.ne) tm.assert_numpy_array_equal(result, ~expected)
def wrapper(self, other): res_name = get_op_result_name(self, other) # TODO: shouldn't we be applying finalize whenever # not isinstance(other, ABCSeries)? finalizer = ( lambda x: x.__finalize__(self) if isinstance(other, (np.ndarray, ABCIndexClass)) else x ) if isinstance(other, ABCDataFrame): # pragma: no cover # Defer to DataFrame implementation; fail early return NotImplemented if isinstance(other, ABCSeries) and not self._indexed_same(other): raise ValueError("Can only compare identically-labeled Series objects") lvalues = extract_array(self, extract_numpy=True) rvalues = extract_array(other, extract_numpy=True) res_values = comparison_op(lvalues, rvalues, op) result = self._constructor(res_values, index=self.index) result = finalizer(result) # Set the result's name after finalizer is called because finalizer # would set it back to self.name result.name = res_name return result
def wrapper(self, other): res_name = get_op_result_name(self, other) if isinstance(other, ABCSeries) and not self._indexed_same(other): raise ValueError("Can only compare identically-labeled Series objects") lvalues = extract_array(self, extract_numpy=True) rvalues = extract_array(other, extract_numpy=True) res_values = comparison_op(lvalues, rvalues, op) return _construct_result(self, res_values, index=self.index, name=res_name)
def wrapper(self, other): res_name = get_op_result_name(self, other) if isinstance(other, ABCDataFrame): # pragma: no cover # Defer to DataFrame implementation; fail early return NotImplemented if isinstance(other, ABCSeries) and not self._indexed_same(other): raise ValueError("Can only compare identically-labeled Series objects") lvalues = extract_array(self, extract_numpy=True) rvalues = extract_array(other, extract_numpy=True) res_values = comparison_op(lvalues, rvalues, op) return _construct_result(self, res_values, index=self.index, name=res_name)