Guard QBI phaseout division when po_length is zero (refs #8216)#8217
Draft
vahid-ahmadi wants to merge 1 commit intomainfrom
Draft
Guard QBI phaseout division when po_length is zero (refs #8216)#8217vahid-ahmadi wants to merge 1 commit intomainfrom
vahid-ahmadi wants to merge 1 commit intomainfrom
Conversation
Refs #8216 The QBI phaseout in qbid_amount used unguarded division: reduction_rate = min_(1, (max_(0, taxinc_less_qbid - po_start)) / po_length) When the configured phaseout length is zero for a filing-status / year combination this produces RuntimeWarning: invalid value encountered in divide and NaN values that propagate through the deduction. Replace with np.divide(..., where=po_length > 0, out=ones) so that: - po_length > 0: behaviour unchanged. - po_length == 0: rows above the threshold are treated as fully phased out (reduction_rate = 1), rows at/below as no reduction. Eliminates the QBI source of the 84 divide warnings reported in #8216. Other suspected sources (labor-supply variables) already use guarded np.divide; if more warnings remain, run the suite with `-W error::RuntimeWarning` to surface them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8217 +/- ##
============================================
+ Coverage 71.72% 100.00% +28.27%
============================================
Files 4658 1 -4657
Lines 67710 50 -67660
Branches 341 0 -341
============================================
- Hits 48563 50 -48513
+ Misses 19140 0 -19140
+ Partials 7 0 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #8216 (84 divide warnings reported from
policyengine.py).Summary
The QBI phaseout in
qbid_amountused unguarded division:```python
reduction_rate = min_(1, (max_(0, taxinc_less_qbid - po_start)) / po_length)
```
When the configured phaseout length is zero for a filing-status / year combination this produces
RuntimeWarning: invalid value encountered in divideand NaN values that propagate through the deduction.Replaced with
np.divide(excess, po_length, where=po_length > 0, out=ones):po_length > 0— behaviour unchanged.po_length == 0— rows above the threshold are treated as fully phased out (reduction_rate = 1), rows at/below as no reduction.Scope
This fixes the QBI source of the 84 warnings reported in #8216. The labor-supply variables I inspected (
*_behavioral_response.py,behavioral_response_measurements.py) already use guardednp.divide/np.clip/ explicit masks, so they are likely not the source of the remaining warnings.If warnings persist after this lands, running the test suite with
-W error::RuntimeWarningwill surface any remaining unguarded divisions.Marked draft so reviewers can confirm:
po_length == 0(fully phased out above threshold, no phaseout at/below) matches what the IRS regulation intends — alternative interpretation could be "no phaseout regardless" (reduction_rate = 0).po_length == 0is currently exercised by tests (in which case existing tests would lock in the wrong behavior).Test plan
pytest -W error::RuntimeWarningno longer fails on QBI variables.qbid_amountfor a filing-status / year wherepo_length > 0to confirm no behavioral change in the common case.🤖 Generated with Claude Code