Skip to content

Commit 17fc21d

Browse files
committed
Make error message more informative.
1 parent 3439542 commit 17fc21d

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

lib/iris/analysis/_grid_angles.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,14 @@ def guess_2D_bounds(x, y, extrapolate=True, in_place=False):
686686
if x.coord_system != y.coord_system:
687687
msg = "Coordinate systems must be the same."
688688
raise ValueError(msg)
689-
if not all(
690-
isinstance(coord.coord_system, GeogCS | RotatedGeogCS | None)
691-
for coord in [x, y]
692-
):
693-
msg = "Coordinate systems are expected geodetic."
694-
raise ValueError(msg)
689+
for coord in (x, y):
690+
if not isinstance(coord.coord_system, GeogCS | RotatedGeogCS | None):
691+
msg = (
692+
f"Coordinate {coord.name()!r} has a coordinate system of type "
693+
f"{type(coord.coord_system)!r} : must be geodetic "
694+
"(GeogCs / RotatedGeogCS), or None."
695+
)
696+
raise ValueError(msg)
695697

696698
if in_place:
697699
new_x = x

lib/iris/tests/unit/analysis/cartography/test_guess_2D_bounds.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ def test_2D_guess_bounds_coord_systems():
155155
mercator_cube.coord("latitude").coord_system = mercator_cs
156156
mercator_cube.coord("longitude").coord_system = mercator_cs
157157

158-
with pytest.raises(ValueError, match="Coordinate systems are expected geodetic."):
158+
msg = (
159+
"Coordinate 'longitude' has a coordinate system of type <class '.*Mercator'> : "
160+
r"must be geodetic \(GeogCs / RotatedGeogCS\), or None."
161+
)
162+
with pytest.raises(ValueError, match=msg):
159163
_2D_guess_bounds(mercator_cube)
160164

161165

0 commit comments

Comments
 (0)