From d24d3d981c79b00e55422a325f0ed207ca6d6fc8 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Fri, 26 Jul 2024 00:22:40 -0700 Subject: [PATCH] Add doc to H5DataIO.dataset setter --- src/hdmf/backends/hdf5/h5_utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/hdmf/backends/hdf5/h5_utils.py b/src/hdmf/backends/hdf5/h5_utils.py index 8654e2b4b..fa236d2e3 100644 --- a/src/hdmf/backends/hdf5/h5_utils.py +++ b/src/hdmf/backends/hdf5/h5_utils.py @@ -546,10 +546,29 @@ def __init__(self, **kwargs): @property def dataset(self): + """Get the cached h5py.Dataset.""" return self.__dataset @dataset.setter def dataset(self, val): + """Cache an h5py.Dataset, which can be used to cache a written, empty dataset and fill it in later. + + This allows users to access the handle to the dataset *without* having to close and repoen a file. + + For example:: + + dataio = H5DataIO(shape=(5,), dtype=int) + foo = Foo('foo1', dataio, "I am foo1", 17, 3.14) + bucket = FooBucket('bucket1', [foo]) + foofile = FooFile(buckets=[bucket]) + + io = HDF5IO(self.path, manager=self.manager, mode='w') + # write the object to disk, including initializing an empty int dataset with shape (5,) + io.write(foofile) + + foo.my_data.dataset[:] = [0, 1, 2, 3, 4] + io.close() + """ if self.__dataset is not None: raise ValueError("Cannot overwrite H5DataIO.dataset") self.__dataset = val