| 122 | @pytest.mark.parametrize("dtype", list(np.typecodes["All"])[1:] + ["i,O"]) |
| 123 | @pytest.mark.parametrize("mode", ["raise", "wrap", "clip"]) |
| 124 | def test_simple(self, dtype, mode): |
| 125 | if dtype.lower() == "m": |
| 126 | dtype += "8[ns]" |
| 127 | |
| 128 | # put is weird and doesn't care about value length (even shorter) |
| 129 | vals = np.arange(1001).astype(dtype=dtype) |
| 130 | |
| 131 | # Use vals.dtype in case of flexible dtype (i.e. string) |
| 132 | arr = np.zeros(1000, dtype=vals.dtype) |
| 133 | zeros = arr.copy() |
| 134 | |
| 135 | if mode == "clip": |
| 136 | # Special because 0 and -1 value are "reserved" for clip test |
| 137 | indx = np.random.permutation(len(arr) - 2)[:-500] + 1 |
| 138 | |
| 139 | indx[-1] = 0 |
| 140 | indx[-2] = len(arr) - 1 |
| 141 | indx_put = indx.copy() |
| 142 | indx_put[-1] = -1389 |
| 143 | indx_put[-2] = 1321 |
| 144 | else: |
| 145 | # Avoid duplicates (for simplicity) and fill half only |
| 146 | indx = np.random.permutation(len(arr) - 3)[:-500] |
| 147 | indx_put = indx |
| 148 | if mode == "wrap": |
| 149 | indx_put = indx_put + len(arr) |
| 150 | |
| 151 | np.put(arr, indx_put, vals, mode=mode) |
| 152 | assert_array_equal(arr[indx], vals[:len(indx)]) |
| 153 | untouched = np.ones(len(arr), dtype=bool) |
| 154 | untouched[indx] = False |
| 155 | assert_array_equal(arr[untouched], zeros[:untouched.sum()]) |
| 156 | |
| 157 | @pytest.mark.parametrize("dtype", list(np.typecodes["All"])[1:] + ["i,O"]) |
| 158 | @pytest.mark.parametrize("mode", ["raise", "wrap", "clip"]) |