|
| 1 | +"""Test Scotland UC households with child under 1 calibration target. |
| 2 | +
|
| 3 | +Source: DWP Stat-Xplore, UC Households dataset, November 2023 |
| 4 | +https://stat-xplore.dwp.gov.uk/ |
| 5 | +Filters: Scotland, Age of Youngest Child = 0 |
| 6 | +Result: 13,992 households (~14k) |
| 7 | +""" |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.xfail( |
| 13 | + reason="Will pass after recalibration with new scotland_uc_households_child_under_1 target" |
| 14 | +) |
| 15 | +def test_scotland_uc_households_child_under_1(baseline): |
| 16 | + """Test that UC households in Scotland with child under 1 matches DWP data. |
| 17 | +
|
| 18 | + Target: ~14,000 households (13,992 from Stat-Xplore November 2023) |
| 19 | + Source: DWP Stat-Xplore UC Households dataset |
| 20 | + """ |
| 21 | + region = baseline.calculate( |
| 22 | + "region", map_to="household", period=2025 |
| 23 | + ).values |
| 24 | + uc = baseline.calculate("universal_credit", period=2025).values |
| 25 | + household_weight = baseline.calculate( |
| 26 | + "household_weight", map_to="household", period=2025 |
| 27 | + ).values |
| 28 | + |
| 29 | + # Check if household has child under 1 |
| 30 | + is_child = baseline.calculate( |
| 31 | + "is_child", map_to="person", period=2025 |
| 32 | + ).values |
| 33 | + age = baseline.calculate("age", map_to="person", period=2025).values |
| 34 | + |
| 35 | + child_under_1 = is_child & (age < 1) |
| 36 | + has_child_under_1 = ( |
| 37 | + baseline.map_result(child_under_1, "person", "household") > 0 |
| 38 | + ) |
| 39 | + |
| 40 | + scotland_uc_child_under_1 = ( |
| 41 | + (region == "SCOTLAND") & (uc > 0) & has_child_under_1 |
| 42 | + ) |
| 43 | + total = (household_weight * scotland_uc_child_under_1).sum() |
| 44 | + |
| 45 | + TARGET = 14_000 # DWP Stat-Xplore November 2023: 13,992 rounded to 14k |
| 46 | + TOLERANCE = 0.15 # 15% tolerance |
| 47 | + |
| 48 | + assert abs(total / TARGET - 1) < TOLERANCE, ( |
| 49 | + f"Expected ~{TARGET/1000:.0f}k UC households with child under 1 in Scotland, " |
| 50 | + f"got {total/1000:.0f}k ({total/TARGET*100:.0f}% of target)" |
| 51 | + ) |
0 commit comments