From 216ef35e7f722a9c3239aef5880610bc63911e85 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 25 Oct 2026 01:02:34 -0400 Subject: [PATCH 1/3] Compare Guarantee Credit pound for pound only where it is paid at both amounts Round 2 review N4 of #2645: the mask looked only at the later amount, so a draw where Guarantee Credit starts from zero would fail although the model is right. Adds that case (a carer with IIDB) as an explicit example. Fixes #2652 Co-Authored-By: Claude Opus 5.5 --- ...ion_credit_widowed_parents_allowance_properties.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py b/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py index 6c481ddf8f..c996a62d3a 100644 --- a/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py +++ b/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py @@ -75,6 +75,12 @@ def carer(country): # Carer's Allowance in England and Carer Support Payment in Scotland, each # paid in full until WPA displaces it. CARERS = [carer("ENGLAND"), carer("SCOTLAND")] +# The same carer with £10,500 of IIDB: a draw where Guarantee Credit can start +# from zero once WPA displaces Carer's Allowance. +CARER_WITH_IIDB = dict( + carer("ENGLAND"), + benefits={**carer("ENGLAND")["benefits"], "iidb": (0, 10_500.0)}, +) def test_an_award_that_displaces_a_carer_benefit_raises_guarantee_credit_by_the_disregard(): @@ -108,6 +114,7 @@ def test_an_award_that_displaces_a_carer_benefit_raises_guarantee_credit_by_the_ @PROPERTY_SETTINGS @given(st.lists(family(state_pension=8_000), min_size=1, max_size=4)) @example(CARERS) +@example([CARER_WITH_IIDB]) def test_guarantee_credit_falls_pound_for_pound_with_widowed_parents_allowance( families, ): @@ -139,7 +146,9 @@ def test_guarantee_credit_falls_pound_for_pound_with_widowed_parents_allowance( assert np.allclose( extra_income[positive_income], expected[positive_income], atol=0.01 ), (families, pc_income, tax, carer_benefit) - paid = gc[..., 1:] > 0 + # Pound for pound only where Guarantee Credit is paid at both amounts: from + # zero it rises by less than the income falls (round 2 review N4 of #2645). + paid = (gc[..., :-1] > 0) & (gc[..., 1:] > 0) assert np.allclose(-np.diff(gc, axis=-1)[paid], extra_income[paid], atol=0.01), ( families, gc, From c2992567327d38d316ab1cd10d9936877607dbeb Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 25 Oct 2026 01:02:36 -0400 Subject: [PATCH 2/3] Add the changelog fragment for #2652 Co-Authored-By: Claude Opus 5.5 --- changelog.d/2652.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/2652.fixed.md diff --git a/changelog.d/2652.fixed.md b/changelog.d/2652.fixed.md new file mode 100644 index 0000000000..2508d12f61 --- /dev/null +++ b/changelog.d/2652.fixed.md @@ -0,0 +1 @@ +Fixed a Pension Credit property test that compared Guarantee Credit pound for pound where it started from zero. From ce6b784e6e841d64771647768745fc69a393f350 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sun, 25 Oct 2026 04:16:58 -0400 Subject: [PATCH 3/3] Assert the floored Guarantee Credit change at both ends Per the independent review of #2653 (F1, F2): instead of skipping steps where Guarantee Credit starts or ends, assert that the minimum guarantee does not move with WPA, that a paid Guarantee Credit becomes max(before - extra income, 0), and that from zero it rises by no more than the income falls. The new IIDB example's own 0 -> 404.40 step is now checked. The docstring's invariant 1 says the same. Co-Authored-By: Claude Opus 5.5 --- ...it_widowed_parents_allowance_properties.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py b/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py index c996a62d3a..a78336a9c3 100644 --- a/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py +++ b/policyengine_uk/tests/test_pension_credit_widowed_parents_allowance_properties.py @@ -25,7 +25,8 @@ 1. Extra Pension Credit income is the extra WPA above £10 a week, less the extra income tax and National Insurance, less any Carer's Allowance or Carer Support Payment it displaces. While Guarantee Credit is positive it - falls pound for pound with that income, and it never rises where no + falls pound for pound with that income until it reaches zero; from zero it + rises by no more than the income falls; and it never rises where no carer's benefit is displaced. 2. Differential: where neither Guarantee Credit nor Savings Credit is due and Housing Benefit income is above its zero floor, Housing Benefit applicable @@ -124,6 +125,7 @@ def test_guarantee_credit_falls_pound_for_pound_with_widowed_parents_allowance( (len(families), len(AMOUNTS)), [ "guarantee_credit", + "minimum_guarantee", "pension_credit_income", INCOME_TAX, "national_insurance", @@ -146,10 +148,22 @@ def test_guarantee_credit_falls_pound_for_pound_with_widowed_parents_allowance( assert np.allclose( extra_income[positive_income], expected[positive_income], atol=0.01 ), (families, pc_income, tax, carer_benefit) - # Pound for pound only where Guarantee Credit is paid at both amounts: from - # zero it rises by less than the income falls (round 2 review N4 of #2645). - paid = (gc[..., :-1] > 0) & (gc[..., 1:] > 0) - assert np.allclose(-np.diff(gc, axis=-1)[paid], extra_income[paid], atol=0.01), ( + # Guarantee Credit is the minimum guarantee less Pension Credit income, + # floored at zero, and WPA does not change the minimum guarantee (the + # carer addition follows entitlement before overlap). So Guarantee Credit + # falls pound for pound with the income until it reaches zero, and from + # zero it rises by no more than the income falls (round 2 review N4 of + # #2645). + assert np.allclose(np.diff(g["minimum_guarantee"], axis=-1), 0, atol=0.01), ( + families, + g["minimum_guarantee"], + ) + before, after = gc[..., :-1], gc[..., 1:] + paid = before > 0 + assert np.allclose( + after[paid], np.maximum(before - extra_income, 0)[paid], atol=0.01 + ), (families, gc, pc_income) + assert np.all(after[~paid] <= np.maximum(-extra_income, 0)[~paid] + 0.01), ( families, gc, pc_income,