コード例 #1
0
def test_full(zarr_version):
    kwargs = _init_creation_kwargs(zarr_version)
    z = full(100, chunks=10, fill_value=42, dtype='i4', **kwargs)
    assert (100, ) == z.shape
    assert (10, ) == z.chunks
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8', **kwargs)
    assert np.all(np.isnan(z[:]))
コード例 #2
0
ファイル: test_creation.py プロジェクト: will133/zarr
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    eq((100, ), z.shape)
    eq((10, ), z.chunks)
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # "NaN"
    z = full(100, chunks=10, fill_value='NaN', dtype='U3')
    assert np.all(z[:] == 'NaN')
コード例 #3
0
ファイル: test_creation.py プロジェクト: alimanfoo/zarr
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    eq((100,), z.shape)
    eq((10,), z.chunks)
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # "NaN"
    z = full(100, chunks=10, fill_value='NaN', dtype='U3')
    assert np.all(z[:] == 'NaN')
コード例 #4
0
def test_open_like(zarr_version):
    kwargs = _init_creation_kwargs(zarr_version)
    expected_zarr_version = DEFAULT_ZARR_VERSION if zarr_version is None else zarr_version

    # zarr array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    z = full(100,
             chunks=10,
             dtype='f4',
             compressor=Zlib(5),
             fill_value=42,
             order='F',
             **kwargs)
    z2 = open_like(z, path)
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    assert (z._store._store_version == z2._store._store_version ==
            expected_zarr_version)
    # numpy array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    a = np.empty(100, dtype='f4')
    z3 = open_like(a, path, chunks=10, zarr_version=zarr_version)
    assert a.shape == z3.shape
    assert (10, ) == z3.chunks
    assert a.dtype == z3.dtype
    assert 0 == z3.fill_value
    assert z3._store._store_version == expected_zarr_version
コード例 #5
0
def test_full_like(zarr_version):

    kwargs = _init_creation_kwargs(zarr_version)
    expected_zarr_version = DEFAULT_ZARR_VERSION if zarr_version is None else zarr_version

    z = full(100,
             chunks=10,
             dtype='f4',
             compressor=Zlib(5),
             fill_value=42,
             order='F',
             **kwargs)
    z2 = full_like(z, path=kwargs.get('path', None))
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    assert (z._store._store_version == z2._store._store_version ==
            expected_zarr_version)
    # numpy array
    a = np.empty(100, dtype='f4')
    z3 = full_like(a, chunks=10, fill_value=42, **kwargs)
    assert a.shape == z3.shape
    assert (10, ) == z3.chunks
    assert a.dtype == z3.dtype
    assert 42 == z3.fill_value
    assert z3._store._store_version == expected_zarr_version
    with pytest.raises(TypeError):
        # fill_value missing
        full_like(a, chunks=10, **kwargs)
コード例 #6
0
def test_open_like():
    # zarr array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    z = full(100,
             chunks=10,
             dtype='f4',
             compressor=Zlib(5),
             fill_value=42,
             order='F')
    z2 = open_like(z, path)
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    # numpy array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    a = np.empty(100, dtype='f4')
    z3 = open_like(a, path, chunks=10)
    assert a.shape == z3.shape
    assert (10, ) == z3.chunks
    assert a.dtype == z3.dtype
    assert 0 == z3.fill_value
コード例 #7
0
ファイル: test_creation.py プロジェクト: will133/zarr
def test_open_like():
    # zarr array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    z = full(100,
             chunks=10,
             dtype='f4',
             compressor=Zlib(5),
             fill_value=42,
             order='F')
    z2 = open_like(z, path)
    eq(z.shape, z2.shape)
    eq(z.chunks, z2.chunks)
    eq(z.dtype, z2.dtype)
    eq(z.compressor.get_config(), z2.compressor.get_config())
    eq(z.fill_value, z2.fill_value)
    eq(z.order, z2.order)
    # numpy array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    a = np.empty(100, dtype='f4')
    z3 = open_like(a, path, chunks=10)
    eq(a.shape, z3.shape)
    eq((10, ), z3.chunks)
    eq(a.dtype, z3.dtype)
    eq(0, z3.fill_value)
コード例 #8
0
def test_create_in_dict():
    for func in [empty, zeros, ones]:
        a = func(100, store=dict())
        assert isinstance(a.store, KVStore)

    a = full(100, 5, store=dict())
    assert isinstance(a.store, KVStore)
コード例 #9
0
ファイル: hierarchy.py プロジェクト: vincentschut/zarr
 def _full_nosync(self, name, fill_value, **kwargs):
     path = self._item_path(name)
     kwargs.setdefault('synchronizer', self._synchronizer)
     return full(store=self._store,
                 path=path,
                 chunk_store=self._chunk_store,
                 fill_value=fill_value,
                 **kwargs)
コード例 #10
0
def test_create_in_dict(zarr_version):
    kwargs = _init_creation_kwargs(zarr_version)
    expected_store_type = KVStoreV3 if zarr_version == 3 else KVStore

    for func in [empty, zeros, ones]:
        a = func(100, store=dict(), **kwargs)
        assert isinstance(a.store, expected_store_type)

    a = full(100, 5, store=dict(), **kwargs)
    assert isinstance(a.store, expected_store_type)
