Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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),
)
Expand Down Expand Up @@ -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)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/concatenate/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down