Skip to content

Commit

Permalink
Merge pull request #1327 from martinholmer/c21040-logic
Browse files Browse the repository at this point in the history
Fix c21040 logic and add several output consistency tests
  • Loading branch information
martinholmer authored Apr 30, 2017
2 parents 953093b + 07de1a9 commit ba4fe85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions taxcalc/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,17 @@ def calc_one_year(self, zero_out_calc_vars=False):
std = copy.deepcopy(self.records.standard)
item = copy.deepcopy(self.records.c04470)
item_no_limit = copy.deepcopy(self.records.c21060)
item_phaseout = copy.deepcopy(self.records.c21040)
self.records.c04470 = np.zeros(self.records.dim)
self.records.c21060 = np.zeros(self.records.dim)
self.records.c21040 = np.zeros(self.records.dim)
self.TaxInc_to_AMT()
std_taxes = copy.deepcopy(self.records.c05800)
# Set standard deduction to zero, calculate taxes w/o
# standard deduction, and store AMT + Regular Tax
self.records.standard = np.zeros(self.records.dim)
self.records.c21060 = item_no_limit
self.records.c21040 = item_phaseout
self.records.c04470 = item
self.TaxInc_to_AMT()
item_taxes = copy.deepcopy(self.records.c05800)
Expand All @@ -175,6 +178,8 @@ def calc_one_year(self, zero_out_calc_vars=False):
item, 0.)
self.records.c21060[:] = np.where(item_taxes < std_taxes,
item_no_limit, 0.)
self.records.c21040[:] = np.where(item_taxes < std_taxes,
item_phaseout, 0.)
# Calculate taxes with optimal itemized deduction
self.TaxInc_to_AMT()
F2441(self.policy, self.records)
Expand Down
2 changes: 0 additions & 2 deletions taxcalc/tests/test_dropq.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def puf_path(tests_path):
return os.path.join(tests_path, '..', '..', 'puf.csv')


@pytest.mark.one
def test_check_user_mods_errors():
check_user_mods(USER_MODS)
seed1 = random_seed(USER_MODS)
Expand Down Expand Up @@ -472,7 +471,6 @@ def test_create_dropq_diff_table_groupby_options(groupby, res_col,
wsum=dec_sum)


@pytest.mark.one
@pytest.mark.requires_pufcsv
def test_with_pufcsv(puf_path): # pylint: disable=redefined-outer-name
# pylint: disable=too-many-locals
Expand Down
10 changes: 9 additions & 1 deletion taxcalc/tests/test_pufcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_mtr(tests_path, puf_path):
sample input from the puf.csv file and writing output to a string,
which is then compared for differences with EXPECTED_MTR_RESULTS.
"""
# pylint: disable=too-many-locals
# pylint: disable=too-many-locals,too-many-statements
# for fixture args, pylint: disable=redefined-outer-name
assert len(PTAX_MTR_BIN_EDGES) == len(ITAX_MTR_BIN_EDGES)
# construct actual results string, res
Expand Down Expand Up @@ -194,6 +194,14 @@ def test_mtr(tests_path, puf_path):
negative_finite_diff=MTR_NEG_DIFF,
zero_out_calculated_vars=zero_out,
wrt_full_compensation=False)
if zero_out:
# check that calculated variables are consistent
crs = calc.records
assert np.allclose(crs.iitax + crs.payrolltax, crs.combined)
assert np.allclose(crs.ptax_was + crs.setax + crs.ptax_amc,
crs.payrolltax)
assert np.allclose(crs.c21060 - crs.c21040, crs.c04470)
assert np.allclose(crs.taxbc + crs.c09600, crs.c05800)
if var_str == 'e00200s':
# only MARS==2 filing units have valid MTR values
mtr_ptax = mtr_ptax[calc.records.MARS == 2]
Expand Down
1 change: 1 addition & 0 deletions taxcalc/validation/taxsim/d15.taxdiffs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 7 1 1 0.01 [11965]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 9 4 0 0.90 [16808]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 14 604 604 -1.28 [2349]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 15 604 604 1.28 [56716]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 16 817 1 -9925.50 [53539]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 17 146 0 25000.00 [66962]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 18 750 604 -12400.00 [66962]
TAXDIFF:ovar,#diffs,#smdiffs,maxdiff[id]= 19 1382 1236 -1415.00 [41106]
Expand Down

0 comments on commit ba4fe85

Please sign in to comment.