コード例 #11
0
ファイル: test_creation.py プロジェクト: funkey/zarr
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    assert (100, ) == z.shape
    assert (10, ) == z.chunks
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # NaT
    z = full(100, chunks=10, fill_value='NaT', dtype='M8[s]')
    assert np.all(np.isnat(z[:]))
    z = full(100, chunks=10, fill_value='NaT', dtype='m8[s]')
    assert np.all(np.isnat(z[:]))

    # byte string dtype
    v = b'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='S3')
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # unicode string dtype
    v = u'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='U3')
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # bytes fill value / unicode dtype
    v = b'xxx'
    if PY2:  # pragma: py3 no cover
        # allow this on PY2
        z = full(100, chunks=10, fill_value=v, dtype='U3')
        a = z[...]
        assert z.dtype == a.dtype
        assert v == a[0]
        assert np.all(a == v)
    else:  # pragma: py2 no cover
        # be strict on PY3
        with pytest.raises(ValueError):
            full(100, chunks=10, fill_value=v, dtype='U3')
コード例 #12
0
def test_full_additional_dtypes(zarr_version):
    """Test additional types that aren't part of the base v3 spec."""
    kwargs = _init_creation_kwargs(zarr_version)
    # NaT
    z = full(100, chunks=10, fill_value='NaT', dtype='M8[s]', **kwargs)
    assert np.all(np.isnat(z[:]))
    z = full(100, chunks=10, fill_value='NaT', dtype='m8[s]', **kwargs)
    assert np.all(np.isnat(z[:]))

    # byte string dtype
    v = b'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='S3', **kwargs)
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # unicode string dtype
    v = 'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='U3', **kwargs)
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # bytes fill value / unicode dtype
    v = b'xxx'
    with pytest.raises(ValueError):
        full(100, chunks=10, fill_value=v, dtype='U3')
コード例 #13
0
ファイル: test_creation.py プロジェクト: pombredanne/zarr
def test_full_like():
    z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
             fill_value=42, order='F')
    z2 = full_like(z)
    eq(z.shape, z2.shape)
    eq(z.chunks, z2.chunks)
    eq(z.dtype, z2.dtype)
    eq(z.compressor.get_config(), z2.compressor.get_config())
    eq(z.fill_value, z2.fill_value)
    eq(z.order, z2.order)
    # numpy array
    a = np.empty(100, dtype='f4')
    z3 = full_like(a, chunks=10, fill_value=42)
    eq(a.shape, z3.shape)
    eq((10,), z3.chunks)
    eq(a.dtype, z3.dtype)
    eq(42, z3.fill_value)
    with assert_raises(TypeError):
        # fill_value missing
        full_like(a, chunks=10)
コード例 #14
0
ファイル: test_creation.py プロジェクト: martindurant/zarr
def test_full_like():
    z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
             fill_value=42, order='F')
    z2 = full_like(z)
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    # numpy array
    a = np.empty(100, dtype='f4')
    z3 = full_like(a, chunks=10, fill_value=42)
    assert a.shape == z3.shape
    assert (10,) == z3.chunks
    assert a.dtype == z3.dtype
    assert 42 == z3.fill_value
    with pytest.raises(TypeError):
        # fill_value missing
        full_like(a, chunks=10)
コード例 #15
0
def test_full_like():
    z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
             fill_value=42, order='F')
    z2 = full_like(z)
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    # numpy array
    a = np.empty(100, dtype='f4')
    z3 = full_like(a, chunks=10, fill_value=42)
    assert a.shape == z3.shape
    assert (10,) == z3.chunks
    assert a.dtype == z3.dtype
    assert 42 == z3.fill_value
    with pytest.raises(TypeError):
        # fill_value missing
        full_like(a, chunks=10)
コード例 #16
0
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    assert (100, ) == z.shape
    assert (10, ) == z.chunks
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # NaT
    z = full(100, chunks=10, fill_value='NaT', dtype='M8[s]')
    assert np.all(np.isnat(z[:]))
    z = full(100, chunks=10, fill_value='NaT', dtype='m8[s]')
    assert np.all(np.isnat(z[:]))

    # byte string dtype
    v = b'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='S3')
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # unicode string dtype
    v = 'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='U3')
    assert v == z[0]
    a = z[...]
    assert z.dtype == a.dtype
    assert v == a[0]
    assert np.all(a == v)

    # bytes fill value / unicode dtype
    v = b'xxx'
    with pytest.raises(ValueError):
        full(100, chunks=10, fill_value=v, dtype='U3')
