diff --git a/lib/iris/util.py b/lib/iris/util.py index e862e8055d..5f6ac166fe 100644 --- a/lib/iris/util.py +++ b/lib/iris/util.py @@ -25,7 +25,7 @@ import numpy.ma as ma from iris._deprecation import warn_deprecated -from iris._lazy_data import is_lazy_data +from iris._lazy_data import as_concrete_data, is_lazy_data import iris.exceptions @@ -364,7 +364,6 @@ def array_equal(array1, array2, withnans=False): def normalise_array(array): if not is_lazy_data(array): array = np.asarray(array) - # (All other np operations in array_equal() preserve array laziness). return array array1, array2 = normalise_array(array1), normalise_array(array2) @@ -375,12 +374,22 @@ def normalise_array(array): if withnans and (array1.dtype.kind == "f" or array2.dtype.kind == "f"): nans1, nans2 = np.isnan(array1), np.isnan(array2) - if not np.all(nans1 == nans2): - eq = False # simply fail - else: - eqs[nans1] = True # fix NaNs; check all the others + eq = as_concrete_data(np.all(nans1 == nans2)) + + if eq: + eqs = as_concrete_data(eqs) + if not is_lazy_data(nans1): + idxs = nans1 + elif not is_lazy_data(nans2): + idxs = nans2 + else: + idxs = as_concrete_data(nans1) + + if np.any(idxs): + eqs[idxs] = True if eq: + eqs = as_concrete_data(eqs) eq = np.all(eqs) # check equal at all points return eq