Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/scenario-apply-canonical-paths.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions policyengine_uk/tests/test_process_time_reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion policyengine_uk/utils/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading