Skip to content

Commit c17dc69

Browse files
authored
Merge pull request #264 from PolicyEngine/fresh-pr
Add Scotland UC households with youngest child under 1 calibration target
2 parents 7d2da06 + 9832a7c commit c17dc69

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
27-
pip install black
27+
pip install black==25.1.0
2828
- name: Check formatting
2929
run: black . -l 79 --check
3030
test:

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: minor
2+
changes:
3+
added:
4+
- Add calibration target for UC households in Scotland with youngest child under 1 (~14k from DWP Stat-Xplore)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
)

policyengine_uk_data/utils/loss.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,27 @@ def pe_count(*variables):
536536
target_names.append("sss/scottish_child_payment")
537537
target_values.append(scp_target)
538538

539+
# UC households in Scotland with child under 1
540+
# Source: DWP Stat-Xplore, UC Households dataset, November 2023
541+
# https://stat-xplore.dwp.gov.uk/
542+
# Filters: Scotland, Age of Youngest Child = 0
543+
# ~14,000 households (13,992 in November 2023)
544+
uc_amount = sim.calculate("universal_credit")
545+
on_uc_family = uc_amount > 0
546+
on_uc_household = household_from_family(on_uc_family) > 0
547+
548+
child_under_1 = is_child & (age < 1)
549+
has_child_under_1 = household_from_person(child_under_1) > 0
550+
551+
scotland_uc_child_under_1 = (
552+
(household_region == "SCOTLAND") & on_uc_household & has_child_under_1
553+
)
554+
df["dwp/scotland_uc_households_child_under_1"] = (
555+
scotland_uc_child_under_1.astype(float)
556+
)
557+
target_names.append("dwp/scotland_uc_households_child_under_1")
558+
target_values.append(14_000) # 13,992 rounded, November 2023
559+
539560
# Council Tax band counts
540561

541562
ct_data = pd.read_csv(STORAGE_FOLDER / "council_tax_bands_2024.csv")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ python_classes = ["Test*"]
5959
python_functions = ["test_*"]
6060
markers = [
6161
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
62-
"unit: marks tests as unit tests",
62+
"unit: marks tests as unit tests",
6363
"integration: marks tests as integration tests",
6464
]
6565
filterwarnings = [

0 commit comments

Comments
 (0)