def test_zeros_like(): z = zeros(100, 10) z2 = zeros_like(z) eq(z.shape, z2.shape) eq(z.chunks, z2.chunks) eq(z.dtype, z2.dtype) eq(z.cname, z2.cname) eq(z.clevel, z2.clevel) eq(z.shuffle, z2.shuffle) eq(z.fill_value, z2.fill_value)
def test_zeros_like(): z = zeros(100, 10) z2 = zeros_like(z) eq(z.shape, z2.shape) eq(z.chunks, z2.chunks) eq(z.dtype, z2.dtype) eq(z.cname, z2.cname) eq(z.clevel, z2.clevel) eq(z.shuffle, z2.shuffle) eq(z.fill_value, z2.fill_value)
def test_set_basic_selection_0d(): # setup v = np.array(42) a = np.zeros_like(v) z = zarr.zeros_like(v) assert_array_equal(a, z) # tests z.set_basic_selection(Ellipsis, v) assert_array_equal(v, z) z[...] = 0 assert_array_equal(a, z) z[...] = v assert_array_equal(v, z) # test structured array value = (b'aaa', 1, 4.2) v = np.array(value, dtype=[('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')]) a = np.zeros_like(v) z = zarr.create(shape=a.shape, dtype=a.dtype, fill_value=None) # tests z.set_basic_selection(Ellipsis, v) assert_array_equal(v, z) z.set_basic_selection(Ellipsis, a) assert_array_equal(a, z) z[...] = v assert_array_equal(v, z) z[...] = a assert_array_equal(a, z) # with fields z.set_basic_selection(Ellipsis, v['foo'], fields='foo') assert v['foo'] == z['foo'] assert a['bar'] == z['bar'] assert a['baz'] == z['baz'] z['bar'] = v['bar'] assert v['foo'] == z['foo'] assert v['bar'] == z['bar'] assert a['baz'] == z['baz'] # multiple field assignment not supported with pytest.raises(IndexError): z.set_basic_selection(Ellipsis, v[['foo', 'bar']], fields=['foo', 'bar']) with pytest.raises(IndexError): z[..., 'foo', 'bar'] = v[['foo', 'bar']]
def zeros_like(arr): """ Smooth over the differences zeros_likes for different array types Parameters ---------- arr : array-like Returns ------- An zeroed array of the same array type as *arr* """ if isinstance(arr, np.ndarray): return np.zeros_like(arr) elif isinstance(arr, xr.DataArray): return xr.zeros_like(arr) elif isinstance(arr, zarr.Array): return zarr.zeros_like(arr) elif isinstance(arr, da.Array): return da.zeros_like(arr)