()
| 82 | assert_raises(IndexError, lambda: a[:]) |
| 83 | |
| 84 | def test_operators(): |
| 85 | # For every operator, we test that it works for the required type |
| 86 | # combinations and raises TypeError otherwise |
| 87 | binary_op_dtypes = { |
| 88 | "__add__": "numeric", |
| 89 | "__and__": "integer_or_boolean", |
| 90 | "__eq__": "all", |
| 91 | "__floordiv__": "real numeric", |
| 92 | "__ge__": "real numeric", |
| 93 | "__gt__": "real numeric", |
| 94 | "__le__": "real numeric", |
| 95 | "__lshift__": "integer", |
| 96 | "__lt__": "real numeric", |
| 97 | "__mod__": "real numeric", |
| 98 | "__mul__": "numeric", |
| 99 | "__ne__": "all", |
| 100 | "__or__": "integer_or_boolean", |
| 101 | "__pow__": "numeric", |
| 102 | "__rshift__": "integer", |
| 103 | "__sub__": "numeric", |
| 104 | "__truediv__": "floating", |
| 105 | "__xor__": "integer_or_boolean", |
| 106 | } |
| 107 | # Recompute each time because of in-place ops |
| 108 | def _array_vals(): |
| 109 | for d in _integer_dtypes: |
| 110 | yield asarray(1, dtype=d) |
| 111 | for d in _boolean_dtypes: |
| 112 | yield asarray(False, dtype=d) |
| 113 | for d in _floating_dtypes: |
| 114 | yield asarray(1.0, dtype=d) |
| 115 | |
| 116 | |
| 117 | BIG_INT = int(1e30) |
| 118 | for op, dtypes in binary_op_dtypes.items(): |
| 119 | ops = [op] |
| 120 | if op not in ["__eq__", "__ne__", "__le__", "__ge__", "__lt__", "__gt__"]: |
| 121 | rop = "__r" + op[2:] |
| 122 | iop = "__i" + op[2:] |
| 123 | ops += [rop, iop] |
| 124 | for s in [1, 1.0, 1j, BIG_INT, False]: |
| 125 | for _op in ops: |
| 126 | for a in _array_vals(): |
| 127 | # Test array op scalar. From the spec, the following combinations |
| 128 | # are supported: |
| 129 | |
| 130 | # - Python bool for a bool array dtype, |
| 131 | # - a Python int within the bounds of the given dtype for integer array dtypes, |
| 132 | # - a Python int or float for real floating-point array dtypes |
| 133 | # - a Python int, float, or complex for complex floating-point array dtypes |
| 134 | |
| 135 | if ((dtypes == "all" |
| 136 | or dtypes == "numeric" and a.dtype in _numeric_dtypes |
| 137 | or dtypes == "real numeric" and a.dtype in _real_numeric_dtypes |
| 138 | or dtypes == "integer" and a.dtype in _integer_dtypes |
| 139 | or dtypes == "integer_or_boolean" and a.dtype in _integer_or_boolean_dtypes |
| 140 | or dtypes == "boolean" and a.dtype in _boolean_dtypes |
| 141 | or dtypes == "floating" and a.dtype in _floating_dtypes |
nothing calls this directly
no test coverage detected