Skip to content

Commit 043e655

Browse files
authored
Widen disability benefit flags from reported amounts (#416)
1 parent 0cfcfb2 commit 043e655

2 files changed

Lines changed: 82 additions & 6 deletions

File tree

policyengine_uk_data/datasets/disability_benefits.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
"pip_dl_category",
3434
)
3535

36+
BASE_DISABILITY_FLAG_REPORTED_AMOUNT_COLUMNS = (
37+
"attendance_allowance_reported",
38+
"dla_sc_reported",
39+
"dla_m_reported",
40+
"pip_m_reported",
41+
"pip_dl_reported",
42+
"sda_reported",
43+
"incapacity_benefit_reported",
44+
"iidb_reported",
45+
"afcs_reported",
46+
"esa_contrib_reported",
47+
"esa_income_reported",
48+
)
49+
3650
SAFETY_MARGIN = 0.1
3751
SURVEY_REPORTED_AMOUNT_WEEKS_IN_YEAR = 365.25 / 7
3852

@@ -56,6 +70,16 @@ def _reported_amount(person: pd.DataFrame, column: str) -> pd.Series:
5670
return pd.to_numeric(person[column], errors="coerce").fillna(0.0)
5771

5872

73+
def _reported_amount_sum(
74+
person: pd.DataFrame,
75+
columns: tuple[str, ...],
76+
) -> pd.Series:
77+
total = pd.Series(0.0, index=person.index)
78+
for column in columns:
79+
total += _reported_amount(person, column)
80+
return total
81+
82+
5983
def _category_from_reported_amount(
6084
reported_amount: pd.Series,
6185
thresholds: tuple[tuple[str, float], ...],
@@ -148,15 +172,20 @@ def add_disability_benefit_flags_from_reported_amounts(
148172
person = person.copy()
149173

150174
dwp = _dwp_flag_parameters(int(year))
175+
attendance_allowance = _reported_amount(person, "attendance_allowance_reported")
151176
dla_sc = _reported_amount(person, "dla_sc_reported")
152-
dla_m = _reported_amount(person, "dla_m_reported")
153-
pip_m = _reported_amount(person, "pip_m_reported")
154177
pip_dl = _reported_amount(person, "pip_dl_reported")
155178
afcs = _reported_amount(person, "afcs_reported")
156179

157-
person["is_disabled_for_benefits"] = (dla_sc + dla_m + pip_m + pip_dl) > 0
180+
person["is_disabled_for_benefits"] = (
181+
_reported_amount_sum(person, BASE_DISABILITY_FLAG_REPORTED_AMOUNT_COLUMNS) > 0
182+
)
158183

159184
threshold_safety_gap = 1 * SURVEY_REPORTED_AMOUNT_WEEKS_IN_YEAR
185+
aa_higher = (
186+
dwp.attendance_allowance.higher * SURVEY_REPORTED_AMOUNT_WEEKS_IN_YEAR
187+
- threshold_safety_gap
188+
)
160189
dla_sc_higher = (
161190
dwp.dla.self_care.higher * SURVEY_REPORTED_AMOUNT_WEEKS_IN_YEAR
162191
- threshold_safety_gap
@@ -166,9 +195,16 @@ def add_disability_benefit_flags_from_reported_amounts(
166195
- threshold_safety_gap
167196
)
168197

169-
person["is_enhanced_disabled_for_benefits"] = dla_sc > dla_sc_higher
198+
person["is_enhanced_disabled_for_benefits"] = (
199+
(attendance_allowance >= aa_higher)
200+
| (dla_sc > dla_sc_higher)
201+
| (pip_dl >= pip_dl_enhanced)
202+
)
170203
person["is_severely_disabled_for_benefits"] = (
171-
(dla_sc >= dla_sc_higher) | (pip_dl >= pip_dl_enhanced) | (afcs > 0)
204+
(attendance_allowance > 0)
205+
| (dla_sc >= dla_sc_higher)
206+
| (pip_dl >= pip_dl_enhanced)
207+
| (afcs > 0)
172208
)
173209

174210
return person

policyengine_uk_data/tests/test_disability_benefits.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_reported_amounts_recompute_disability_flags():
6060
dwp = CountryTaxBenefitSystem().parameters(year).gov.dwp
6161
person = pd.DataFrame(
6262
{
63+
"attendance_allowance_reported": [0.0, 0.0, 0.0],
6364
"dla_sc_reported": [
6465
0.0,
6566
dwp.dla.self_care.higher * (365.25 / 7),
@@ -85,7 +86,7 @@ def test_reported_amounts_recompute_disability_flags():
8586
assert result["is_enhanced_disabled_for_benefits"].tolist() == [
8687
False,
8788
True,
88-
False,
89+
True,
8990
]
9091
assert result["is_severely_disabled_for_benefits"].tolist() == [
9192
False,
@@ -94,6 +95,45 @@ def test_reported_amounts_recompute_disability_flags():
9495
]
9596

9697

98+
def test_reported_amounts_widen_base_disability_flag():
99+
year = 2025
100+
person = pd.DataFrame(
101+
{
102+
"attendance_allowance_reported": [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
103+
"sda_reported": [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
104+
"incapacity_benefit_reported": [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
105+
"iidb_reported": [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
106+
"afcs_reported": [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0],
107+
"esa_contrib_reported": [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0],
108+
"esa_income_reported": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
109+
}
110+
)
111+
112+
result = add_disability_benefit_flags_from_reported_amounts(person, year)
113+
114+
assert result["is_disabled_for_benefits"].all()
115+
116+
117+
def test_attendance_allowance_feeds_stronger_disability_flags():
118+
year = 2025
119+
dwp = CountryTaxBenefitSystem().parameters(year).gov.dwp
120+
weeks = 365.25 / 7
121+
person = pd.DataFrame(
122+
{
123+
"attendance_allowance_reported": [
124+
dwp.attendance_allowance.lower * weeks,
125+
dwp.attendance_allowance.higher * weeks,
126+
],
127+
}
128+
)
129+
130+
result = add_disability_benefit_flags_from_reported_amounts(person, year)
131+
132+
assert result["is_disabled_for_benefits"].tolist() == [True, True]
133+
assert result["is_enhanced_disabled_for_benefits"].tolist() == [False, True]
134+
assert result["is_severely_disabled_for_benefits"].tolist() == [True, True]
135+
136+
97137
def test_drop_internal_disability_reported_amounts_keeps_categories():
98138
person = pd.DataFrame(
99139
{

0 commit comments

Comments
 (0)