Skip to content

Commit

Permalink
Merge pull request #2217 from martinholmer/fix-rtr-test
Browse files Browse the repository at this point in the history
Strengthen testing of 2017_law.json and TCJA.json reform files
  • Loading branch information
martinholmer authored Feb 5, 2019
2 parents f3a7947 + c97d49f commit 3f9f024
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 139 deletions.
1 change: 1 addition & 0 deletions read-the-docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __getattr__(cls, name):
else:
return Mock()


MOCK_MODULES = ['numba', 'numba.jit', 'numba.vectorize', 'numba.guvectorize']
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

Expand Down
11 changes: 10 additions & 1 deletion taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def set_default_vals(self, known_years=999999):
"""
Called by initialize method and from some subclass methods.
"""
if isinstance(known_years, int):
known_years_is_int = True
elif isinstance(known_years, dict):
known_years_is_int = False
else:
raise ValueError('known_years is neither an int nor a dict')
if hasattr(self, '_vals'):
for name, data in self._vals.items():
intg_val = data.get('integer_value')
Expand All @@ -69,7 +75,10 @@ def set_default_vals(self, known_years=999999):
if cpi_inflated:
index_rates = self.indexing_rates(name)
if name != '_SS_Earnings_c':
values = values[:known_years]
if known_years_is_int:
values = values[:known_years]
else:
values = values[:known_years[name]]
else:
index_rates = None
setattr(self, name,
Expand Down
28 changes: 24 additions & 4 deletions taxcalc/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,14 @@ def _apply_reform_cpi_offset(self, reform):
Call this method ONLY if _cpi_offset_in_reform returns True.
Apply CPI offset to inflation rates and
revert indexed parameter values in preparation for re-indexing.
Also, return known_years which is
(first cpi_offset year - start year + 1).
Also, return known_years which is dictionary with indexed policy
parameter names as keys and known_years as values. For indexed
parameters included in reform, the known_years value is equal to:
(first_cpi_offset_year - start_year + 1). For indexed parameters
not included in reform, the known_years value is equal to:
(max(first_cpi_offset_year, Policy.LAST_KNOWN_YEAR) - start_year + 1).
"""
# pylint: disable=too-many-branches
# extrapolate cpi_offset reform
self.set_year(self.start_year)
first_cpi_offset_year = 0
Expand All @@ -422,8 +427,23 @@ def _apply_reform_cpi_offset(self, reform):
for name in self._vals.keys():
if self._vals[name]['cpi_inflated']:
setattr(self, name, self._vals[name]['value'])
# return known_years
return first_cpi_offset_year - self.start_year + 1
# construct and return known_years dictionary
known_years = dict()
kyrs_in_reform = (first_cpi_offset_year -
self.start_year + 1)
kyrs_not_in_reform = (max(first_cpi_offset_year,
Policy.LAST_KNOWN_YEAR) -
self.start_year + 1)
for year in sorted(reform.keys()):
for name in reform[year]:
if self._vals[name]['cpi_inflated']:
if name not in known_years:
known_years[name] = kyrs_in_reform
for name in self._vals.keys():
if self._vals[name]['cpi_inflated']:
if name not in known_years:
known_years[name] = kyrs_not_in_reform
return known_years

def _validate_parameter_names_types(self, reform):
"""
Expand Down
16 changes: 8 additions & 8 deletions taxcalc/policy_current_law.json
Original file line number Diff line number Diff line change
Expand Up @@ -4245,14 +4245,14 @@
[413200.00, 464850.00, 232425.00, 439000.00, 464850.00],
[415050.00, 466950.00, 233475.00, 441000.00, 466950.00],
[418400.00, 470700.00, 235350.00, 444550.00, 470700.00],
[500000.0, 600000.0, 300000.0, 500000.0, 500000.0],
[511450.0, 613740.0, 306870.0, 511450.0, 511450.0],
[521627.86, 625953.43, 312976.71, 521627.86, 521627.86],
[533312.32, 639974.78, 319987.39, 533312.32, 533312.32],
[545418.51, 654502.21, 327251.11, 545418.51, 545418.51],
[557581.34, 669097.61, 334548.8, 557581.34, 557581.34],
[569736.61, 683683.94, 341841.97, 569736.61, 569736.61],
[581985.95, 698383.14, 349191.57, 581985.95, 581985.95],
[500000.0, 600000.0, 300000.0, 500000.0, 600000.0],
[511450.0, 613740.0, 306870.0, 511450.0, 613740.0],
[521627.86, 625953.43, 312976.71, 521627.86, 625953.43],
[533312.32, 639974.78, 319987.39, 533312.32, 639974.78],
[545418.51, 654502.21, 327251.11, 545418.51, 654502.21],
[557581.34, 669097.61, 334548.8, 557581.34, 669097.61],
[569736.61, 683683.94, 341841.97, 569736.61, 683683.94],
[581985.95, 698383.14, 349191.57, 581985.95, 698383.14],
[506680.0, 570015.0, 285008.0, 538348.0, 570015.0]],
"range": {"min": "_PT_brk5", "max": "_PT_brk7"},
"out_of_range_minmsg": "for _PT_brk5",
Expand Down
69 changes: 45 additions & 24 deletions taxcalc/reforms/2017_law.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,79 @@
// Reform_Baseline: current_law_policy.json
// Reform_Description:
// - Switch to unchained CPI-U calculation of 2018+ policy parameter values (0)
// - Set pre-TCJA tax rates (1)
// - Set pre-TCJA tax rates and brackets (1)
// - Set pre-TCJA handling of pass-through income (2)
// - Set pre-TCJA child tax credit (CTC) and additional CTC policy (3)
// - Set pre-TCJA dependent credit policy parameters (4)
// - Set pre-TCJA above the line deduction policy (5)
// - Set pre-TCJA itemized deduction policy (6)
// - Set pre-TCJA standard deduction and personal exemption (3)
// - Set pre-TCJA child tax credit (CTC) and additional CTC policy (4)
// - Set pre-TCJA dependent credit policy parameters (5)
// - Set pre-TCJA AMT exemption parameters (6)
// - Set pre-TCJA above the line deduction policy (7)
// - Set pre-TCJA itemized deduction policy (8)
// Reform_Parameter_Map:
// - 0: _cpi_offset
// - 1: _II_rt? and _PT_rt?
// - 1: _II_rt?/_II_brk? and _PT_rt?/_PT_brk?
// - 2: four _PT_excl_* parameters
// - 3: _CTC_c and _CTC_ps and _ACTC_Income_thd
// - 4: three different _DependentCredit_* parameters
// - 5: three _ALD_* parameters
// - 6: seven different _ID_* parameters
// - 3: _STD and _II_em parameters
// - 4: _CTC_c and _CTC_ps and _ACTC_Income_thd
// - 5: three different _DependentCredit_* parameters
// - 6: three different _AMT_em* parameters
// - 7: three _ALD_* parameters
// - 8: seven different _ID_* parameters
// NOTE: this reform projects pre-TCJA 2017 parameter values forward using the
// unchained CPI-U price index.
{
"policy": {
"_cpi_offset": {"2017": [0.0025]},
"_II_rt1": {"2018": [0.10]},
"_II_brk1": {"2017": [[9325, 18650, 9325, 13350, 18650]]},
"_II_rt2": {"2018": [0.15]},
"_II_brk2": {"2017": [[37950, 75900, 37950, 50800, 75900]]},
"_II_rt3": {"2018": [0.25]},
"_II_brk3": {"2017": [[91900, 153100, 76550, 131200, 153100]]},
"_II_rt4": {"2018": [0.28]},
"_II_brk4": {"2017": [[191650, 233350, 116675, 212500, 233350]]},
"_II_rt5": {"2018": [0.33]},
"_II_brk5": {"2017": [[416700, 416700, 208350, 416700, 416700]]},
"_II_rt6": {"2018": [0.35]},
"_II_brk6": {"2017": [[418400, 470700, 235350, 444550, 470700]]},
"_II_rt7": {"2018": [0.396]},
"_PT_rt1": {"2018": [0.10]},
"_PT_brk1": {"2017": [[9325, 18650, 9325, 13350, 18650]]},
"_PT_rt2": {"2018": [0.15]},
"_PT_brk2": {"2017": [[37950, 75900, 37950, 50800, 75900]]},
"_PT_rt3": {"2018": [0.25]},
"_PT_brk3": {"2017": [[91900, 153100, 76550, 131200, 153100]]},
"_PT_rt4": {"2018": [0.28]},
"_PT_brk4": {"2017": [[191650, 233350, 116675, 212500, 233350]]},
"_PT_rt5": {"2018": [0.33]},
"_PT_brk5": {"2017": [[416700, 416700, 208350, 416700, 416700]]},
"_PT_rt6": {"2018": [0.35]},
"_PT_brk6": {"2017": [[418400, 470700, 235350, 444550, 470700]]},
"_PT_rt7": {"2018": [0.396]},
"_PT_excl_rt": {"2018": [0.0]},
"_PT_excl_rt": {"2018": [0]},
"_PT_excl_wagelim_rt": {"2018": [9e99]},
"_PT_excl_wagelim_thd": {"2018": [[0.0, 0.0, 0.0, 0.0, 0.0]]},
"_PT_excl_wagelim_prt": {"2018": [[0.0, 0.0, 0.0, 0.0, 0.0]]},
"_CTC_c": {"2018": [1000.0]},
"_CTC_ps": {"2018": [[75000.0, 110000.0, 55000.0, 75000.0, 75000.0]]},
"_ACTC_Income_thd": {"2018": [3000.0]},
"_DependentCredit_Child_c": {"2018": [0.0]},
"_DependentCredit_Nonchild_c": {"2018": [0.0]},
"_PT_excl_wagelim_thd": {"2018": [[0, 0, 0, 0, 0]]},
"_PT_excl_wagelim_prt": {"2018": [[0, 0, 0, 0, 0]]},
"_STD": {"2017": [[6350, 12700, 6350, 9350, 12700]]},
"_II_em": {"2017": [4050]},
"_CTC_c": {"2018": [1000]},
"_CTC_ps": {"2018": [[75000, 110000, 55000, 75000, 75000]]},
"_ACTC_Income_thd": {"2018": [3000]},
"_DependentCredit_Child_c": {"2018": [0]},
"_DependentCredit_Nonchild_c": {"2018": [0]},
"_DependentCredit_before_CTC": {"2018": [false]},
"_ALD_AlimonyPaid_hc": {"2019": [0.0]},
"_ALD_AlimonyReceived_hc": {"2019": [1.0]},
"_ALD_DomesticProduction_hc": {"2018": [0.0]},
"_AMT_em": {"2017": [[54300, 84500, 42250, 54300, 84500]]},
"_AMT_em_ps": {"2017": [[120700, 160900, 80450, 120700, 160900]]},
"_AMT_em_pe": {"2017": [249450]},
"_ALD_AlimonyPaid_hc": {"2019": [0]},
"_ALD_AlimonyReceived_hc": {"2019": [1]},
"_ALD_DomesticProduction_hc": {"2018": [0]},
"_ID_prt": {"2018": [0.03]},
"_ID_crt": {"2018": [0.8]},
"_ID_crt": {"2018": [0.80]},
"_ID_Charity_crt_all": {"2018": [0.5]},
"_ID_Casualty_hc": {"2018": [0.0]},
"_ID_Casualty_hc": {"2018": [0]},
"_ID_AllTaxes_c": {"2018": [[9e99, 9e99, 9e99, 9e99, 9e99]]},
"_ID_Miscellaneous_hc": {"2018": [0.0]},
"_ID_Miscellaneous_hc": {"2018": [0]},
"_ID_Medical_frt": {"2017": [0.1]}
}
}
31 changes: 17 additions & 14 deletions taxcalc/reforms/TCJA.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Title: Tax Cuts and Jobs Act, final version
// Reform_File_Author: Cody Kallen
// Reform_Reference: http://docs.house.gov/billsthisweek/20171218/CRPT-115HRPT-466.pdf
// Reform_File_Author: Cody Kallen (with updates by Martin Holmer)
// Reform_Reference: 2018 IRS forms and this URL:
// http://docs.house.gov/billsthisweek/20171218/CRPT-115HRPT-466.pdf
// Reform_Baseline: 2017_law.json
// Reform_Description:
// - New personal income tax schedule (regular/non-AMT/non-pass-through) (1)
// - New pass-through income tax schedule (2)
// - New standard deductions (3)
// - Repeal personal exemption (4)
// - Modification to child tax credit, nonrefundable dependent credits (5)
// - Modification of Alternative Minimum Tax exemption (6)
// - Modification of Alternative Minimum Tax exemption parameters (6)
// - Changes to certain above the line deductions (7)
// - Changes to itemized deductions (8)
// - Switch to chained CPI from CPI-U for tax parameter adjustment (9)
Expand All @@ -18,16 +19,16 @@
// - 3: _STD (can safely ignore WARNINGs about 2026+ values)
// - 4: _II_em
// - 5: _DependentCredit_*, _CTC_c, _CTC_ps, _ACTC_Income_thd
// - 6: _AMT_rt*
// - 6: _AMT_em*
// - 7: _ALD_*
// - 8: _ID_* (can safely ignore WARNINGs about values for several parameters)
// - 9: _cpi_offset
// Note: _II_rt*, _PT_rt*, _STD and _II_em are rounded to the nearest integer value.
// Note: _II_brk*, _PT_brk*, _STD, _II_em are rounded to nearest integer value
{
"policy": {
"_II_rt1":
{"2018": [0.1],
"2026": [0.1]},
{"2018": [0.10],
"2026": [0.10]},
"_II_rt2":
{"2018": [0.12],
"2026": [0.15]},
Expand Down Expand Up @@ -62,11 +63,11 @@
{"2018": [[200000, 400000, 200000, 200000, 400000]],
"2026": [[502356, 502356, 251178, 502356, 502356]]},
"_II_brk6":
{"2018": [[500000, 600000, 300000, 500000, 500000]],
{"2018": [[500000, 600000, 300000, 500000, 600000]],
"2026": [[504406 ,567457, 283728, 535931, 567457]]},
"_PT_rt1":
{"2018": [0.1],
"2026": [0.1]},
{"2018": [0.10],
"2026": [0.10]},
"_PT_rt2":
{"2018": [0.12],
"2026": [0.15]},
Expand Down Expand Up @@ -101,7 +102,7 @@
{"2018": [[200000, 400000, 200000, 200000, 400000]],
"2026": [[502356, 502356, 251178, 502356, 502356]]},
"_PT_brk6":
{"2018": [[500000, 600000, 300000, 500000, 500000]],
{"2018": [[500000, 600000, 300000, 500000, 600000]],
"2026": [[504406, 567457, 283728, 535931, 567457]]},
"_PT_excl_rt":
{"2018": [0.2],
Expand Down Expand Up @@ -148,6 +149,8 @@
"_AMT_em_ps":
{"2018": [[500000, 1000000, 500000, 500000, 1000000]],
"2026": [[145511, 193974, 96987, 145511, 193974]]},
"_AMT_em_pe":
{"2018": [718800]},
"_ALD_DomesticProduction_hc":
{"2018": [1],
"2026": [0]},
Expand All @@ -161,10 +164,10 @@
{"2018": [[250000, 500000, 250000, 250000, 500000]],
"2026": [[9e99, 9e99, 9e99, 9e99, 9e99]]},
"_ID_prt":
{"2018": [0],
{"2018": [0.00],
"2026": [0.03]},
"_ID_crt":
{"2018": [1],
{"2018": [1.0],
"2026": [0.8]},
"_ID_Charity_crt_all":
{"2018": [0.6],
Expand All @@ -180,7 +183,7 @@
"2026": [0]},
"_ID_Medical_frt":
{"2017": [0.075],
"2019": [0.1]},
"2019": [0.100]},
"_cpi_offset":
{"2017": [-0.0025]}
}
Expand Down
Loading

0 comments on commit 3f9f024

Please sign in to comment.