-
Notifications
You must be signed in to change notification settings - Fork 201
New Jersey TANF earned income disregard #2222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Jersey TANF earned income disregard #2222
Conversation
Fixes PolicyEngine#2217 Co-authored-by: VioletChen0916 <VioletChen0916@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2222 +/- ##
=======================================
Coverage 97.18% 97.19%
=======================================
Files 1265 1269 +4
Lines 19997 20048 +51
Branches 163 163
=======================================
+ Hits 19434 19485 +51
Misses 537 537
Partials 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes PolicyEngine#2217 Co-authored-by: VioletChen0916 <VioletChen0916@users.noreply.github.com>
| person_enrolled_in_tanf_for_additional_months_with_Work_hours_below_20 = ( | ||
| months_enrolled_in_tanf > p.first_month_threshold | ||
| ) | ||
| if person_meet_higher_work_hours_threshold: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since if statements aren't vectorized, we have to use where and select statements instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Is there an example shows how to use "select" statement or how to use "where" and "select" to achieve the function of "if" there? Originally, we are using a nested where function, it is not so readable although it passes all the test. That's why we are trying to use "if" function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xudonglai0426 see my comment in the review below. Select is much cleaner than nested where (although both are vectorized). if will still achieve the same result, but is not vectorized so it will be much slower.
leogoldman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use variable names that aren't quite as long (but still descriptive) to make the code a bit easier to read. Also, avoid creating variables that are the opposite of existing variables (use the boolean inverse instead)
| person_meet_higher_work_hours_threshold = ( | ||
| weekly_hours_worked >= p.work_hours_threshold | ||
| ) | ||
| person_meet_lower_work_hours_threshold = ( | ||
| weekly_hours_worked < p.work_hours_threshold | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| person_meet_higher_work_hours_threshold = ( | |
| weekly_hours_worked >= p.work_hours_threshold | |
| ) | |
| person_meet_lower_work_hours_threshold = ( | |
| weekly_hours_worked < p.work_hours_threshold | |
| ) | |
| meets_hours_threshold = weekly_hours_worked >= p.work_hours_threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a variable that is the opposite of the first variable. If you need to check if the number of hours is less than the threshold, you can use ~meets_hours_threshold, flipping all the booleans
| result = 0 | ||
| # If applicant is enrolled in TANF for the first month, the earned income deduction is 100%. | ||
| result = where( | ||
| person_enrolled_in_tanf_for_first_month, | ||
| gross_earned_income | ||
| * (1 - p.higher_work_hours.first_month_percent), | ||
| result, | ||
| ) | ||
| # If applicant is enrolled in TANF for consecutive months with work hours over 20, the earned income deduction is 75%. | ||
| result = where( | ||
| ( | ||
| person_meet_higher_work_hours_threshold | ||
| and person_enrolled_in_tanf_for_consecutive_months_with_work_hours_over_20 | ||
| ), | ||
| gross_earned_income | ||
| * (1 - p.higher_work_hours.consecutive_month_percent), | ||
| result, | ||
| ) | ||
| # If applicant is enrolled in TANF for additional months with work hours over 20, the earned income deduction is 50%. | ||
| result = where( | ||
| person_enrolled_in_tanf_for_additional_months_with_work_hours_over_20, | ||
| gross_earned_income * (1 - p.higher_work_hours.additional_percent), | ||
| result, | ||
| ) | ||
| # If applicant is enrolled in TANF for additional months with work hours below 20, the earned income deduction is 50%. | ||
| result = where( | ||
| person_enrolled_in_tanf_for_additional_months_with_work_hours_below_20, | ||
| gross_earned_income * (1 - p.lower_work_hours.additional_percent), | ||
| result, | ||
| ) | ||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of how to use select():
policyengine-us/policyengine_us/variables/gov/states/nj/tax/income/nj_main_income_tax.py
Line 4 in 83b0d38
| class nj_main_income_tax(Variable): |
The function's first argument is a condition list, the second argument is the list of values to return if that condition is true, and the (optional) third argument is the value to return if none of them are true (by default this is zero). The function goes through the condition list and returns the corresponding value. For example, if the third condition is true, the third value in the return list would be returned.
Here, you would want something like
select( [ enrolled_in_tanf_first_month, meets_hours_threshold, ... ], [ gross_earned_income * ( 1-p.higher_work_hours.first_month_percent), gross_earned_income * (1 - p.higher_work_hours.consecutive_month_percent), ... ] )
You don't need to specify a default return value since you want zero anyway.
| person_enrolled_in_tanf_for_consecutive_months_with_work_hours_over_20 = ( | ||
| months_enrolled_in_tanf <= p.consecutive_month_threshold | ||
| and months_enrolled_in_tanf > p.first_month_threshold | ||
| and person_meet_higher_work_hours_threshold | ||
| ) | ||
| person_enrolled_in_tanf_for_additional_months_with_work_hours_over_20 = ( | ||
| months_enrolled_in_tanf > p.consecutive_month_threshold | ||
| and person_meet_higher_work_hours_threshold | ||
| ) | ||
| person_enrolled_in_tanf_for_additional_months_with_work_hours_below_20 = ( | ||
| months_enrolled_in_tanf > p.first_month_threshold | ||
| and person_meet_lower_work_hours_threshold | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you want element-wise boolean operations, make sure you use & instead of and.
7926ec9 to
d2543dc
Compare
|
Consolidated into #7123 |
Fixes #2217
Co-authored-by: VioletChen0916 VioletChen0916@users.noreply.github.com
🤖 Generated by Copilot at 268a820
Summary
✨📄🛠️
This pull request adds the New Jersey TANF earned income disregards as a new feature to the policy engine. It introduces new parameters, variables, and tests for calculating the countable earned income for TANF households in New Jersey, based on the state's administrative code. It also adds some auxiliary variables for tracking the months enrolled in TANF and the weekly hours worked by TANF recipients.
Walkthrough
nj_tanf_countable_earned_incomethat calculates the amount of earned income that is considered for TANF eligibility and benefit amount, using the new parameters and the existinggross_earned_incomevariable (link)months_enrolled_in_tanfandhours_workedthat record the duration and intensity of work for TANF recipients, and derive a new variableweekly_hours_workedfrom the latter (link, link, link)nj_tanf_countable_earned_incomevariable, covering different scenarios of income, enrollment, and work hours, and the expected output according to the New Jersey rules (link)