From 7901bbc2fb2b1d84dba73757a66bddc8c08a8d0d Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Thu, 18 Dec 2025 14:32:30 +0000 Subject: [PATCH] refactored DatalessError --- lib/iris/_lazy_data.py | 2 +- lib/iris/cube.py | 6 ++++-- lib/iris/exceptions.py | 9 ++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/iris/_lazy_data.py b/lib/iris/_lazy_data.py index c74da78d6b..2de7f8c5ac 100644 --- a/lib/iris/_lazy_data.py +++ b/lib/iris/_lazy_data.py @@ -370,7 +370,7 @@ def _co_realise_lazy_arrays(arrays): if real_out is not None: real_out = np.asanyarray(real_out) else: - raise iris.exceptions.DatalessError("realising") + raise iris.exceptions.DatalessError("Data is None; cannot be realised.") if isinstance(real_out, ma.core.MaskedConstant): # Convert any masked constants into NumPy masked arrays. # NOTE: in this case, also apply the original lazy-array dtype, as diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 7d077581e1..a68e9d7599 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -5374,7 +5374,9 @@ def interpolate( """ if self.is_dataless(): - raise iris.exceptions.DatalessError("interpolate") + raise iris.exceptions.DatalessError( + "Dataless cubes cannot be interpolated." + ) coords, points = zip(*sample_points) interp = scheme.interpolator(self, coords) # type: ignore[arg-type] return interp(points, collapse_scalar=collapse_scalar) @@ -5421,7 +5423,7 @@ def regrid(self, grid: Cube, scheme: iris.analysis.RegriddingScheme) -> Cube: """ if self.is_dataless(): - raise iris.exceptions.DatalessError("regrid") + raise iris.exceptions.DatalessError("Dataless cubes cannot be regridded.") regridder = scheme.regridder(self, grid) return regridder(self) diff --git a/lib/iris/exceptions.py b/lib/iris/exceptions.py index 2ac0e35dc4..56e220faf9 100644 --- a/lib/iris/exceptions.py +++ b/lib/iris/exceptions.py @@ -170,14 +170,9 @@ class CannotAddError(ValueError): class DatalessError(ValueError): - """Raised when an method cannot be performed on a dataless :class:`~iris.cube.Cube`.""" + """Raised when a method cannot be performed on a dataless :class:`~iris.cube.Cube`.""" - def __str__(self): - msg = ( - "Dataless cubes are still early in implementation, and dataless {} " - "operations are not currently supported." - ) - return msg.format(super().__str__()) + pass class CFParseError(IrisError):