Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def get_current_version(pyproject_path: Path) -> str:

def infer_bump(changelog_dir: Path) -> str:
fragments = [
f
for f in changelog_dir.iterdir()
if f.is_file() and f.name != ".gitkeep"
f for f in changelog_dir.iterdir() if f.is_file() and f.name != ".gitkeep"
]
if not fragments:
print("No changelog fragments found", file=sys.stderr)
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check formatting
uses: "lgeiger/black-action@master"
- name: Set up Python
uses: actions/setup-python@v5
with:
args: ". -l 79 --check"
python-version: "3.14"
allow-prereleases: true
- name: Install ruff
run: pip install "ruff>=0.9.0"
- name: Check formatting
run: ruff format --check .
check-changelog:
name: Check changelog fragment
runs-on: ubuntu-latest
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ jobs:
&& (github.event.head_commit.message == 'Update PolicyEngine Canada')
steps:
- uses: actions/checkout@v4
- name: Check formatting
uses: "lgeiger/black-action@master"
- name: Set up Python
uses: actions/setup-python@v5
with:
args: ". -l 79 --check"
python-version: "3.14"
allow-prereleases: true
- name: Install ruff
run: pip install "ruff>=0.9.0"
- name: Check formatting
run: ruff format --check .
versioning:
name: Update versioning
if: |
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ documentation:
jupyter-book build docs

format:
black . -l 79
linecheck . --fix
ruff format .

install:
pip install -e .[dev]
Expand Down
1 change: 1 addition & 0 deletions changelog.d/switch-to-ruff.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch code formatter from Black to Ruff.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class CountryTemplateDataset(Dataset):
label = "Country template dataset"
folder_path = COUNTRY_DIR / "data" / "storage"
data_format = Dataset.TIME_PERIOD_ARRAYS
file_path = (
Path(__file__).parent.parent
/ "storage"
/ "country_template_dataset.h5"
)
file_path = Path(__file__).parent.parent / "storage" / "country_template_dataset.h5"

# The generation function is the most important part: it defines
# how the dataset is generated from the raw data for a given year.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ def formula(person, period, parameters):
age = person("age", period)
p = parameters(period).gov.cra.benefits.ccb
full_custody = person("full_custody", period)
return where(
full_custody, p.base.calc(age), p.base.calc(age) / p.divisor
)
return where(full_custody, p.base.calc(age), p.base.calc(age) / p.divisor)
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def formula(household, period, parameters):
person = household.members
# Compute individual-level eligibility among heads/spouses.
head_or_spouse = person("is_head_or_spouse", period)
disability_eligible = person(
"cwb_disability_supplement_eligible", period
)
disability_eligible = person("cwb_disability_supplement_eligible", period)
cwb_family = household("is_cwb_family", period)
eligible_spouses = household.sum(head_or_spouse * disability_eligible)
return select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class cwb_disability_supplement_eligible(Variable):
entity = Person
label = "Eligible for canada workers benefit supplement"
definition_period = YEAR
reference = (
"https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
)
reference = "https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"

def formula(person, period, parameters):
# For now, apply a person-level logic based on age.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ class cwb_disability_supplement_max_amount(Variable):
entity = Household
label = "Eligible for canada workers benefit supplement"
definition_period = YEAR
reference = (
"https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
)
reference = "https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
unit = CAD

def formula(household, period, parameters):
person = household.members
eligible = person("cwb_disability_supplement_eligible", period)
amount = parameters(
period
).gov.cra.benefits.cwb.amount.disability_supplement
amount = parameters(period).gov.cra.benefits.cwb.amount.disability_supplement
return household.sum(eligible * amount)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class cwb_disability_supplement_phase_in(Variable):

def formula(household, period, parameters):
income = household("family_working_income", period)
p = parameters(
period
).gov.cra.benefits.cwb.phase_in.disability_supplement
p = parameters(period).gov.cra.benefits.cwb.phase_in.disability_supplement
return p.calc(income)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class cwb_disability_supplement_phase_out(Variable):

def formula(household, period, parameters):
income = household("adjusted_family_net_income", period)
p = parameters(
period
).gov.cra.benefits.cwb.phase_out.disability_supplement
p = parameters(period).gov.cra.benefits.cwb.phase_out.disability_supplement
category = household("cwb_disability_category", period)
categories = category.possible_values
return select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class family_working_income(Variable):
documentation = "Income from employment and self-employment of a family"
definition_period = YEAR
# A.2.(122.7)(1.1)
reference = (
"https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-96.html#h-299725"
)
reference = "https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-96.html#h-299725"

