Skip to content

Commit

Permalink
Add doc to H5DataIO.dataset setter (#1154)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Oliver Ruebel <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent dfb1df7 commit 77be0cc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/hdmf/backends/hdf5/h5_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,31 @@ def __init__(self, **kwargs):

@property
def dataset(self):
"""Get the cached h5py.Dataset."""
return self.__dataset

@dataset.setter
def dataset(self, val):
"""Cache the h5py.Dataset written with the stored IO settings.
This attribute 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 reopen 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
Expand Down

0 comments on commit 77be0cc

Please sign in to comment.