Skip to content

Commit

Permalink
feat(memh5): add '.copy' method to MemDiskGroup
Browse files Browse the repository at this point in the history
Closes #190
  • Loading branch information
ljgray committed Mar 14, 2023
1 parent 1fb0b6d commit f4829d0
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions caput/memh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ def require_group(self, name):


class MemGroup(_BaseGroup):
"""
In memory implementation of the :class:`h5py.Group`.
"""In memory implementation of the :class:`h5py.Group`.
This class doubles as the memory implementation of :class:`h5py.File`,
object, since the distinction between a file and a group for in-memory data
Expand Down Expand Up @@ -2007,6 +2006,30 @@ def flush(self):
if self.ondisk:
self._data.flush()

def copy(self, shared: list = []) -> MemDiskGroup:
"""Return a deep copy of this class or subclass.
Parameters
----------
shared
dataset names to share (i.e. don't deep copy)
Returns
-------
copy
Copy of this group. Datasets in shared are shallow copies,
everything else is a deep copy
"""
cls = self.__class__.__new__(self.__class__)
MemDiskGroup.__init__(cls, distributed=self.distributed, comm=self.comm)
deep_group_copy(self._data, cls._data, deep_copy_dsets=True, shared=shared)

return cls

def __deepcopy__(self, memo, /) -> MemDiskGroup:
"""Called when copy.deepcopy is called on this class"""
return self.copy()

def save(
self,
filename,
Expand Down

0 comments on commit f4829d0

Please sign in to comment.