def test_resource_shape(): with tmpfile('.hdf5') as fn: r = resource(fn+'::/data', dshape='10 * int') assert r.shape == (10,) r.file.close() with tmpfile('.hdf5') as fn: r = resource(fn+'::/data', dshape='10 * 10 * int') assert r.shape == (10, 10) r.file.close() with tmpfile('.hdf5') as fn: r = resource(fn+'::/data', dshape='var * 10 * int') assert r.shape == (0, 10) r.file.close()
def test_resource_shape(): with tmpfile('.hdf5') as fn: r = resource(fn + '::/data', dshape='10 * int') assert r.shape == (10, ) r.file.close() with tmpfile('.hdf5') as fn: r = resource(fn + '::/data', dshape='10 * 10 * int') assert r.shape == (10, 10) r.file.close() with tmpfile('.hdf5') as fn: r = resource(fn + '::/data', dshape='var * 10 * int') assert r.shape == (0, 10) r.file.close()
def test_resource(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('{x: int32, y: 3 * int32}') r = resource(fn, dshape=ds) r2 = resource(fn + '::/x') try: assert isinstance(r, h5py.File) assert discover(r) == ds assert isinstance(r2, h5py.Dataset) finally: r.close() r2.file.close()
def test_resource_with_variable_length(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('var * 4 * int32') r = resource(fn + '::/data', dshape=ds) try: assert r.shape == (0, 4) finally: r.file.close()
def test_resource_with_option_types(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('4 * {name: ?string, amount: ?int32}') r = resource(fn + '::/data', dshape=ds) try: assert r.shape == (4,) assert r.dtype == [('name', 'O'), ('amount', 'f4')] finally: r.file.close()
def test_resource_with_option_types(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('4 * {name: ?string, amount: ?int32}') r = resource(fn + '::/data', dshape=ds) try: assert r.shape == (4, ) assert r.dtype == [('name', 'O'), ('amount', 'f4')] finally: r.file.close()
def test_resource_with_datapath(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('3 * 4 * int32') r = resource(fn + '::/data', dshape=ds) try: assert isinstance(r, h5py.Dataset) assert discover(r) == ds assert r.file.filename == fn assert r.file['/data'] == r finally: r.file.close()
def test_resource_with_h5py_protocol(): with tmpfile('.hdf5') as fn: assert isinstance(resource('h5py://' + fn), h5py.File) with tmpfile('.xyz') as fn: assert isinstance(resource('h5py://' + fn), h5py.File)