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
4 changes: 0 additions & 4 deletions lib/iris/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,10 +1239,6 @@ def merge(self, unique=True):
# normal array.
dtype = self._cube_signature.data_type
merged_data = as_concrete_data(merged_data)
# Unmask the array if it has no masked points.
if (ma.isMaskedArray(merged_data) and
not ma.is_masked(merged_data)):
merged_data = merged_data.data
merged_cube = self._get_cube(merged_data)
merged_cubes.append(merged_cube)

Expand Down
5 changes: 0 additions & 5 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2094,11 +2094,6 @@ def new_cell_measure_dims(cm_):
# We don't want a view of the data, so take a copy of it.
data = deepcopy(data)

# We can turn a masked array into a normal array if it's full.
if ma.isMaskedArray(data):
if ma.count_masked(data) == 0:
data = data.filled()

# XXX: Slicing a single item from a masked array that is masked,
# results in numpy (v1.11.1) *always* returning a MaskedConstant
# with a dtype of float64, regardless of the original masked
Expand Down
18 changes: 18 additions & 0 deletions lib/iris/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ def test__masked_ndarray(self):
self.assertEqual(result.dtype, self.dtype)
self._check_fill_value(result, fill0=fill)

def test_maksed_array_preserved(self):
for (lazy0, lazy1), (fill,) in self.mixed_combos:
cubes = iris.cube.CubeList()
mask = False
cubes.append(self._make_cube(0, mask=mask, lazy=lazy0,
dtype=self.dtype,
fill_value=fill))
cubes.append(self._make_cube(1, lazy=lazy1, dtype=self.dtype))
result = cubes.merge_cube()
mask = False
expected_fill_value = self._expected_fill_value(fill)
expected = self._make_data([0, 1], mask=mask, dtype=self.dtype,
fill_value=expected_fill_value)
self.assertEqual(type(result.data), ma.MaskedArray)
self.assertMaskedArrayEqual(result.data, expected)
self.assertEqual(result.dtype, self.dtype)
self._check_fill_value(result, fill0=fill)

def test_fill_value_invariant_to_order__same_non_None(self):
fill_value = 1234
cubes = [self._make_cube(i, mask=True,
Expand Down
7 changes: 7 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def test_masked(self):
self.assertEqual(type(cube.data), ma.MaskedArray)
self.assertMaskedArrayEqual(cube.data, data)

def test_masked_no_mask(self):
# ma.MaskedArray should be allowed through even if it has no mask
data = ma.masked_array(np.arange(12).reshape(3, 4), False)
cube = Cube(data)
self.assertEqual(type(cube.data), ma.MaskedArray)
self.assertMaskedArrayEqual(cube.data, data)

def test_matrix(self):
# Subclasses of np.ndarray should be coerced back to np.ndarray.
# (Except for np.ma.MaskedArray.)
Expand Down