From 8280eacbce0fc26cdb59eb4aae573c26767075a1 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Tue, 26 Jul 2022 13:12:48 +0100 Subject: [PATCH 1/2] replace unmasked_data_as_1d_array --- lib/iris/tests/__init__.py | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) 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, ) From c8547b566bbaddc40119240f9de1d2a6cc5cc5f5 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 27 Jul 2022 12:07:02 +0100 Subject: [PATCH 2/2] whatsnew --- docs/src/whatsnew/latest.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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``,