Skip to content

Commit 78447ed

Browse files
committed
Ensure a definite ordering for formula-root processing.
1 parent 16959a5 commit 78447ed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/iris/fileformats/netcdf.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,25 @@ def _assert_case_specific_facts(engine, cf, cf_group):
462462

463463
# Assert facts for CF formula terms associated with the cf_group
464464
# of the CF data variable.
465-
formula_root = set()
465+
466+
# Collect varnames of formula-root variables as we go.
467+
# NOTE: use dictionary keys as an 'OrderedDict'
468+
# - see: https://stackoverflow.com/a/53657523/2615050
469+
# This is to ensure that we can handle the resulting facts in a definite
470+
# order, as using a 'set' led to indeterminate results.
471+
formula_root = {}
466472
for cf_var in cf.cf_group.formula_terms.values():
467473
for cf_root, cf_term in cf_var.cf_terms_by_root.items():
468474
# Only assert this fact if the formula root variable is
469475
# defined in the CF group of the CF data variable.
470476
if cf_root in cf_group:
471-
formula_root.add(cf_root)
477+
formula_root[cf_root] = True
472478
engine.add_case_specific_fact(
473479
"formula_term",
474480
(cf_var.cf_name, cf_root, cf_term),
475481
)
476482

477-
for cf_root in formula_root:
483+
for cf_root in formula_root.keys():
478484
engine.add_case_specific_fact("formula_root", (cf_root,))
479485

480486

0 commit comments

Comments
 (0)