Skip to content

Commit

Permalink
added cubelist errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Dec 18, 2024
1 parent 2123b8f commit 703bbb6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,11 @@ def concatenate(
A :class:`iris.cube.CubeList` of concatenated :class:`iris.cube.Cube` instances.
"""
cube_signatures = [_CubeSignature(cube) for cube in cubes]
cube_signatures = []
for cube in cubes:
if cube.is_dataless():
raise iris.exceptions.DatalessError("concatenate")
cube_signatures.append(_CubeSignature(cube))

proto_cubes: list[_ProtoCube] = []
# Initialise the nominated axis (dimension) of concatenation
Expand Down
6 changes: 5 additions & 1 deletion lib/iris/_lazy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dask.array as da
import dask.config
import dask.utils
import iris.exceptions
import numpy as np
import numpy.ma as ma

Expand Down Expand Up @@ -317,7 +318,10 @@ def _co_realise_lazy_arrays(arrays):
# Note : in some cases dask (and numpy) will return a scalar
# numpy.int/numpy.float object rather than an ndarray.
# Recorded in https://github.com/dask/dask/issues/2111.
real_out = np.asanyarray(real_out)
if real_out is not None:
real_out = np.asanyarray(real_out)
else:
raise iris.exceptions.DatalessError("realising")
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
Expand Down
4 changes: 4 additions & 0 deletions lib/iris/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@ def __init__(self, cube):
source-cube.
"""
if cube.is_dataless():
raise iris.exceptions.DatalessError("merge")
# Default hint ordering for candidate dimension coordinates.
self._hints = [
"time",
Expand Down Expand Up @@ -1289,6 +1291,8 @@ def register(self, cube, error_on_mismatch=False):
this :class:`ProtoCube`.
"""
if cube.is_dataless():
raise iris.exceptions.DatalessError("merge")
cube_signature = self._cube_signature
other = self._build_signature(cube)
match = cube_signature.match(other, error_on_mismatch)
Expand Down
3 changes: 0 additions & 3 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ def _assert_is_cube(obj):
if not hasattr(obj, "add_aux_coord"):
msg = r"Object {obj} cannot be put in a cubelist, as it is not a Cube."
raise ValueError(msg)
elif obj.is_dataless():
raise iris.exceptions.DatalessError("CubeList")

def _repr_html_(self):
from iris.experimental.representation import CubeListRepresentation
Expand Down Expand Up @@ -412,7 +410,6 @@ def merge_cube(self):
"""
if not self:
raise ValueError("can't merge an empty CubeList")

# Register each of our cubes with a single ProtoCube.
proto_cube = iris._merge.ProtoCube(self[0])
for c in self[1:]:
Expand Down

0 comments on commit 703bbb6

Please sign in to comment.