diff --git a/lib/iris/_concatenate.py b/lib/iris/_concatenate.py index ffa290d1a1..5debc452ee 100644 --- a/lib/iris/_concatenate.py +++ b/lib/iris/_concatenate.py @@ -437,7 +437,7 @@ def meta_key_func(dm): av_and_dims = _CoordAndDims(av, tuple(dims)) self.ancillary_variables_and_dims.append(av_and_dims) - def _coordinate_differences(self, other, attr): + def _coordinate_differences(self, other, attr, reason="metadata"): """ Determine the names of the coordinates that differ between `self` and `other` for a coordinate attribute on a _CubeSignature. @@ -451,12 +451,16 @@ def _coordinate_differences(self, other, attr): The _CubeSignature attribute within which differences exist between `self` and `other`. + * reason (string): + The reason to give for mismatch (function is normally, but not + always, testing metadata) + Returns: - Tuple of a descriptive error message and the names of coordinates + Tuple of a descriptive error message and the names of attributes that differ between `self` and `other`. """ - # Set up {name: coord_metadata} dictionaries. + # Set up {name: attribute} dictionaries. self_dict = {x.name(): x for x in getattr(self, attr)} other_dict = {x.name(): x for x in getattr(other, attr)} if len(self_dict) == 0: @@ -466,7 +470,7 @@ def _coordinate_differences(self, other, attr): self_names = sorted(self_dict.keys()) other_names = sorted(other_dict.keys()) - # Compare coord metadata. + # Compare coord attributes. if len(self_names) != len(other_names) or self_names != other_names: result = ("", ", ".join(self_names), ", ".join(other_names)) else: @@ -476,7 +480,7 @@ def _coordinate_differences(self, other, attr): if self_value != other_value: diff_names.append(self_key) result = ( - " metadata", + " " + reason, ", ".join(diff_names), ", ".join(diff_names), ) @@ -542,7 +546,9 @@ def match(self, other, error_on_mismatch): ) # Check scalar coordinates. if self.scalar_coords != other.scalar_coords: - differences = self._coordinate_differences(other, "scalar_coords") + differences = self._coordinate_differences( + other, "scalar_coords", reason="values or metadata" + ) msgs.append( msg_template.format("Scalar coordinates", *differences) ) diff --git a/lib/iris/tests/unit/concatenate/test_concatenate.py b/lib/iris/tests/unit/concatenate/test_concatenate.py index f71f9c4596..2af568f077 100644 --- a/lib/iris/tests/unit/concatenate/test_concatenate.py +++ b/lib/iris/tests/unit/concatenate/test_concatenate.py @@ -154,7 +154,7 @@ def test_scalar_coords_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord("height").long_name = "alice" - exc_regexp = "Scalar coordinates metadata differ: .* != .*" + exc_regexp = "Scalar coordinates values or metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)