diff --git a/changelog.d/scenario-apply-canonical-paths.fixed.md b/changelog.d/scenario-apply-canonical-paths.fixed.md new file mode 100644 index 0000000000..5abf770be7 --- /dev/null +++ b/changelog.d/scenario-apply-canonical-paths.fixed.md @@ -0,0 +1 @@ +`Scenario.apply` on a built simulation now changes the parameter a deprecated `labor_supply_responses` path copies, as constructing the simulation with the scenario does; it used to edit only the alias copy, which formulas do not read, unless the scenario had been summed. diff --git a/policyengine_uk/tests/test_process_time_reforms.py b/policyengine_uk/tests/test_process_time_reforms.py index ec16289e45..21ae54cf3e 100644 --- a/policyengine_uk/tests/test_process_time_reforms.py +++ b/policyengine_uk/tests/test_process_time_reforms.py @@ -625,3 +625,13 @@ def test_baselines_stay_current_law(change, baseline): assert weekly(after, NEW_STATE_PENSION, 2028) == weekly( baseline, NEW_STATE_PENSION, 2028 ) + + +@pytest.mark.parametrize("summed", [False, True]) +def test_scenario_apply_changes_the_parameter_an_alias_path_copies(summed): + scenario = Scenario(parameter_changes={LSR_LEGACY: 0.3}) + if summed: + scenario = Scenario() + scenario + simulation = Simulation(situation=PENSIONER) + scenario.apply(simulation) + assert value(simulation, LSR, "2028-01-01") == pytest.approx(0.3) diff --git a/policyengine_uk/utils/scenario.py b/policyengine_uk/utils/scenario.py index df3e02c162..f74777b297 100644 --- a/policyengine_uk/utils/scenario.py +++ b/policyengine_uk/utils/scenario.py @@ -363,7 +363,9 @@ def apply(self, simulation: Simulation) -> None: overrides: List[LegacyOverride] = [] if self.parameter_changes: parameters = simulation.tax_benefit_system.parameters - for path, value in self.parameter_changes.items(): + # Keyed by canonical paths, as a sum of scenarios already is, so a + # deprecated alias path changes the parameter formulas read. + for path, value in _canonical_paths(self.parameter_changes).items(): if isinstance(value, dict): # Handle nested parameter changes if not value: