From 91d74a346c959328735969e72deafbe6d6c82f0b Mon Sep 17 00:00:00 2001 From: martinholmer Date: Sun, 30 Apr 2017 05:06:31 -0400 Subject: [PATCH 1/3] Add calculated-vars consistency test that fails --- taxcalc/tests/test_dropq.py | 2 -- taxcalc/tests/test_pufcsv.py | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/taxcalc/tests/test_dropq.py b/taxcalc/tests/test_dropq.py index 61765fb28..0fa92b886 100644 --- a/taxcalc/tests/test_dropq.py +++ b/taxcalc/tests/test_dropq.py @@ -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) @@ -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 diff --git a/taxcalc/tests/test_pufcsv.py b/taxcalc/tests/test_pufcsv.py index 6c6650408..7a796a6fc 100644 --- a/taxcalc/tests/test_pufcsv.py +++ b/taxcalc/tests/test_pufcsv.py @@ -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] From b31beed14673b9f2f988d4cd6f92a8712a1415b6 Mon Sep 17 00:00:00 2001 From: martinholmer Date: Sun, 30 Apr 2017 05:54:36 -0400 Subject: [PATCH 2/3] Add c21040 logic to Calculator calc_one_year method --- taxcalc/calculate.py | 5 +++++ taxcalc/validation/taxsim/d15.taxdiffs | 1 + 2 files changed, 6 insertions(+) diff --git a/taxcalc/calculate.py b/taxcalc/calculate.py index dbc36de85..9bd348d9b 100644 --- a/taxcalc/calculate.py +++ b/taxcalc/calculate.py @@ -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) @@ -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) diff --git a/taxcalc/validation/taxsim/d15.taxdiffs b/taxcalc/validation/taxsim/d15.taxdiffs index b5f09a677..ac2ce3a9e 100644 --- a/taxcalc/validation/taxsim/d15.taxdiffs +++ b/taxcalc/validation/taxsim/d15.taxdiffs @@ -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] From 07de1a9cc0ae97a718dfc5d9abb2a58fce53b5eb Mon Sep 17 00:00:00 2001 From: martinholmer Date: Sun, 30 Apr 2017 06:03:04 -0400 Subject: [PATCH 3/3] Suppress pylint warning in test_pufcsv.py --- taxcalc/tests/test_pufcsv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taxcalc/tests/test_pufcsv.py b/taxcalc/tests/test_pufcsv.py index 7a796a6fc..547df400c 100644 --- a/taxcalc/tests/test_pufcsv.py +++ b/taxcalc/tests/test_pufcsv.py @@ -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