Check for unformatted geography fields in subsampling parameters
Unformatted fields with geographic information are the result of a
misconfiguration or missing data and should produce an error. Without the
exception introduced in this commit, subsampling rules are still produced with
meaningless filter commands (e.g., "region!={region}") and cause subsampling to
produce incorrect results silently.
@@ -191,8 +191,12 @@ def _get_specific_subsampling_setting(setting, optional=False):
if ("geo_hierarchy" in config
and geographic_scale in config["geo_hierarchy"]
and geographic_name in config["geo_hierarchy"][geographic_scale]):
- return value.format(**config["geo_hierarchy"][geographic_scale][geographic_name])
- else:
+ value = value.format(**config["geo_hierarchy"][geographic_scale][geographic_name])
+
+ # Check format strings that haven't been resolved.
+ if re.search(r'\{.+\}', value):
+ raise Exception(f"The parameters for the subsampling scheme '{wildcards.subsample}' require expansion from the geo hierarchy but it is not defined: '{value}'. Check that the build params define the correct geographic name and scale, and that these are present in the `geo_hierarchy`")
+
return value
return _get_setting
