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
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ This document explains the changes made to Iris for this release
#. `@stephenworsley`_ fixed incompatibilities with numpy v2.3 affecting arrays of dates and
array printing. (:pull:`6518`)

#. `@stephenworsley`_ fixed a bug which caused :meth:`~iris.cube.CubeList.concatenate_cube`
to fail when concatenating over multiple axes. (:pull:`6533`)


💣 Incompatible Changes
=======================
Expand Down
22 changes: 10 additions & 12 deletions lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,15 @@ def add_coords(cube_signature: _CubeSignature, coord_type: str) -> None:
add_coords(cube_signature, "ancillary_variables_and_dims")

hashes = _compute_hashes(arrays)
msg = None

# Register each cube with its appropriate proto-cube.
for cube_signature in cube_signatures:
registered = False

# Register cube with an existing proto-cube.
for proto_cube in proto_cubes:
registered = proto_cube.register(
registered, msg = proto_cube.register(
cube_signature,
hashes,
axis,
Expand Down Expand Up @@ -648,6 +649,11 @@ def _none_sort(proto_cube):
count = len(concatenated_cubes)
if count != 1 and count != len(cubes):
concatenated_cubes = concatenate(concatenated_cubes)
elif msg is not None:
if error_on_mismatch:
raise iris.exceptions.ConcatenateError([msg])
else:
warnings.warn(msg, category=iris.warnings.IrisUserWarning)

return concatenated_cubes

Expand Down Expand Up @@ -1115,7 +1121,7 @@ def register(
check_cell_measures: bool = False,
check_ancils: bool = False,
check_derived_coords: bool = False,
) -> bool:
) -> tuple[bool, str | None]:
"""Determine if the given source-cube is suitable for concatenation.

Determine if the given source-cube is suitable for concatenation
Expand Down Expand Up @@ -1158,7 +1164,7 @@ def register(

Returns
-------
bool
tuple[bool, str]

"""
# Verify and assert the nominated axis.
Expand Down Expand Up @@ -1275,15 +1281,7 @@ def check_coord_match(coord_type: str) -> tuple[bool, str]:
if existing_order == _CONSTANT and this_order != _CONSTANT:
self._coord_signature.dim_order[dim_ind] = this_order

if mismatch_error_msg and not match:
if error_on_mismatch:
raise iris.exceptions.ConcatenateError([mismatch_error_msg])
else:
warnings.warn(
mismatch_error_msg, category=iris.warnings.IrisUserWarning
)

return match
return match, mismatch_error_msg

def _add_skeleton(self, coord_signature, data):
"""Create and add the source-cube skeleton to the :class:`_ProtoCube`.
Expand Down
15 changes: 15 additions & 0 deletions lib/iris/tests/unit/cube/test_CubeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ def test_empty(self):
with pytest.raises(ValueError, match=exc_regexp):
CubeList([]).concatenate_cube()

def test_multidim(self):
lat = DimCoord(np.arange(20), standard_name="latitude")
lon = DimCoord(np.arange(20), standard_name="longitude")

cube = Cube(np.zeros([20, 20]))
cube.add_dim_coord(lat, 0)
cube.add_dim_coord(lon, 1)

cube_quarters = CubeList(
[cube[:10, :10], cube[:10, 10:], cube[10:, :10], cube[10:, 10:]]
)

result = cube_quarters.concatenate_cube()
assert cube == result


class Test_extend:
@pytest.fixture(autouse=True)
Expand Down
Loading