Skip to content
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: 7 additions & 0 deletions lib/iris/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def _deepcopy(self, memo, data=None):
data = copy.deepcopy(self._lazy_array, memo)
else:
data = self._real_array.copy()
else:
# Check that the replacement data is valid relative to
# the currently managed data.
dm_check = DataManager(self.core_data())
dm_check.data = data
# If the replacement data is valid, then use it but
# without copying it.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am putting this back as this ensures you are doing a deepcopy with a data of the correct shape.
Without this you can do:

>>> dm = DataManager(np.array([0,1,2]))
>>> dm._deepcopy(dict(), data=np.array(0))
DataManager(array(0))

Which shouldn't happen

result = DataManager(data)
except ValueError as error:
emsg = 'Cannot copy {!r} - {}'
Expand Down
2 changes: 2 additions & 0 deletions lib/iris/_lazy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def as_lazy_data(data, chunks=_MAX_CHUNK_SIZE):
The input array converted to a dask array.

"""
if isinstance(data, ma.core.MaskedConstant):
data = ma.masked_array(data.data, mask=data.mask)
if not is_lazy_data(data):
asarray = not ma.isMaskedArray(data)
data = da.from_array(data, chunks=chunks, asarray=asarray)
Expand Down
Loading