diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 41367ea6..3a33c54c 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -4013,7 +4013,7 @@ def _get_set_findex_default(self, _slice, out=None, value=None): new_shape = sel_idx.newshape(out.shape) out[sel_idx.raw] = chunk[sub_idx].reshape(new_shape) else: - chunk[sub_idx] = value if np.isscalar(value) else value[sel_idx] + chunk[sub_idx] = value if np.isscalar(value) else value[sel_idx.raw] out = super().set_slice((start, stop), chunk) return out diff --git a/tests/ndarray/test_setitem.py b/tests/ndarray/test_setitem.py index a2145b90..8d81bc97 100644 --- a/tests/ndarray/test_setitem.py +++ b/tests/ndarray/test_setitem.py @@ -110,3 +110,15 @@ def test_ndfield(): fb[:] = blosc2.full(shape, fill_value=1, dtype=np.float64) assert np.allclose(sa["a"][:], nsa["a"]) assert np.allclose(sa["b"][:], nsa["b"]) + + +def test_setitem_fancy_index(): + out = blosc2.zeros(10) + idx = np.array([1, 6, 7]) + value = np.arange(0, 3) + out[idx] = value + + out_numpy = np.zeros(10) + out_numpy[idx] = value + + np.testing.assert_array_equal(out[:], out_numpy)