Skip to content

Guard QBI phaseout division when po_length is zero (refs #8216)#8217

Draft
vahid-ahmadi wants to merge 1 commit intomainfrom
fix-qbi-divide-warnings
Draft

Guard QBI phaseout division when po_length is zero (refs #8216)#8217
vahid-ahmadi wants to merge 1 commit intomainfrom
fix-qbi-divide-warnings

Conversation

@vahid-ahmadi
Copy link
Copy Markdown
Collaborator

Refs #8216 (84 divide warnings reported from policyengine.py).

Summary

The QBI phaseout in qbid_amount used 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 divide and 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 guarded np.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::RuntimeWarning will surface any remaining unguarded divisions.

Marked draft so reviewers can confirm:

  1. The behavior I chose for 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).
  2. There are no parameter-tree configurations where po_length == 0 is currently exercised by tests (in which case existing tests would lock in the wrong behavior).

Test plan

  • Existing test suite passes.
  • pytest -W error::RuntimeWarning no longer fails on QBI variables.
  • Spot-check qbid_amount for a filing-status / year where po_length > 0 to confirm no behavioral change in the common case.

🤖 Generated with Claude Code

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
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cc5bd64) to head (fc6f081).
⚠️ Report is 105 commits behind head on main.

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (+28.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant