From 1e515886071bed78c8aafe8f1fcbd3b5dc1c98a3 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 24 Oct 2024 10:13:48 +0200 Subject: [PATCH 1/2] Improve handling of masks --- lib/iris/_concatenate.py | 2 +- lib/iris/tests/unit/concatenate/test_hashing.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/iris/_concatenate.py b/lib/iris/_concatenate.py index 841cecfd53..ac9e699790 100644 --- a/lib/iris/_concatenate.py +++ b/lib/iris/_concatenate.py @@ -310,7 +310,7 @@ def _hash_ndarray(a: np.ndarray) -> np.ndarray: # Hash the bytes representing the array data. hash.update(b"data=") - if isinstance(a, np.ma.MaskedArray): + if np.ma.is_masked(a): # Hash only the unmasked data hash.update(a.compressed().tobytes()) # Hash the mask diff --git a/lib/iris/tests/unit/concatenate/test_hashing.py b/lib/iris/tests/unit/concatenate/test_hashing.py index 7a56be1db8..24062a2af3 100644 --- a/lib/iris/tests/unit/concatenate/test_hashing.py +++ b/lib/iris/tests/unit/concatenate/test_hashing.py @@ -21,6 +21,8 @@ (np.array([np.nan, 1.0]), np.array([np.nan, 1.0]), True), (np.ma.array([1, 2], mask=[0, 1]), np.ma.array([1, 2], mask=[0, 1]), True), (np.ma.array([1, 2], mask=[0, 1]), np.ma.array([1, 2], mask=[0, 0]), False), + (np.ma.array([1, 2], mask=[1, 1]), np.ma.array([1, 2], mask=[1, 1]), True), + (np.ma.array([1, 2], mask=[0, 0]), np.ma.array([1, 2], mask=[0, 0]), True), (da.arange(6).reshape((2, 3)), da.arange(6, chunks=1).reshape((2, 3)), True), (da.arange(20, chunks=1), da.arange(20, chunks=2), True), ( @@ -33,6 +35,21 @@ da.ma.masked_array([1, 3], mask=[0, 1]), True, ), + ( + np.arange(2), + da.ma.masked_array(np.arange(2), mask=[0, 0]), + True, + ), + ( + np.arange(2), + da.ma.masked_array(np.arange(2), mask=[0, 1]), + False, + ), + ( + da.ma.masked_array(np.arange(10), mask=np.zeros(10)), + da.ma.masked_array(np.arange(10), mask=np.ma.nomask), + True, + ), ( np.ma.array([1, 2], mask=[0, 1]), np.ma.array([1, 3], mask=[0, 1], fill_value=10), From b79bddee44582bbb370079ff6d5421ac01942c59 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Thu, 24 Oct 2024 10:29:03 +0200 Subject: [PATCH 2/2] Add whatsnew --- docs/src/whatsnew/latest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 58e3f5f956..cafd0b0938 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -81,7 +81,7 @@ This document explains the changes made to Iris for this release may happen when there are very many or large auxiliary coordinates, derived coordinates, cell measures, or ancillary variables to be checked that span the concatenation axis. This issue can be avoided by disabling the - problematic check. (:pull:`5926`) + problematic check. (:pull:`5926` and :pull:`6187`) 🔥 Deprecations ===============