Skip to content

Commit ca0bc4e

Browse files
committed
Special case for printing scalar hybrid coords.
1 parent c100869 commit ca0bc4e

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

lib/iris/_representation/cube_summary.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,32 @@ def __init__(self, cube, coord):
151151
self.unit = ""
152152
else:
153153
self.unit = " {!s}".format(coord.units)
154-
coord_cell = None
155-
if not _lazy.is_lazy_data(coord.core_points()):
156-
coord_cell = coord.cell(0)
154+
155+
# Don't print values of lazy coords, as computing them could cost a lot.
156+
safe_to_print = not _lazy.is_lazy_data(coord.core_points())
157+
if not safe_to_print:
158+
# However there is a special case: If it is a *factory* coord, then those
159+
# are generally lazy. If all the dependencies are real, then it is useful
160+
# (and safe) to compute + print the value.
161+
for factory in cube._aux_factories:
162+
# Note : a factory doesn't have a ".metadata" which can be matched
163+
# against a coord. For now, just assume that it has a 'standard_name'
164+
# property (also not actually guaranteed), and require them to match.
165+
if coord.standard_name == factory.standard_name:
166+
all_deps_real = True
167+
for dependency_coord in factory.dependencies.values():
168+
if (
169+
dependency_coord.has_lazy_points()
170+
or dependency_coord.has_lazy_bounds()
171+
):
172+
all_deps_real = False
173+
174+
if all_deps_real:
175+
safe_to_print = True
176+
177+
if safe_to_print:
178+
coord_cell = coord_cell = coord.cell(0)
179+
157180
if coord.dtype.type is np.str_:
158181
self.string_type = True
159182
if coord_cell is not None:

0 commit comments

Comments
 (0)