Skip to content

Commit

Permalink
Edit files based on Pavel's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid-ahmadi committed Jan 23, 2025
1 parent c1bb0e1 commit df9f458
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
input:
tax_free_childcare_child_age_eligible: true
tax_free_childcare_meets_income_requirements: true
tax_free_childcare_incompatibilities_childcare_eligible: true
tax_free_childcare_program_eligible: true
tax_free_childcare_work_condition: true
output:
tax_free_childcare_eligible: true
Expand All @@ -14,7 +14,7 @@
input:
tax_free_childcare_child_age_eligible: false
tax_free_childcare_meets_income_requirements: true
tax_free_childcare_incompatibilities_childcare_eligible: true
tax_free_childcare_program_eligible: true
tax_free_childcare_work_condition: true
output:
tax_free_childcare_eligible: false
Expand All @@ -24,7 +24,7 @@
input:
tax_free_childcare_child_age_eligible: true
tax_free_childcare_meets_income_requirements: false
tax_free_childcare_incompatibilities_childcare_eligible: true
tax_free_childcare_program_eligible: true
tax_free_childcare_work_condition: true
output:
tax_free_childcare_eligible: false
Expand All @@ -34,7 +34,7 @@
input:
tax_free_childcare_child_age_eligible: true
tax_free_childcare_meets_income_requirements: true
tax_free_childcare_incompatibilities_childcare_eligible: true
tax_free_childcare_program_eligible: true
tax_free_childcare_work_condition: false
output:
tax_free_childcare_eligible: false
Expand All @@ -44,7 +44,7 @@
input:
tax_free_childcare_child_age_eligible: false
tax_free_childcare_meets_income_requirements: false
tax_free_childcare_incompatibilities_childcare_eligible: false
tax_free_childcare_program_eligible: false
tax_free_childcare_work_condition: false
output:
tax_free_childcare_eligible: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
child_tax_credit: 0
universal_credit: 0
output:
tax_free_childcare_incompatibilities_childcare_eligible: True
tax_free_childcare_program_eligible: True


- name: Non eligible - receives benefits
Expand All @@ -15,7 +15,7 @@
child_tax_credit: 0
universal_credit: 0
output:
tax_free_childcare_incompatibilities_childcare_eligible: False
tax_free_childcare_program_eligible: False


- name: Non eligible - receives benefits
Expand All @@ -25,7 +25,7 @@
child_tax_credit: 1
universal_credit: 0
output:
tax_free_childcare_incompatibilities_childcare_eligible: False
tax_free_childcare_program_eligible: False


- name: Non eligible - receives benefits
Expand All @@ -35,4 +35,4 @@
child_tax_credit: 1
universal_credit: 1
output:
tax_free_childcare_incompatibilities_childcare_eligible: False
tax_free_childcare_program_eligible: False
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class tax_free_childcare_child_age_eligible(Variable):
value_type = bool
entity = Person
label = "Child age eligibility requirements for tax-free childcare"
label = "Eligible child for the tax-free childcare"
documentation = "Whether this person meets the age and disability requirements for eligibility"
definition_period = YEAR

Expand All @@ -20,18 +20,14 @@ def formula(person, period, parameters):

# Get age thresholds from parameters
age_limits = parameters(period).gov.hmrc.tax_free_childcare.age
standard_age_limit = age_limits.standard
disability_age_limit = age_limits.disability

# Check disability status
is_disabled = person("is_disabled_for_benefits", period)

# Check age conditions using parameterized values
basic_age_condition = (age < standard_age_limit).astype(bool)
age_under_disability_limit = (age < disability_age_limit).astype(bool)
basic_age_condition = age < age_limits.standard
age_under_disability_limit = age < age_limits.disability

# Combine conditions
combined_condition = (age_under_disability_limit & is_disabled).astype(
bool
)
return (basic_age_condition | combined_condition).astype(bool)
combined_condition = age_under_disability_limit & is_disabled
return basic_age_condition | combined_condition
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class tax_free_childcare_meets_income_requirements(Variable):
value_type = bool
entity = Person
label = "Income requirements and calculations for tax-free childcare"
label = "Income eligible for the tax-free childcare"
documentation = "Whether this person meets the income requirements for tax-free childcare based on age and income thresholds"
definition_period = YEAR

Expand Down Expand Up @@ -36,20 +36,10 @@ def formula(person, period, parameters):
quarterly_income = yearly_eligible_income / 4

# Get required income threshold based on age
income_limits = parameters(
period
).gov.hmrc.tax_free_childcare.income_thresholds

required_threshold = income_limits.calc(age)

