Skip to content

Commit

Permalink
Replace if with where
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid-ahmadi committed Jan 13, 2025
1 parent d3ad685 commit 5c6d359
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
description: Income thresholds for tax-free childcare eligibility - adult category
description: Income thresholds for tax-free childcare eligibility
metadata:
period: year
label: Adult income thresholds for tax-free childcare eligibility
label: Income thresholds for tax-free childcare eligibility
reference:
- title: Childcare Payments Act
href: https://www.legislation.gov.uk/ukdsi/2015/9780111127063
- title: Tax-Free Childcare Guidance
href: https://www.gov.uk/tax-free-childcare?step-by-step-nav=d78aeaf6-1747-4d72-9619-f16efb4dd89d

quarterly_income:
values:
2015-01-01: 2379
metadata:
unit: currency-GBP

min_age:
values:
2015-01-01: 21
metadata:
unit: year
period: year
brackets:
- threshold:
2015-01-01: 0
amount:
2015-01-01: 0
- threshold:
2015-01-01: 18
amount:
2015-01-01: 1_788
- threshold:
2015-01-01: 21
amount:
2015-01-01: 2_379

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from policyengine_uk.model_api import *


class child_age_eligible(Variable):
value_type = bool
entity = Person
Expand All @@ -22,8 +21,8 @@ def formula(person, period, parameters):
age_limits = parameters(
period
).gov.hmrc.childcare_subsidies.tax_free_childcare.age
standard_age_limit = age_limits.standard.values
disability_age_limit = age_limits.disability.values
standard_age_limit = age_limits.standard
disability_age_limit = age_limits.disability

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

# Combine conditions
return basic_age_condition | (age_under_disability_limit & is_disabled)
return basic_age_condition | (age_under_disability_limit & is_disabled)
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,14 @@ def formula(person, period, parameters):
)

yearly_eligible_income = max_(total_income - investment_income, 0)
quarterly_income = yearly_eligible_income / 4

# Get income thresholds from parameters
# Get required income threshold based on age
income_limits = parameters(
period
).gov.hmrc.childcare_subsidies.tax_free_childcare.income_thresholds
quarterly_income = yearly_eligible_income / 4

# Age >= 21
meets_adult_condition = (age >= income_limits.adult.min_age.values) & (
quarterly_income >= income_limits.adult.quarterly_income.values
)

# Age 18-20
meets_young_adult_condition = (
(age >= income_limits.young_adult.min_age.values)
& (age <= income_limits.young_adult.max_age.values)
& (
quarterly_income
>= income_limits.young_adult.quarterly_income.values
)
)

# Age < 18
meets_youth_condition = (
age < income_limits.young_adult.min_age.values
) & (quarterly_income >= income_limits.youth.quarterly_income.values)

# Combine all conditions
return (
meets_adult_condition
| meets_young_adult_condition
| meets_youth_condition
)

required_threshold = income_limits.calc(age)

# Compare quarterly income to required threshold
return quarterly_income >= required_threshold
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ def formula(benunit, period, parameters):
# Determine the maximum eligible childcare cost for a single child
max_amount = 0
for child in benunit.members("is_child", period):
if is_eligible[child]:
if child("is_disabled", period):
max_amount = p.disabled_child.values
else:
max_amount = p.standard_child.values

return where(is_eligible, max_amount, 0)
max_amount = where(
is_eligible[child],
where(
child("is_disabled", period),
p.disabled_child.values,
p.standard_child.values
),
max_amount
)

return where(is_eligible, max_amount, 0)

0 comments on commit 5c6d359

Please sign in to comment.