Skip to content

Don't unnecessarily copy dask arrays #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion xray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ def copy(self, deep=True):
If `deep=True`, the data array is loaded into memory and copied onto
the new object. Dimensions, attributes and encodings are always copied.
"""
data = self.values.copy() if deep else self._data
if deep and not isinstance(self.data, dask_array_type):
# dask arrays don't have a copy method
# https://github.com/blaze/dask/issues/911
data = self.data.copy()
else:
data = self._data
# note:
# dims is already an immutable tuple
# attributes and encoding will be copied when the new Array is created
Expand Down
5 changes: 5 additions & 0 deletions xray/test/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def test_basics(self):
self.assertEqual(self.data.chunks, v.chunks)
self.assertArrayEqual(self.values, v)

def test_copy(self):
self.assertLazyAndIdentical(self.eager_var, self.lazy_var.copy())
self.assertLazyAndIdentical(self.eager_var,
self.lazy_var.copy(deep=True))

def test_chunk(self):
for chunks, expected in [(None, ((2, 2), (2, 2, 2))),
(3, ((3, 1), (3, 3))),
Expand Down