MCPcopy Create free account
hub / github.com/dask/dask / test_scalar_setitem

Function test_scalar_setitem

dask/array/tests/test_array_core.py:6153–6164  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

6151
6152
6153def 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(

Callers

nothing calls this directly

Calls 3

assert_eqFunction · 0.90
zerosMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected