Skip to content

Commit

Permalink
Add doc to H5DataIO.dataset setter
Browse files Browse the repository at this point in the history
  • Loading branch information
rly authored Jul 26, 2024
1 parent dfb1df7 commit d24d3d9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 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,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
Expand Down

0 comments on commit d24d3d9

Please sign in to comment.