Skip to content

Commit

Permalink
Special case for printing scalar hybrid coords.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Apr 2, 2024
1 parent c100869 commit ca0bc4e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/iris/_representation/cube_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,32 @@ def __init__(self, cube, coord):
self.unit = ""
else:
self.unit = " {!s}".format(coord.units)
coord_cell = None
if not _lazy.is_lazy_data(coord.core_points()):
coord_cell = coord.cell(0)

# Don't print values of lazy coords, as computing them could cost a lot.
safe_to_print = not _lazy.is_lazy_data(coord.core_points())
if not safe_to_print:
# However there is a special case: If it is a *factory* coord, then those
# are generally lazy. If all the dependencies are real, then it is useful
# (and safe) to compute + print the value.
for factory in cube._aux_factories:
# Note : a factory doesn't have a ".metadata" which can be matched
# against a coord. For now, just assume that it has a 'standard_name'
# property (also not actually guaranteed), and require them to match.
if coord.standard_name == factory.standard_name:
all_deps_real = True
for dependency_coord in factory.dependencies.values():
if (
dependency_coord.has_lazy_points()
or dependency_coord.has_lazy_bounds()
):
all_deps_real = False

if all_deps_real:
safe_to_print = True

if safe_to_print:
coord_cell = coord_cell = coord.cell(0)

if coord.dtype.type is np.str_:
self.string_type = True
if coord_cell is not None:
Expand Down

0 comments on commit ca0bc4e

Please sign in to comment.