diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 6675636685..25f5f01722 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -74,6 +74,10 @@ This document explains the changes made to Iris for this release one cell's bounds align with the requested maximum and negative minimum, fixing :issue:`4221`. (:pull:`4278`) +#. `@tinyendian`_ fixed the error message produced by :meth:`~iris.cube.CubeList.concatenate_cube` + when a cube list contains cubes with different names, which will no longer report + "Cube names differ: var1 != var1" if var1 appears multiple times in the list + (:issue:`4342`, :pull:`4345`) 💣 Incompatible Changes ======================= @@ -142,6 +146,7 @@ This document explains the changes made to Iris for this release Whatsnew author names (@github name) in alphabetical order. Note that, core dev names are automatically included by the common_links.inc: +.. _@tinyendian: https://github.com/tinyendian diff --git a/lib/iris/cube.py b/lib/iris/cube.py index f39f714070..c9ab990b15 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -555,7 +555,9 @@ def concatenate_cube( else: msgs = [] msgs.append( - "Cube names differ: {} != {}".format(names[0], names[1]) + "Cube names differ: {} != {}".format( + unique_names[0], unique_names[1] + ) ) raise iris.exceptions.ConcatenateError(msgs) diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index bccac639bc..eb4c6c4f3f 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -49,6 +49,21 @@ def test_fail(self): with self.assertRaises(iris.exceptions.ConcatenateError): CubeList([self.cube1, cube2]).concatenate_cube() + def test_names_differ_fail(self): + self.cube2 = Cube([1, 2, 3], "air_temperature", units="K") + self.cube2.add_dim_coord( + DimCoord([3, 4, 5], "time", units=self.units), 0 + ) + self.cube3 = Cube([1, 2, 3], "air_pressure", units="Pa") + self.cube3.add_dim_coord( + DimCoord([3, 4, 5], "time", units=self.units), 0 + ) + exc_regexp = "Cube names differ: air_temperature != air_pressure" + with self.assertRaisesRegex( + iris.exceptions.ConcatenateError, exc_regexp + ): + CubeList([self.cube1, self.cube2, self.cube3]).concatenate_cube() + def test_empty(self): exc_regexp = "can't concatenate an empty CubeList" with self.assertRaisesRegex(ValueError, exc_regexp):