Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Calculator.param method as Calculator.policy_param #1915

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions taxcalc/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def array_len(self):
"""
return self.__records.array_length

def param(self, param_name, param_value=None):
def policy_param(self, param_name, param_value=None):
"""
If param_value is None, return named parameter in
embedded Policy object.
Expand Down Expand Up @@ -687,10 +687,10 @@ def mtr(self, variable_str='e00200p',
mtr_on_earnings = (variable_str == 'e00200p' or
variable_str == 'e00200s')
if wrt_full_compensation and mtr_on_earnings:
adj = np.where(variable < self.param('SS_Earnings_c'),
0.5 * (self.param('FICA_ss_trt') +
self.param('FICA_mc_trt')),
0.5 * self.param('FICA_mc_trt'))
adj = np.where(variable < self.policy_param('SS_Earnings_c'),
0.5 * (self.policy_param('FICA_ss_trt') +
self.policy_param('FICA_mc_trt')),
0.5 * self.policy_param('FICA_mc_trt'))
else:
adj = 0.0
# compute marginal tax rates
Expand Down
94 changes: 49 additions & 45 deletions taxcalc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def BenefitPrograms(calc):
"""
# zero out benefits delivered by repealed programs
zero = np.zeros(calc.array_len)
if calc.param('BEN_housing_repeal'):
if calc.policy_param('BEN_housing_repeal'):
calc.array('housing_ben', zero)
if calc.param('BEN_ssi_repeal'):
if calc.policy_param('BEN_ssi_repeal'):
calc.array('ssi_ben', zero)
if calc.param('BEN_snap_repeal'):
if calc.policy_param('BEN_snap_repeal'):
calc.array('snap_ben', zero)
if calc.param('BEN_tanf_repeal'):
if calc.policy_param('BEN_tanf_repeal'):
calc.array('tanf_ben', zero)
if calc.param('BEN_vet_repeal'):
if calc.policy_param('BEN_vet_repeal'):
calc.array('vet_ben', zero)
if calc.param('BEN_wic_repeal'):
if calc.policy_param('BEN_wic_repeal'):
calc.array('wic_ben', zero)
if calc.param('BEN_mcare_repeal'):
if calc.policy_param('BEN_mcare_repeal'):
calc.array('mcare_ben', zero)
if calc.param('BEN_mcaid_repeal'):
if calc.policy_param('BEN_mcaid_repeal'):
calc.array('mcaid_ben', zero)
if calc.param('BEN_oasdi_repeal'):
if calc.policy_param('BEN_oasdi_repeal'):
calc.array('e02400', zero)
if calc.param('BEN_ui_repeal'):
if calc.policy_param('BEN_ui_repeal'):
calc.array('e02300', zero)
if calc.param('BEN_other_repeal'):
if calc.policy_param('BEN_other_repeal'):
calc.array('other_ben', zero)
# calculate government cost of all benefits
cost = np.array(
Expand Down Expand Up @@ -1677,19 +1677,19 @@ def ComputeBenefit(calc, ID_switch):
# the types of itemized deductions covered under the BenefitSurtax
no_ID_calc = copy.deepcopy(calc)
if ID_switch[0]:
no_ID_calc.param('ID_Medical_hc', 1.)
no_ID_calc.policy_param('ID_Medical_hc', 1.)
if ID_switch[1]:
no_ID_calc.param('ID_StateLocalTax_hc', 1.)
no_ID_calc.policy_param('ID_StateLocalTax_hc', 1.)
if ID_switch[2]:
no_ID_calc.param('ID_RealEstate_hc', 1.)
no_ID_calc.policy_param('ID_RealEstate_hc', 1.)
if ID_switch[3]:
no_ID_calc.param('ID_Casualty_hc', 1.)
no_ID_calc.policy_param('ID_Casualty_hc', 1.)
if ID_switch[4]:
no_ID_calc.param('ID_Miscellaneous_hc', 1.)
no_ID_calc.policy_param('ID_Miscellaneous_hc', 1.)
if ID_switch[5]:
no_ID_calc.param('ID_InterestPaid_hc', 1.)
no_ID_calc.policy_param('ID_InterestPaid_hc', 1.)
if ID_switch[6]:
no_ID_calc.param('ID_Charity_hc', 1.)
no_ID_calc.policy_param('ID_Charity_hc', 1.)
no_ID_calc._calc_one_year() # pylint: disable=protected-access
diff_iitax = no_ID_calc.array('iitax') - calc.array('iitax')
benefit = np.where(diff_iitax > 0., diff_iitax, 0.)
Expand All @@ -1701,12 +1701,15 @@ def BenefitSurtax(calc):
Computes itemized-deduction-benefit surtax and adds the surtax amount
to income tax, combined tax, and surtax liabilities.
"""
if calc.param('ID_BenefitSurtax_crt') != 1.:
ben = ComputeBenefit(calc, calc.param('ID_BenefitSurtax_Switch'))
ben_deduct = calc.param('ID_BenefitSurtax_crt') * calc.array('c00100')
ben_exempt = calc.param('ID_BenefitSurtax_em')[calc.array('MARS') - 1]
if calc.policy_param('ID_BenefitSurtax_crt') != 1.:
benefit_surtax_switch = calc.policy_param('ID_BenefitSurtax_Switch')
ben = ComputeBenefit(calc, benefit_surtax_switch)
agi = calc.array('c00100')
ben_deduct = calc.policy_param('ID_BenefitSurtax_crt') * agi
ben_exempt_array = calc.policy_param('ID_BenefitSurtax_em')
ben_exempt = ben_exempt_array[calc.array('MARS') - 1]
ben_dedem = ben_deduct + ben_exempt
ben_surtax = (calc.param('ID_BenefitSurtax_trt') *
ben_surtax = (calc.policy_param('ID_BenefitSurtax_trt') *
np.where(ben > ben_dedem, ben - ben_dedem, 0.))
# add ben_surtax to income & combined taxes and to surtax subtotal
calc.incarray('iitax', ben_surtax)
Expand All @@ -1719,31 +1722,32 @@ def BenefitLimitation(calc):
Limits the benefits of select itemized deductions to a fraction of
deductible expenses.
"""
if calc.param('ID_BenefitCap_rt') != 1.:
if calc.policy_param('ID_BenefitCap_rt') != 1.:
# pylint: disable=no-member
# (above pylint comment eliminates bogus np.maximum warnings)
benefit = ComputeBenefit(calc, calc.param('ID_BenefitCap_Switch'))
# Calculate total deductible expenses under the cap.
deductible_expenses = 0.
if calc.param('ID_BenefitCap_Switch')[0]: # Medical
deductible_expenses += calc.array('c17000')
if calc.param('ID_BenefitCap_Switch')[1]: # StateLocal
deductible_expenses += ((1. - calc.param('ID_StateLocalTax_hc')) *
np.maximum(calc.array('e18400_capped'),
0.))
if calc.param('ID_BenefitCap_Switch')[2]:
deductible_expenses += ((1. - calc.param('ID_RealEstate_hc')) *
calc.array('e18500_capped'))
if calc.param('ID_BenefitCap_Switch')[3]: # Casualty
deductible_expenses += calc.array('c20500')
if calc.param('ID_BenefitCap_Switch')[4]: # Miscellaneous
deductible_expenses += calc.array('c20800')
if calc.param('ID_BenefitCap_Switch')[5]: # Mortgage and interest paid
deductible_expenses += calc.array('c19200')
if calc.param('ID_BenefitCap_Switch')[6]: # Charity
deductible_expenses += calc.array('c19700')
benefit = ComputeBenefit(calc,
calc.policy_param('ID_BenefitCap_Switch'))
# Calculate total deductible expenses under the cap
deduct_exps = 0.
if calc.policy_param('ID_BenefitCap_Switch')[0]: # medical
deduct_exps += calc.array('c17000')
if calc.policy_param('ID_BenefitCap_Switch')[1]: # statelocal
one_minus_hc = 1. - calc.policy_param('ID_StateLocalTax_hc')
deduct_exps += (one_minus_hc *
np.maximum(calc.array('e18400_capped'), 0.))
if calc.policy_param('ID_BenefitCap_Switch')[2]: # realestate
one_minus_hc = 1. - calc.policy_param('ID_RealEstate_hc')
deduct_exps += one_minus_hc * calc.array('e18500_capped')
if calc.policy_param('ID_BenefitCap_Switch')[3]: # casualty
deduct_exps += calc.array('c20500')
if calc.policy_param('ID_BenefitCap_Switch')[4]: # misc
deduct_exps += calc.array('c20800')
if calc.policy_param('ID_BenefitCap_Switch')[5]: # interest
deduct_exps += calc.array('c19200')
if calc.policy_param('ID_BenefitCap_Switch')[6]: # charity
deduct_exps += calc.array('c19700')
# Calculate cap value for itemized deductions
benefit_limit = deductible_expenses * calc.param('ID_BenefitCap_rt')
benefit_limit = deduct_exps * calc.policy_param('ID_BenefitCap_rt')
# Add the difference between the actual benefit and capped benefit
# to income tax and combined tax liabilities.
excess_benefit = np.maximum(benefit - benefit_limit, 0)
Expand Down
18 changes: 9 additions & 9 deletions taxcalc/tests/test_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def test_make_calculator_with_policy_reform(cps_subsample):
calc = Calculator(policy=pol, records=rec)
# check that Policy object embedded in Calculator object is correct
assert calc.current_year == year
assert calc.param('II_em') == 4000
assert np.allclose(calc.param('_II_em'),
assert calc.policy_param('II_em') == 4000
assert np.allclose(calc.policy_param('_II_em'),
np.array([4000] * Policy.DEFAULT_NUM_YEARS))
exp_STD_Aged = [[1600, 1300, 1300,
1600, 1600]] * Policy.DEFAULT_NUM_YEARS
assert np.allclose(calc.param('_STD_Aged'),
assert np.allclose(calc.policy_param('_STD_Aged'),
np.array(exp_STD_Aged))
assert np.allclose(calc.param('STD_Aged'),
assert np.allclose(calc.policy_param('STD_Aged'),
np.array([1600, 1300, 1300, 1600, 1600]))


Expand All @@ -122,14 +122,14 @@ def test_make_calculator_with_multiyear_reform(cps_subsample):
# check that Policy object embedded in Calculator object is correct
assert pol.num_years == Policy.DEFAULT_NUM_YEARS
assert calc.current_year == year
assert calc.param('II_em') == 3950
assert calc.policy_param('II_em') == 3950
exp_II_em = [3900, 3950, 5000] + [6000] * (Policy.DEFAULT_NUM_YEARS - 3)
assert np.allclose(calc.param('_II_em'),
assert np.allclose(calc.policy_param('_II_em'),
np.array(exp_II_em))
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2016
assert np.allclose(calc.param('STD_Aged'),
assert np.allclose(calc.policy_param('STD_Aged'),
np.array([1600, 1300, 1600, 1300, 1600]))


Expand Down Expand Up @@ -244,10 +244,10 @@ def test_make_calculator_increment_years_first(cps_subsample):
[std5, std5, std5, std5, std5],
[std6, std6, std6, std6, std6],
[std7, std7, std7, std7, std7]])
act_STD_Aged = calc.param('_STD_Aged')
act_STD_Aged = calc.policy_param('_STD_Aged')
assert np.allclose(act_STD_Aged[:5], exp_STD_Aged)
exp_II_em = np.array([3900, 3950, 5000, 6000, 6000])
act_II_em = calc.param('_II_em')
act_II_em = calc.policy_param('_II_em')
assert np.allclose(act_II_em[:5], exp_II_em)


Expand Down