Skip to content

DSD definition checked by demand but not by region #268

@idelder

Description

@idelder

From coderabbit:

Backfill demand defaults per (region, demand), not per demand name.

The new key shape and the final validation are region-scoped, but this block still collapses demand_specific_distribution down to just dem. If one region supplies a custom distribution and another relies on defaults, nothing gets backfilled for the second region and the later (r, dem) validation raises. Compute the unset set from (r, dem) pairs before expanding across seasons and times-of-day.

Suggested fix

-    demands_specified = set(
-        map(
-            demand_specific_distributon_dem,
-            (i for i in demand_specific_distribution.sparse_iterkeys()),
-        )
-    )
-    unset_demand_distributions = used_dems.difference(
-        demands_specified
-    )  # the demands not mentioned in DSD *at all*
+    used_r_dems = {(r, dem) for r, _p, dem in model.demand.sparse_iterkeys()}
+    specified_r_dems = {
+        (r, dem) for r, _s, _d, dem in demand_specific_distribution.sparse_iterkeys()
+    }
+    unset_r_dems = used_r_dems.difference(specified_r_dems)

-    if unset_demand_distributions:
-        unset_distributions = set(
-            cross_product(
-                model.regions,
-                model.time_season,
-                model.time_of_day,
-                unset_demand_distributions,
-            )
-        )
-        for r, s, d, dem in unset_distributions:
-            demand_specific_distribution[r, s, d, dem] = value(
-                model.segment_fraction[s, d]
-            )  # DSD._constructed = True
+    if unset_r_dems:
+        for r, dem in unset_r_dems:
+            for s, d in cross_product(model.time_season, model.time_of_day):
+                demand_specific_distribution[r, s, d, dem] = value(
+                    model.segment_fraction[s, d]
+                )

-    used_r_dems = {(r, dem) for r, p, dem in model.demand.sparse_iterkeys()}
     for r, dem in used_r_dems:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions