| 211 | """Various Series and DataFrame comparison ops methods.""" |
| 212 | |
| 213 | def _compare_other(self, ser: pd.Series, data, op, other): |
| 214 | if op.__name__ in ["eq", "ne"]: |
| 215 | # comparison should match point-wise comparisons |
| 216 | result = op(ser, other) |
| 217 | expected = ser.combine(other, op) |
| 218 | expected = self._cast_pointwise_result(op.__name__, ser, other, expected) |
| 219 | tm.assert_series_equal(result, expected) |
| 220 | |
| 221 | else: |
| 222 | exc = None |
| 223 | try: |
| 224 | result = op(ser, other) |
| 225 | except Exception as err: |
| 226 | exc = err |
| 227 | |
| 228 | if exc is None: |
| 229 | # Didn't error, then should match pointwise behavior |
| 230 | expected = ser.combine(other, op) |
| 231 | expected = self._cast_pointwise_result( |
| 232 | op.__name__, ser, other, expected |
| 233 | ) |
| 234 | tm.assert_series_equal(result, expected) |
| 235 | else: |
| 236 | with pytest.raises(type(exc)): |
| 237 | ser.combine(other, op) |
| 238 | |
| 239 | def test_compare_scalar(self, data, comparison_op): |
| 240 | ser = pd.Series(data) |