After a da.Array.__getitem__ call that returns a scalar, the chunk contains a read-only np.generic instead of a writable np.ndarray. This is a specific quirk of numpy; cupy and other backends always return a 0-dimensional array. Make sure that __setitem__ still works.
()
| 6151 | |
| 6152 | |
| 6153 | def test_scalar_setitem(): |
| 6154 | """After a da.Array.__getitem__ call that returns a scalar, the chunk contains a |
| 6155 | read-only np.generic instead of a writable np.ndarray. This is a specific quirk of |
| 6156 | numpy; cupy and other backends always return a 0-dimensional array. |
| 6157 | Make sure that __setitem__ still works. |
| 6158 | """ |
| 6159 | x = da.zeros(1) |
| 6160 | y = x[0] |
| 6161 | assert isinstance(y.compute(), np.generic) |
| 6162 | y[()] = 2 |
| 6163 | assert_eq(y, 2.0) |
| 6164 | assert isinstance(y.compute(), np.ndarray) |
| 6165 | |
| 6166 | |
| 6167 | @pytest.mark.parametrize( |