Skip to content

Commit 4be7088

Browse files
committed
Merge pull request #713 from shoyer/dask-no-copy
Don't unnecessarily copy dask arrays
2 parents 8d59f74 + abb2178 commit 4be7088

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

xray/core/variable.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,12 @@ def copy(self, deep=True):
410410
If `deep=True`, the data array is loaded into memory and copied onto
411411
the new object. Dimensions, attributes and encodings are always copied.
412412
"""
413-
data = self.values.copy() if deep else self._data
413+
if deep and not isinstance(self.data, dask_array_type):
414+
# dask arrays don't have a copy method
415+
# https://github.com/blaze/dask/issues/911
416+
data = self.data.copy()
417+
else:
418+
data = self._data
414419
# note:
415420
# dims is already an immutable tuple
416421
# attributes and encoding will be copied when the new Array is created

xray/test/test_dask.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def test_basics(self):
6767
self.assertEqual(self.data.chunks, v.chunks)
6868
self.assertArrayEqual(self.values, v)
6969

70+
def test_copy(self):
71+
self.assertLazyAndIdentical(self.eager_var, self.lazy_var.copy())
72+
self.assertLazyAndIdentical(self.eager_var,
73+
self.lazy_var.copy(deep=True))
74+
7075
def test_chunk(self):
7176
for chunks, expected in [(None, ((2, 2), (2, 2, 2))),
7277
(3, ((3, 1), (3, 3))),

0 commit comments

Comments
 (0)