Skip to content

Commit 5c6d359

Browse files
committed
Replace if with where
1 parent d3ad685 commit 5c6d359

File tree

6 files changed

+36
-98
lines changed

6 files changed

+36
-98
lines changed

policyengine_uk/parameters/gov/hmrc/childcare_subsidies/tax_free_childcare/income_thresholds/adult.yaml renamed to policyengine_uk/parameters/gov/hmrc/childcare_subsidies/tax_free_childcare/income_thresholds.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
description: Income thresholds for tax-free childcare eligibility - adult category
1+
description: Income thresholds for tax-free childcare eligibility
22
metadata:
33
period: year
4-
label: Adult income thresholds for tax-free childcare eligibility
4+
label: Income thresholds for tax-free childcare eligibility
55
reference:
66
- title: Childcare Payments Act
77
href: https://www.legislation.gov.uk/ukdsi/2015/9780111127063
88
- title: Tax-Free Childcare Guidance
99
href: https://www.gov.uk/tax-free-childcare?step-by-step-nav=d78aeaf6-1747-4d72-9619-f16efb4dd89d
1010

11-
quarterly_income:
12-
values:
13-
2015-01-01: 2379
14-
metadata:
15-
unit: currency-GBP
16-
17-
min_age:
18-
values:
19-
2015-01-01: 21
20-
metadata:
21-
unit: year
22-
period: year
11+
brackets:
12+
- threshold:
13+
2015-01-01: 0
14+
amount:
15+
2015-01-01: 0
16+
- threshold:
17+
2015-01-01: 18
18+
amount:
19+
2015-01-01: 1_788
20+
- threshold:
21+
2015-01-01: 21
22+
amount:
23+
2015-01-01: 2_379

policyengine_uk/parameters/gov/hmrc/childcare_subsidies/tax_free_childcare/income_thresholds/young_adult.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

policyengine_uk/parameters/gov/hmrc/childcare_subsidies/tax_free_childcare/income_thresholds/youth.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/childcare_age_child_condition.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from policyengine_uk.model_api import *
22

3-
43
class child_age_eligible(Variable):
54
value_type = bool
65
entity = Person
@@ -22,8 +21,8 @@ def formula(person, period, parameters):
2221
age_limits = parameters(
2322
period
2423
).gov.hmrc.childcare_subsidies.tax_free_childcare.age
25-
standard_age_limit = age_limits.standard.values
26-
disability_age_limit = age_limits.disability.values
24+
standard_age_limit = age_limits.standard
25+
disability_age_limit = age_limits.disability
2726

2827
# Check disability conditions
2928
gc = parameters(
@@ -42,4 +41,4 @@ def formula(person, period, parameters):
4241
age_under_disability_limit = age < disability_age_limit
4342

4443
# Combine conditions
45-
return basic_age_condition | (age_under_disability_limit & is_disabled)
44+
return basic_age_condition | (age_under_disability_limit & is_disabled)

policyengine_uk/variables/gov/hmrc/tax_free_childcare/conditions/childcare_income_condition.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,14 @@ def formula(person, period, parameters):
3333
)
3434

3535
yearly_eligible_income = max_(total_income - investment_income, 0)
36+
quarterly_income = yearly_eligible_income / 4
3637

37-
# Get income thresholds from parameters
38+
# Get required income threshold based on age
3839
income_limits = parameters(
3940
period
4041
).gov.hmrc.childcare_subsidies.tax_free_childcare.income_thresholds
41-
quarterly_income = yearly_eligible_income / 4
42-
43-
# Age >= 21
44-
meets_adult_condition = (age >= income_limits.adult.min_age.values) & (
45-
quarterly_income >= income_limits.adult.quarterly_income.values
46-
)
47-
48-
# Age 18-20
49-
meets_young_adult_condition = (
50-
(age >= income_limits.young_adult.min_age.values)
51-
& (age <= income_limits.young_adult.max_age.values)
52-
& (
53-
quarterly_income
54-
>= income_limits.young_adult.quarterly_income.values
55-
)
56-
)
57-
58-
# Age < 18
59-
meets_youth_condition = (
60-
age < income_limits.young_adult.min_age.values
61-
) & (quarterly_income >= income_limits.youth.quarterly_income.values)
62-
63-
# Combine all conditions
64-
return (
65-
meets_adult_condition
66-
| meets_young_adult_condition
67-
| meets_youth_condition
68-
)
42+
43+
required_threshold = income_limits.calc(age)
44+
45+
# Compare quarterly income to required threshold
46+
return quarterly_income >= required_threshold

policyengine_uk/variables/gov/hmrc/tax_free_childcare/tax_free_childcare_benefits.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ def formula(benunit, period, parameters):
4040
# Determine the maximum eligible childcare cost for a single child
4141
max_amount = 0
4242
for child in benunit.members("is_child", period):
43-
if is_eligible[child]:
44-
if child("is_disabled", period):
45-
max_amount = p.disabled_child.values
46-
else:
47-
max_amount = p.standard_child.values
48-
49-
return where(is_eligible, max_amount, 0)
43+
max_amount = where(
44+
is_eligible[child],
45+
where(
46+
child("is_disabled", period),
47+
p.disabled_child.values,
48+
p.standard_child.values
49+
),
50+
max_amount
51+
)
52+
53+
return where(is_eligible, max_amount, 0)

0 commit comments

Comments
 (0)