diff --git a/lib/iris/_merge.py b/lib/iris/_merge.py index c6d67c1b78..ef11235d93 100644 --- a/lib/iris/_merge.py +++ b/lib/iris/_merge.py @@ -1141,16 +1141,18 @@ def _get_cube(self): aux_coords_and_dims = [(deepcopy(coord), dims) for coord, dims in self._aux_coords_and_dims] kwargs = dict(zip(iris.cube.CubeMetadata._fields, signature.defn)) - # Create fully masked data i.e. all missing. + # Create fully masked data, i.e. all missing. + # (The CubeML checksum doesn't respect the mask, so we zero the + # underlying data to ensure repeatable checksums.) if signature.data_manager is None: - # Must zero the data in order to avoid random checksums. - data = numpy.ma.zeros(self._shape, dtype=signature.data_type) - data.fill_value = signature.mdi + data = numpy.ma.MaskedArray(numpy.zeros(self._shape, + signature.data_type), + mask=numpy.ones(self._shape, 'bool'), + fill_value=signature.mdi) else: - # With dtype=object, ma.empty DOES initialise the memory (all None). - data = numpy.ma.empty(self._shape, dtype=object) + data = numpy.ma.MaskedArray(numpy.zeros(self._shape, 'object'), + mask=numpy.ones(self._shape, 'bool')) - data.mask = True cube = iris.cube.Cube(data, dim_coords_and_dims=dim_coords_and_dims, aux_coords_and_dims=aux_coords_and_dims, diff --git a/lib/iris/fileformats/manager.py b/lib/iris/fileformats/manager.py index d9bd1dfb2e..0a906cf9d9 100644 --- a/lib/iris/fileformats/manager.py +++ b/lib/iris/fileformats/manager.py @@ -249,13 +249,16 @@ def load(self, proxy_array): # Create fully masked data (all missing) try: - data = numpy.ma.zeros(array_shape, dtype=self.data_type.newbyteorder('='), fill_value=self.mdi) - data.mask = True + raw_data = numpy.empty(array_shape, + dtype=self.data_type.newbyteorder('=')) + mask = numpy.ones(array_shape, dtype=numpy.bool) + data = numpy.ma.MaskedArray(raw_data, mask=mask, + fill_value=self.mdi) except ValueError: raise DataManager.ArrayTooBigForAddressSpace( - 'Cannot create an array of shape %r as it will not fit in memory. Try reducing the shape ' - 'of the proxy array by using indexing.' % (array_shape, ) - ) + 'Cannot create an array of shape %r as it will not fit in' + ' memory. Consider using indexing to select a subset of' + ' the Cube.'.format(array_shape)) for index, proxy in numpy.ndenumerate(proxy_array): if proxy not in [None, 0]: # 0 can come from slicing masked proxy; numpy.array(masked_constant).