-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from jjhelmus/resizeable
TST: unit tests for resizable datasets
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#! /usr/bin/env python | ||
""" Create a HDF5 file with data with an resizable datasets. """ | ||
|
||
import h5py | ||
import numpy as np | ||
|
||
f = h5py.File('resizable.hdf5', 'w', libver='earliest') | ||
|
||
f.create_dataset( | ||
'dataset1', shape=(4, 6), maxshape=(8, 12), dtype='<f8', | ||
data=np.arange(4 * 6).reshape(4, 6), track_times=False) | ||
|
||
# datasets with unlimited dimensions | ||
f.create_dataset( | ||
'dataset2', shape=(10, 5), maxshape=(10, None), dtype='<i4', | ||
data=np.arange(10*5).reshape(10, 5), track_times=False) | ||
|
||
f.create_dataset( | ||
'dataset3', shape=(8, 4), maxshape=(None, None), dtype='>i2', | ||
data=np.arange(8*4).reshape(8, 4), track_times=False) | ||
|
||
f.close() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" Test pyfive's abililty to read resizable datasets. """ | ||
import os | ||
|
||
import numpy as np | ||
from numpy.testing import assert_array_equal | ||
|
||
import pyfive | ||
|
||
DIRNAME = os.path.dirname(__file__) | ||
DATASET_RESIZABLE_HDF5_FILE = os.path.join(DIRNAME, 'resizable.hdf5') | ||
|
||
|
||
def test_resizable_dataset(): | ||
|
||
with pyfive.File(DATASET_RESIZABLE_HDF5_FILE) as hfile: | ||
|
||
dset1 = hfile['dataset1'] | ||
assert_array_equal(dset1[:], np.arange(4 * 6).reshape((4, 6))) | ||
assert dset1.dtype == '<f8' | ||
|
||
dset2 = hfile['dataset2'] | ||
assert_array_equal(dset2[:], np.arange(10 * 5).reshape((10, 5))) | ||
assert dset2.dtype == '<i4' | ||
|
||
dset3 = hfile['dataset3'] | ||
assert_array_equal(dset3[:], np.arange(8 * 4).reshape((8, 4))) | ||
assert dset3.dtype == '>i2' |