max_income_threshold = parameters(
period
).gov.hmrc.tax_free_childcare.max_income_thresholds

max_income_threshold_quarterly = max_income_threshold / 4

p = parameters(period).gov.hmrc.tax_free_childcare
required_threshold = p.income_thresholds.calc(age)
max_income_threshold_quarterly = p.max_income_thresholds / 4
# Compare quarterly income to required threshold and convert to boolean
return (
(quarterly_income > required_threshold)
& (quarterly_income < max_income_threshold_quarterly)
).astype(bool)
return (quarterly_income > required_threshold) & (
quarterly_income < max_income_threshold_quarterly
)

This file was deleted.

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


class tax_free_childcare_program_eligible(Variable):
value_type = bool
entity = Person
label = "Tax-Free Childcare program eligibility"
documentation = "Whether the person's benefit unit meets the incompatibility conditions for tax-free childcare (not receiving WTC, CTC, or UC)"
definition_period = YEAR

def formula(person, period, parameters):
"""
Calculate eligibility based on incompatible benefits.
Returns:
bool: True if eligible (no incompatible benefits received), False if receiving any incompatible benefits
"""
countable_programs = add(person.benunit, period, ["working_tax_credit", "child_tax_credit", "universal_credit"])
return countable_programs == 0
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def formula(person, period, parameters):
- Couple where either both work or one works and other has disability/incapacity
"""
benunit = person.benunit
is_adult = person("is_adult", period).astype(bool)
is_adult = person("is_adult", period)

# Basic work status
in_work = person("in_work", period).astype(bool)
Expand All @@ -24,24 +24,26 @@ def formula(person, period, parameters):
standard_disability_benefits = gc.child.disability.eligibility
severe_disability_benefits = gc.child.disability.severe.eligibility

is_disabled = (
receive_disability_program = (
(add(person, period, standard_disability_benefits) > 0)
| (add(person, period, severe_disability_benefits) > 0)
).astype(bool)

has_incapacity = (person("incapacity_benefit", period) > 0).astype(
bool
)
has_condition = (is_disabled | has_incapacity).astype(bool)
eligible_based_on_disability = (
receive_disability_program | has_incapacity
).astype(bool)

# Build conditions
# Single adult conditions
is_single = (benunit.sum(is_adult) == 1).astype(bool)
is_single = person.benunit("is_single", period)
single_working = (is_single & in_work).astype(bool)

# Couple conditions
is_couple = (benunit.sum(is_adult) == 2).astype(bool)
benunit_has_condition = benunit.any(has_condition)
is_couple = person.benunit("is_couple", period)
benunit_has_condition = benunit.any(eligible_based_on_disability)
benunit_has_worker = benunit.any(in_work)
couple_both_working = (is_couple & benunit.all(in_work)).astype(bool)
couple_one_working_one_disabled = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class tax_free_childcare_benefits_amount(Variable):
documentation = "The amount of government contribution provided through the tax-free childcare scheme"
definition_period = YEAR
unit = GBP
defined_for = "tax_free_childcare_eligible"

def formula(benunit, period, parameters):
"""
Expand All @@ -28,17 +29,13 @@ def formula(benunit, period, parameters):
is_eligible = benunit("tax_free_childcare_eligible", period)

# Calculate per-child amounts at the person level
is_child = benunit.members("is_child", period)
is_disabled = benunit.members("is_disabled_for_benefits", period)
person = benunit.members
is_child = person("is_child", period)
is_disabled = person("is_disabled_for_benefits", period)

child_amounts = where(
is_child,
where(is_disabled, p_tfc.disabled_child, p_tfc.standard_child),
0,
)
amount_per_child = (
where(is_disabled, p_tfc.disabled_child, p_tfc.standard_child)
) * is_child

# Reduce to benefit unit level by taking maximum
max_amount = benunit.max(child_amounts)

# Apply final eligibility check
return where(is_eligible, max_amount, 0)
return benunit.sum(amount_per_child)
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ def formula(benunit, period, parameters):
"""
meets_age_condition = benunit(
"tax_free_childcare_child_age_eligible", period
).astype(bool)
)

meets_income_condition = benunit.any(
benunit.members(
"tax_free_childcare_meets_income_requirements", period
)
).astype(bool)
)

childcare_eligible = benunit(
"tax_free_childcare_incompatibilities_childcare_eligible", period
).astype(bool)
"tax_free_childcare_program_eligible", period
)

work_eligible = benunit(
"tax_free_childcare_work_condition", period
).astype(bool)
work_eligible = benunit("tax_free_childcare_work_condition", period)

return np.logical_and.reduce(
[
Expand Down

0 comments on commit df9f458

Please sign in to comment.