adds = ["working_income"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ class oas_eligibility(Variable):
entity = Person
label = "Old age security pension eligibility"
unit = CAD
documentation = "Eligibility for the OAS based on age and adult years resident in canada"
documentation = (
"Eligibility for the OAS based on age and adult years resident in canada"
)
definition_period = YEAR

def formula(person, period, parameters):
p = parameters(
period
).gov.cra.benefits.old_age_security_pension.eligibility
p = parameters(period).gov.cra.benefits.old_age_security_pension.eligibility
age_eligible = person("age", period) >= p.age.base
residency_eligible = (
person("adult_years_in_canada", period) >= p.residence.any
)
residency_eligible = person("adult_years_in_canada", period) >= p.residence.any
return age_eligible & residency_eligible
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def formula(person, period, parameters):
older_increase_age_threshold = p.eligibility.age.older_seniors_increase
eligible_older_increase = age >= older_increase_age_threshold
total_older_increase_factor = (
1
+ eligible_older_increase * p.amount.older_seniors_increase_factor
1 + eligible_older_increase * p.amount.older_seniors_increase_factor
)
base_amount = p.amount.base
# Your full base amount is your number of adult residence years divided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def formula(household, period, parameters):

# Step 1: Cap each child's expenses at their per-child maximum
expenses = person("childcare_expense", period)
max_per_child = person(
"child_care_expense_deduction_max_per_child", period
)
max_per_child = person("child_care_expense_deduction_max_per_child", period)
capped_expenses = min_(expenses, max_per_child)
total_household_expenses = household.sum(capped_expenses)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ def formula(person, period, parameters):
# Use person_index as a deterministic tiebreaker when two
# earners have equal income: lowest index claims.
person_idx = person("person_index", period)
min_idx_among_lowest = household.min(
where(is_lowest_earner, person_idx, inf)
)
min_idx_among_lowest = household.min(where(is_lowest_earner, person_idx, inf))
return is_lowest_earner & (person_idx == min_idx_among_lowest)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class canada_employment_amount(Variable):
reference = "https://www.canada.ca/en/revenue-agency/services/tax/individuals/topics/about-your-tax-return/tax-return/completing-a-tax-return/deductions-credits-expenses/line-31260-canada-employment-amount.html"

def formula(person, period, parameters):
p = parameters(
period
).gov.cra.tax.income.credits.canada_employment_amount
p = parameters(period).gov.cra.tax.income.credits.canada_employment_amount
# While the government website states that the Canada Employment Amount is designed
# to support workers with work-related expenses, those expenses are not part of the formula.
countable_income = add(person, period, p.income_sources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
class ClimateActionIncentiveCategory(Enum):
HEAD = "Head"
SPOUSE = "Spouse"
ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD = (
"Eldest child in single parent household"
)
ELDEST_CHILD_IN_SINGLE_PARENT_HOUSEHOLD = "Eldest child in single parent household"
OTHER_CHILD = "Other child"


Expand All @@ -22,9 +20,7 @@ def formula(person, period, parameters):
is_single_parent_household = person.household(
"climate_action_incentive_single_parent_household", period
)
eldest_child = person(
"is_eldest_child_for_climate_action_incentive", period
)
eldest_child = person("is_eldest_child_for_climate_action_incentive", period)
eldest_child_in_single_parent_household = (
is_single_parent_household & eldest_child
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class climate_action_incentive_single_parent_household(Variable):

def formula(household, period, parameters):
married = household("is_married", period)
cai_children = household(
"climate_action_incentive_dependant_children", period
)
cai_children = household("climate_action_incentive_dependant_children", period)
return ~married & (cai_children > 0)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
class is_child_for_climate_action_incentive(Variable):
value_type = bool
entity = Person
label = (
"Is a for the climate action incentive eligible child in a Household"
)
label = "Is a for the climate action incentive eligible child in a Household"
definition_period = YEAR
defined_for = "is_dependant"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class dtc_child_supplement(Variable):

def formula(person, period, parameters):
p = parameters(period).gov.cra.tax.income.credits.dtc
supplement_eligible = (
person("age", period) < p.supplement_ineligible_age
)
supplement_eligible = person("age", period) < p.supplement_ineligible_age
return p.child_supplement * supplement_eligible
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class gst_credit_person(Variable):

def formula(person, period, parameters):
category = person("gst_credit_category", period)
amounts = parameters(
period
).gov.cra.tax.income.credits.gst_credit.base_amounts
amounts = parameters(period).gov.cra.tax.income.credits.gst_credit.base_amounts
return amounts[category]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class gst_credit_single_parent_household(Variable):

def formula(household, period, parameters):
married = household("is_married", period)
gst_credit_children = household(
"gst_credit_dependant_children", period
)
gst_credit_children = household("gst_credit_dependant_children", period)
return ~married & (gst_credit_children > 0)
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ def formula(household, period, parameters):
"gst_credit_single_parent_household", period
)
net_income = household("household_net_income", period)
p = parameters(
period
).gov.cra.tax.income.credits.gst_credit.singles_boost
p = parameters(period).gov.cra.tax.income.credits.gst_credit.singles_boost
singles_phase_in = p.phase_in.calc(net_income)
singles_amount = min_(p.cap, singles_phase_in)
amount_if_single = where(
single_parent_household, p.cap, singles_amount
)
amount_if_single = where(single_parent_household, p.cap, singles_amount)
eligible = ~household("is_married", period)
return eligible * amount_if_single
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class is_child_for_gst_credit(Variable):
def formula(person, period, parameters):
dependant = person("is_dependant", period)
age = person("age", period)
adult_age = parameters(
period
).gov.cra.tax.income.credits.gst_credit.adult_age
adult_age = parameters(period).gov.cra.tax.income.credits.gst_credit.adult_age
return dependant & (age < adult_age)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class income_tax_before_refundable_credits(Variable):

def formula(person, period, parameters):
income_tax_before_credits = person("income_tax_before_credits", period)
non_refundable_tax_credits = person(
"non_refundable_tax_credits", period
)
non_refundable_tax_credits = person("non_refundable_tax_credits", period)
return max_(income_tax_before_credits - non_refundable_tax_credits, 0)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class acfb_base_component_base(Variable):
defined_for = ProvinceCode.AB

def formula(household, period, parameters):
p = parameters(
period
).gov.provinces.ab.benefits.acfb.base_component.base
p = parameters(period).gov.provinces.ab.benefits.acfb.base_component.base
eligible_children = household("acfb_eligible_children", period)
return (
(p.one_child * (eligible_children > 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class acfb_base_component_reduction(Variable):
defined_for = ProvinceCode.AB

def formula(household, period, parameters):
p = parameters(
period
).gov.provinces.ab.benefits.acfb.base_component.phase_out
p = parameters(period).gov.provinces.ab.benefits.acfb.base_component.phase_out
income = household("adjusted_family_net_income", period)
children = household("acfb_eligible_children", period)
return select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class ab_basic_personal_amount(Variable):
label = "Alberta basic personal amount"
unit = CAD
definition_period = YEAR
reference = "https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1ab/td1ab-23e.pdf"
reference = (
"https://www.canada.ca/content/dam/cra-arc/formspubs/pbg/td1ab/td1ab-23e.pdf"
)
defined_for = ProvinceCode.AB

def formula(person, period, parameters):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class ab_disability_credit(Variable):

def formula(person, period, parameters):
p = parameters(period).gov.provinces.ab.tax.income.credits.disability
additional_amount = person(
"ab_disability_credit_additional_amount", period
)
additional_amount = person("ab_disability_credit_additional_amount", period)
uncapped_amount = p.base + additional_amount
return min_(p.cap, uncapped_amount)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def formula(person, period, parameters):
childcare_expenses = person("care_expenses", period)
excess_childcare_expenses = max_(
0,
childcare_expenses
- p.additional_amount.childcare_expense_threshold,
childcare_expenses - p.additional_amount.childcare_expense_threshold,
)
age = person("age", period)
additional_amount_base = p.additional_amount.base.calc(age)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def formula(household, period, parameters):
income = household("adjusted_family_net_income", period)
household_size = household("household_size", period)
family_size_adjustment = (
max_(0, household_size - p.base_family_size)
* p.family_size_adjustment
max_(0, household_size - p.base_family_size) * p.family_size_adjustment
)
adjusted_income = max_(0, income - family_size_adjustment)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class bc_child_care_fee_reduction(Variable):
)

def formula(household, period, parameters):
p = parameters(
period
).gov.provinces.bc.benefits.child_care_fee_reduction
p = parameters(period).gov.provinces.bc.benefits.child_care_fee_reduction

person = household.members
age = person("age", period)
Expand Down
Loading
Loading