Skip to content

Commit

Permalink
Fix divide-by-zero problem in behavior.py
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Sep 20, 2017
1 parent b21e47a commit a3d00c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions taxcalc/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ def response(calc_x, calc_y):
else:
if calc_y.behavior.BE_subinc_wrt_earnings:
# proportional change in after-tax income
pch = (calc_y.records.aftertax_income /
calc_x.records.aftertax_income) - 1.
with np.errstate(invalid='ignore'):
pch = np.where(calc_x.records.aftertax_income > 0.,
(calc_y.records.aftertax_income /
calc_x.records.aftertax_income) - 1.,
0.)
inc = calc_y.behavior.BE_inc * pch * calc_x.records.e00200
else:
# dollar change in after-tax income
Expand Down
7 changes: 4 additions & 3 deletions taxcalc/tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def test_behavioral_response_Calculator(cps_subsample):
'_BE_subinc_wrt_earnings': [True]}}
behavior_y.update_behavior(behavior1)
assert behavior_y.has_response() is True
assert abs(behavior_y.BE_sub - 0.3) < 1e-9
assert abs(behavior_y.BE_inc - -0.1) < 1e-9
assert abs(behavior_y.BE_cg - 0.0) < 1e-9
epsilon = 1e-9
assert abs(behavior_y.BE_sub - 0.3) < epsilon
assert abs(behavior_y.BE_inc - -0.1) < epsilon
assert abs(behavior_y.BE_cg - 0.0) < epsilon
calc_y_behavior1 = Behavior.response(calc_x, calc_y)
behavior2 = {year: {'_BE_sub': [0.5], '_BE_cg': [-0.8]}}
behavior_y.update_behavior(behavior2)
Expand Down

0 comments on commit a3d00c3

Please sign in to comment.