Skip to content

Commit

Permalink
Don't recast nomask int arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
DPeterK committed Mar 14, 2017
1 parent 7b158c2 commit f6f14fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/iris/_lazy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def array_masked_to_nans(array):
Args:
* masked_array:
* array:
A NumPy `ndarray` or masked array.
Returns:
Expand All @@ -100,10 +100,11 @@ def array_masked_to_nans(array):
if not ma.isMaskedArray(array):
result = array
else:
if array.dtype.kind == 'i':
array = array.astype(np.dtype('f8'))
mask = array.mask
array[mask] = np.nan
if ma.is_masked(array):
if array.dtype.kind == 'i':
array = array.astype(np.dtype('f8'))
mask = array.mask
array[mask] = np.nan
result = array.data
return result

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/tests/unit/lazy_data/test_array_masked_to_nans.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ def test_unmasked__integers(self):
self.assertIs(result, unmasked_array)

def test_no_mask__integers(self):
masked_array = ma.masked_array([1, 2], mask=ma.nomask)
datatype = np.dtype('i4')
masked_array = ma.masked_array([1, 2], dtype=datatype, mask=ma.nomask)

result = array_masked_to_nans(masked_array)

self._common_checks(result)
self.assertEqual(result.dtype, np.dtype('f8'))
self.assertEqual(result.dtype, datatype)


if __name__ == '__main__':
Expand Down

0 comments on commit f6f14fd

Please sign in to comment.