diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 761833ba15..bd24b1c64c 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -245,7 +245,8 @@ This document explains the changes made to Iris for this release #. `@trexfeathers`_ and `@pp-mo`_ improved generation of stock NetCDF files. (:pull:`4827`, :pull:`4836`) -#. `@rcomer`_ removed some now redundant testing methods. (:pull:`4838`) +#. `@rcomer`_ removed some now redundant testing functions. (:pull:`4838`, + :pull:`4878`) #. `@bjlittle`_ and `@jamesp`_ (reviewer) and `@lbdreyer`_ (reviewer) extended the GitHub Continuous-Integration to cover testing on ``py38``, ``py39``, diff --git a/lib/iris/tests/__init__.py b/lib/iris/tests/__init__.py index 75b7882221..5b99885874 100644 --- a/lib/iris/tests/__init__.py +++ b/lib/iris/tests/__init__.py @@ -588,31 +588,18 @@ def assertNoWarningsRegexp(self, expected_regexp=""): self.assertFalse(matches, msg) def _assertMaskedArray(self, assertion, a, b, strict, **kwargs): - # Define helper function to extract unmasked values as a 1d - # array. - def unmasked_data_as_1d_array(array): - array = ma.asarray(array) - if array.ndim == 0: - if array.mask: - data = np.array([]) - else: - data = np.array([array.data]) - else: - data = array.data[~ma.getmaskarray(array)] - return data - - # Compare masks. This will also check that the array shapes - # match, which is not tested when comparing unmasked values if - # strict is False. + # Compare masks. a_mask, b_mask = ma.getmaskarray(a), ma.getmaskarray(b) np.testing.assert_array_equal(a_mask, b_mask) if strict: + # Compare all data values. assertion(a.data, b.data, **kwargs) else: + # Compare only unmasked data values. assertion( - unmasked_data_as_1d_array(a), - unmasked_data_as_1d_array(b), + ma.compressed(a), + ma.compressed(b), **kwargs, )