Skip to content

Commit 1eeaf66

Browse files
author
scott.robinson
committed
Two cases
1 parent 457d5da commit 1eeaf66

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ This document explains the changes made to Iris for this release
5656
cubes with masked :class:`iris.coords.CellMeasure`.
5757
(:issue:`5147`, :pull:`5181`)
5858

59+
#. `@scottrobinson02`_ fixed :class:`iris.util.new_axis` creating an anonymous new
60+
dimension, when the scalar coord provided is already a dim coord.
61+
(:issue:`4415`, :pull:`5194`)
62+
63+
5964

6065
💣 Incompatible Changes
6166
=======================

lib/iris/tests/unit/util/test_new_axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_existing_dim_coord(self, stock_cube):
122122
stock_cube.add_aux_coord(coord)
123123

124124
new_cube = iris.util.new_axis(stock_cube, coord)
125-
with pytest.raises(iris.exceptions.CoordinateNotFoundError):
125+
with pytest.raises(ValueError, match="is already a dimension coordinate."):
126126
iris.util.new_axis(new_cube, coord)
127127

128128
def test_promote_non_scalar(self, stock_cube):

lib/iris/util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,15 @@ def _handle_dimensional_metadata(
11711171
cube_add_method(new_dm_item, new_dims)
11721172

11731173
if scalar_coord is not None:
1174-
scalar_coord = src_cube.coord(scalar_coord, dim_coords=False)
1174+
scalar_coord = src_cube.coord(scalar_coord)
1175+
try:
1176+
src_cube.coord(scalar_coord, dim_coords=False)
1177+
except iris.exceptions.CoordinateNotFoundError:
1178+
emsg = scalar_coord.name() + " is already a dimension coordinate."
1179+
raise ValueError(emsg)
1180+
11751181
if not scalar_coord.shape == (1,):
1176-
emsg = scalar_coord.name() + "is not a scalar coordinate."
1182+
emsg = scalar_coord.name() + " is not a scalar coordinate."
11771183
raise ValueError(emsg)
11781184

11791185
expand_extras = [

0 commit comments

Comments
 (0)