Skip to content

Commit 8c3113b

Browse files
committed
Potential fix for h5py deepcopy issues
1 parent 66ab0ae commit 8c3113b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

xarray/core/indexing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ def __setitem__(self, key, value):
664664
self._ensure_copied()
665665
self.array[key] = value
666666

667+
def __deepcopy__(self, memo):
668+
# CopyOnWriteArray is used to wrap backend array objects, which might
669+
# point to files on disk. Implementing __deepcopy__ this way ensures
670+
# that deep copying is always valid, and results in an in-memory copy.
671+
return type(self)(np.array(self.array))
672+
667673

668674
class MemoryCachedArray(ExplicitlyIndexedNDArrayMixin):
669675
__slots__ = ("array",)

0 commit comments

Comments
 (0)