コード例 #17
0
ファイル: test_creation.py プロジェクト: pombredanne/zarr
def test_open_like():
    # zarr array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
             fill_value=42, order='F')
    z2 = open_like(z, path)
    eq(z.shape, z2.shape)
    eq(z.chunks, z2.chunks)
    eq(z.dtype, z2.dtype)
    eq(z.compressor.get_config(), z2.compressor.get_config())
    eq(z.fill_value, z2.fill_value)
    eq(z.order, z2.order)
    # numpy array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    a = np.empty(100, dtype='f4')
    z3 = open_like(a, path, chunks=10)
    eq(a.shape, z3.shape)
    eq((10,), z3.chunks)
    eq(a.dtype, z3.dtype)
    eq(0, z3.fill_value)
コード例 #18
0
ファイル: test_creation.py プロジェクト: martindurant/zarr
def test_open_like():
    # zarr array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
             fill_value=42, order='F')
    z2 = open_like(z, path)
    assert z.shape == z2.shape
    assert z.chunks == z2.chunks
    assert z.dtype == z2.dtype
    assert z.compressor.get_config() == z2.compressor.get_config()
    assert z.fill_value == z2.fill_value
    assert z.order == z2.order
    # numpy array
    path = tempfile.mktemp()
    atexit.register(shutil.rmtree, path)
    a = np.empty(100, dtype='f4')
    z3 = open_like(a, path, chunks=10)
    assert a.shape == z3.shape
    assert (10,) == z3.chunks
    assert a.dtype == z3.dtype
    assert 0 == z3.fill_value
コード例 #19
0
ファイル: test_creation.py プロジェクト: pombredanne/zarr
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    eq((100,), z.shape)
    eq((10,), z.chunks)
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # byte string dtype
    v = b'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='S3')
    eq(v, z[0])
    a = z[...]
    eq(z.dtype, a.dtype)
    eq(v, a[0])
    assert np.all(a == v)

    # unicode string dtype
    v = u'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='U3')
    eq(v, z[0])
    a = z[...]
    eq(z.dtype, a.dtype)
    eq(v, a[0])
    assert np.all(a == v)

    # bytes fill value / unicode dtype
    v = b'xxx'
    if PY2:  # pragma: py3 no cover
        # allow this on PY2
        z = full(100, chunks=10, fill_value=v, dtype='U3')
        a = z[...]
        eq(z.dtype, a.dtype)
        eq(v, a[0])
        assert np.all(a == v)
    else:  # pragma: py2 no cover
        # be strict on PY3
        with assert_raises(ValueError):
            full(100, chunks=10, fill_value=v, dtype='U3')
コード例 #20
0
ファイル: test_creation.py プロジェクト: hengthu/zarr
def test_full():
    z = full(100, chunks=10, fill_value=42, dtype='i4')
    eq((100, ), z.shape)
    eq((10, ), z.chunks)
    assert_array_equal(np.full(100, fill_value=42, dtype='i4'), z[:])

    # nan
    z = full(100, chunks=10, fill_value=np.nan, dtype='f8')
    assert np.all(np.isnan(z[:]))

    # byte string dtype
    v = b'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='S3')
    eq(v, z[0])
    a = z[...]
    eq(z.dtype, a.dtype)
    eq(v, a[0])
    assert np.all(a == v)

    # unicode string dtype
    v = u'xxx'
    z = full(100, chunks=10, fill_value=v, dtype='U3')
    eq(v, z[0])
    a = z[...]
    eq(z.dtype, a.dtype)
    eq(v, a[0])
    assert np.all(a == v)

    # bytes fill value / unicode dtype
    v = b'xxx'
    if PY2:  # pragma: py3 no cover
        # allow this on PY2
        z = full(100, chunks=10, fill_value=v, dtype='U3')
        a = z[...]
        eq(z.dtype, a.dtype)
        eq(v, a[0])
        assert np.all(a == v)
    else:  # pragma: py2 no cover
        # be strict on PY3
        with assert_raises(ValueError):
            full(100, chunks=10, fill_value=v, dtype='U3')
コード例 #21
0
ファイル: test_creation.py プロジェクト: will133/zarr
def test_full_like():
    z = full(100,
             chunks=10,
             dtype='f4',
             compressor=Zlib(5),
             fill_value=42,
             order='F')
    z2 = full_like(z)
    eq(z.shape, z2.shape)
    eq(z.chunks, z2.chunks)
    eq(z.dtype, z2.dtype)
    eq(z.compressor.get_config(), z2.compressor.get_config())
    eq(z.fill_value, z2.fill_value)
    eq(z.order, z2.order)
    # numpy array
    a = np.empty(100, dtype='f4')
    z3 = full_like(a, chunks=10, fill_value=42)
    eq(a.shape, z3.shape)
    eq((10, ), z3.chunks)
    eq(a.dtype, z3.dtype)
    eq(42, z3.fill_value)
    with assert_raises(TypeError):
        # fill_value missing
        full_like(a, chunks=10)
コード例 #22
0
ファイル: hierarchy.py プロジェクト: alimanfoo/zarr
 def _full_nosync(self, name, fill_value, **kwargs):
     path = self._item_path(name)
     kwargs.setdefault('synchronizer', self._synchronizer)
     return full(store=self._store, path=path,
                 chunk_store=self._chunk_store,
                 fill_value=fill_value, **kwargs)