From cca52fee45bf39fa0b73133797458e610be0cb41 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Sat, 26 Oct 2024 12:37:39 -0400 Subject: [PATCH 1/3] Add 2021 and 2022 to test_tax_revenue.py test --- tests/test_tax_revenue.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_tax_revenue.py b/tests/test_tax_revenue.py index b2bbc8b5..a007ee69 100644 --- a/tests/test_tax_revenue.py +++ b/tests/test_tax_revenue.py @@ -6,11 +6,16 @@ import taxcalc as tc -FIRST_CYR = 2023 +FIRST_CYR = 2021 LAST_CYR = 2033 -RELTOL_ITAX = 0.10 -RELTOL_PTAX = 0.02 +DEFAULT_RELTOL_ITAX = 0.10 +RELTOL_ITAX = { +} +DEFAULT_RELTOL_PTAX = 0.02 +RELTOL_PTAX = { + 2021: 0.05, +} DUMP = False # True implies test always fails with complete output @@ -60,7 +65,7 @@ def test_tax_revenue( emsg = "" for year in range(FIRST_CYR, LAST_CYR + 1): reldiff = act_itax[year] / exp_itax[year] - 1 - same = abs(reldiff) < RELTOL_ITAX + same = abs(reldiff) < RELTOL_ITAX.get(year, DEFAULT_RELTOL_ITAX) if not same or DUMP: msg = ( f"\nITAX:cyr,act,exp,rdiff= {year} " @@ -68,7 +73,7 @@ def test_tax_revenue( ) emsg += msg reldiff = act_ptax[year] / exp_ptax[year] - 1 - same = abs(reldiff) < RELTOL_PTAX + same = abs(reldiff) < RELTOL_PTAX.get(year, DEFAULT_RELTOL_PTAX) if not same or DUMP: msg = ( f"\nPTAX:cyr,act,exp,rdiff= {year} " From afa73b83cf1ccacf5a27837e7692237b43d8e895 Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Sat, 26 Oct 2024 13:38:21 -0400 Subject: [PATCH 2/3] Add test_income_tax totests_misc.py test file --- pytest.ini | 1 + tests/test_misc.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/pytest.ini b/pytest.ini index e31fa6c8..0b46accd 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,3 +6,4 @@ markers = taxexp qbid taxexpdiffs + itax diff --git a/tests/test_misc.py b/tests/test_misc.py index 7e1bda11..7759202a 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2,6 +2,10 @@ Miscellaneous tests of tmd.csv variable weighted totals. """ +import pytest +import taxcalc as tc +from tmd.storage import STORAGE_FOLDER + def test_no_negative_weights(tmd_variables): assert tmd_variables.s006.min() >= 0, "Negative weights found" @@ -22,3 +26,31 @@ def test_population(tmd_variables): assert ( abs(population / 1e6 / 334.18 - 1) < 0.01 ), "Population not within 1% of 334.18 million" + + +@pytest.mark.itax +def test_income_tax(): + + def compare(name, act, exp, tol): + assert abs(act / exp - 1) < tol, \ + f"{name}:act,exp,tol= {act} {exp} {tol}" + + # use national tmd files to compute various 2021 income tax statistics + rec = tc.Records.tmd_constructor( + data_path=(STORAGE_FOLDER / "output" / "tmd.csv.gz"), + weights_path=(STORAGE_FOLDER / "output" / "tmd_weights.csv.gz"), + growfactors_path=(STORAGE_FOLDER / "output" / "tmd_growfactors.csv"), + exact_calculations=True, + ) + sim = tc.Calculator(policy=tc.Policy(), records=rec) + sim.advance_to_year(2021) + sim.calc_all() + wght = sim.array("s006") + agi = sim.array("c00100") + itax = sim.array("iitax") + # check various income tax statistics + compare("wght_sum", wght.sum()*1e-6, 184.0, 0.01) + hiagi = agi >= 1e6 + compare("wght_sum_hiagi", (wght*hiagi).sum()*1e-6, 0.875, 0.01) + compare("wght_itax_sum", (wght*itax).sum()*1e-9, 1591.0, 0.01) + compare("wght_itax_sum_hiagi", ((wght*itax)*hiagi).sum()*1e-9, 902.0, 0.01) From b528c05d011cf05db30b66e4c7250fb3066c5bba Mon Sep 17 00:00:00 2001 From: "martin.holmer@gmail.com" Date: Sat, 26 Oct 2024 14:20:52 -0400 Subject: [PATCH 3/3] black format changes --- tests/test_misc.py | 13 +++++++------ tests/test_tax_revenue.py | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 7759202a..9baddf9f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -32,8 +32,9 @@ def test_population(tmd_variables): def test_income_tax(): def compare(name, act, exp, tol): - assert abs(act / exp - 1) < tol, \ - f"{name}:act,exp,tol= {act} {exp} {tol}" + assert ( + abs(act / exp - 1) < tol + ), f"{name}:act,exp,tol= {act} {exp} {tol}" # use national tmd files to compute various 2021 income tax statistics rec = tc.Records.tmd_constructor( @@ -49,8 +50,8 @@ def compare(name, act, exp, tol): agi = sim.array("c00100") itax = sim.array("iitax") # check various income tax statistics - compare("wght_sum", wght.sum()*1e-6, 184.0, 0.01) + compare("wght_sum", wght.sum(), 184e6, 0.01) hiagi = agi >= 1e6 - compare("wght_sum_hiagi", (wght*hiagi).sum()*1e-6, 0.875, 0.01) - compare("wght_itax_sum", (wght*itax).sum()*1e-9, 1591.0, 0.01) - compare("wght_itax_sum_hiagi", ((wght*itax)*hiagi).sum()*1e-9, 902.0, 0.01) + compare("wght_sum_hiagi", (wght * hiagi).sum(), 0.875e6, 0.01) + compare("wght_itax_sum", (wght * itax).sum(), 1591e9, 0.01) + compare("wght_itax_sum_hiagi", ((wght * itax) * hiagi).sum(), 902e9, 0.01) diff --git a/tests/test_tax_revenue.py b/tests/test_tax_revenue.py index a007ee69..ea560d13 100644 --- a/tests/test_tax_revenue.py +++ b/tests/test_tax_revenue.py @@ -10,8 +10,7 @@ LAST_CYR = 2033 DEFAULT_RELTOL_ITAX = 0.10 -RELTOL_ITAX = { -} +RELTOL_ITAX = {} DEFAULT_RELTOL_PTAX = 0.02 RELTOL_PTAX = { 2021: 0.05,