本文整理汇总了Python中taxcalc.Policy.implement_reform方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.implement_reform方法的具体用法?Python Policy.implement_reform怎么用?Python Policy.implement_reform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taxcalc.Policy
的用法示例。
在下文中一共展示了Policy.implement_reform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Policy_reform_makes_no_changes_before_year
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_Policy_reform_makes_no_changes_before_year():
ppo = Policy(start_year=2013)
reform = {2015: {'_II_em': [4400], '_II_em_cpi': True}}
ppo.implement_reform(reform)
ppo.set_year(2015)
assert_array_equal(ppo._II_em[:3], np.array([3900, 3950, 4400]))
assert ppo.II_em == 4400
示例2: test_make_Calculator_with_reform_after_start_year
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_make_Calculator_with_reform_after_start_year():
# create Policy object using custom indexing rates
irates = {2013: 0.01, 2014: 0.01, 2015: 0.02, 2016: 0.01, 2017: 0.03}
parm = Policy(start_year=2013, num_years=len(irates),
inflation_rates=irates)
# specify reform in 2015, which is two years after Policy start_year
reform = {2015: {}, 2016: {}}
reform[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
parm.implement_reform(reform)
recs = Records(data=TAX_DTA, weights=WEIGHTS, start_year=2009)
calc = Calculator(policy=parm, records=recs)
# compare actual and expected parameter values over all years
exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500, 1200],
[1550, 1200, 1200, 1550, 1550, 1200],
[1600, 1300, 1600, 1300, 1600, 1300],
[1632, 1326, 1632, 1326, 1632, 1326],
[1648, 1339, 1648, 1339, 1648, 1339]])
exp_II_em = np.array([3900, 3950, 5000, 6000, 6000])
assert_array_equal(calc.policy._STD_Aged, exp_STD_Aged)
assert_array_equal(calc.policy._II_em, exp_II_em)
# compare actual and expected values for 2015
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2015
exp_2015_II_em = 5000
assert_array_equal(calc.policy.II_em, exp_2015_II_em)
exp_2015_STD_Aged = np.array([1600, 1300, 1600, 1300, 1600, 1300])
assert_array_equal(calc.policy.STD_Aged, exp_2015_STD_Aged)
示例3: test_make_Calculator_increment_years_first
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_make_Calculator_increment_years_first():
# create Policy object with custom indexing rates and policy reform
irates = {2013: 0.01, 2014: 0.01, 2015: 0.02, 2016: 0.01, 2017: 0.03}
policy = Policy(start_year=2013, inflation_rates=irates,
num_years=len(irates))
reform = {2015: {}, 2016: {}}
reform[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
policy.implement_reform(reform)
# create Records object by reading 1991 data and saying it is 2009 data
tax_dta = pd.read_csv(TAX_DTA_PATH, compression='gzip')
puf = Records(tax_dta, weights=WEIGHTS, start_year=2009)
# create Calculator object with Policy object as modified by reform
calc = Calculator(policy=policy, records=puf)
# compare expected policy parameter values with those embedded in calc
exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500, 1200],
[1550, 1200, 1200, 1550, 1550, 1200],
[1600, 1300, 1600, 1300, 1600, 1300],
[1632, 1326, 1632, 1326, 1632, 1326],
[1648, 1339, 1648, 1339, 1648, 1339]])
exp_II_em = np.array([3900, 3950, 5000, 6000, 6000])
assert_array_equal(calc.policy._STD_Aged, exp_STD_Aged)
assert_array_equal(calc.policy._II_em, exp_II_em)
示例4: test_Policy_reform_after_start_year
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_Policy_reform_after_start_year():
ppo = Policy(start_year=2013)
reform = {2015: {'_STD_Aged': [[1400, 1100, 1100, 1400, 1400, 1199]]}}
ppo.implement_reform(reform)
ppo.set_year(2015)
assert_array_equal(ppo.STD_Aged,
np.array([1400, 1100, 1100, 1400, 1400, 1199]))
示例5: test_expand_2D_accept_None
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_expand_2D_accept_None():
_II_brk2 = [[36000, 72250, 36500, 48600, 72500, 36250],
[38000, 74000, 36900, 49400, 73800, 36900],
[40000, 74900, 37450, 50200, 74900, 37450],
[41000, None, None, None, None, None]]
exp1 = 74900 * 1.02
exp2 = 37450 * 1.02
exp3 = 50200 * 1.02
exp4 = 74900 * 1.02
exp5 = 37450 * 1.02
exp = [[36000, 72250, 36500, 48600, 72500, 36250],
[38000, 74000, 36900, 49400, 73800, 36900],
[40000, 74900, 37450, 50200, 74900, 37450],
[41000, exp1, exp2, exp3, exp4, exp5]]
exp = np.array(exp).astype('i4', casting='unsafe')
res = Policy.expand_array(_II_brk2, inflate=True,
inflation_rates=[0.02] * 5,
num_years=4)
npt.assert_array_equal(res, exp)
user_mods = {2016: {u'_II_brk2': _II_brk2}}
pol = Policy(start_year=2013)
pol.implement_reform(user_mods)
pol.set_year(2019)
irates = Policy.default_inflation_rates()
# The 2019 policy should be the combination of the user-defined
# value and CPI-inflated values from 2018
exp_2019 = [41000.] + [(1 + irates[2018]) * i for i in _II_brk2[2][1:]]
exp_2019 = np.array(exp_2019)
npt.assert_array_equal(pol.II_brk2, exp_2019)
示例6: test_round_trip_tcja_reform
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_round_trip_tcja_reform(tests_path):
"""
Check that current-law policy has the same policy parameter values in
a future year as does a compound reform that first implements the
reform specified in the 2017_law.json file and then implements the
reform specified in the TCJA.json file. This test checks that the
future-year parameter values for current-law policy (which incorporates
TCJA) are the same as future-year parameter values for the compound
round-trip reform. Doing this check ensures that the 2017_law.json
and TCJA.json reform files are specified in a consistent manner.
"""
# pylint: disable=too-many-locals
fyear = 2020
# create clp metadata dictionary for current-law policy in fyear
pol = Policy()
pol.set_year(fyear)
clp_mdata = pol.metadata()
# create rtr metadata dictionary for round-trip reform in fyear
pol = Policy()
reform_file = os.path.join(tests_path, '..', 'reforms', '2017_law.json')
with open(reform_file, 'r') as rfile:
rtext = rfile.read()
pol.implement_reform(Policy.read_json_reform(rtext))
# eventually activate: assert not clp.parameter_warnings
ctc_c_warning = 'CTC_c was redefined in release 1.0.0\n'
assert pol.parameter_warnings == ctc_c_warning
assert not pol.parameter_errors
reform_file = os.path.join(tests_path, '..', 'reforms', 'TCJA.json')
with open(reform_file, 'r') as rfile:
rtext = rfile.read()
pol.implement_reform(Policy.read_json_reform(rtext))
# eventually activate: assert not clp.parameter_warnings
assert pol.parameter_warnings == ctc_c_warning
assert not pol.parameter_errors
pol.set_year(fyear)
rtr_mdata = pol.metadata()
# compare fyear policy parameter values
assert clp_mdata.keys() == rtr_mdata.keys()
fail_dump = False
if fail_dump:
rtr_fails = open('fails_rtr', 'w')
clp_fails = open('fails_clp', 'w')
fail_params = list()
msg = '\nRound-trip-reform and current-law-policy param values differ for:'
for pname in clp_mdata.keys():
rtr_val = rtr_mdata[pname]['value']
clp_val = clp_mdata[pname]['value']
if not np.allclose(rtr_val, clp_val):
fail_params.append(pname)
msg += '\n {} in {} : rtr={} clp={}'.format(
pname, fyear, rtr_val, clp_val
)
if fail_dump:
rtr_fails.write('{} {} {}\n'.format(pname, fyear, rtr_val))
clp_fails.write('{} {} {}\n'.format(pname, fyear, clp_val))
if fail_dump:
rtr_fails.close()
clp_fails.close()
if fail_params:
raise ValueError(msg)
示例7: test_dec_graph_plots
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_dec_graph_plots(cps_subsample):
pol = Policy()
rec = Records.cps_constructor(data=cps_subsample)
calc1 = Calculator(policy=pol, records=rec)
year = 2020
calc1.advance_to_year(year)
reform = {
'SS_Earnings_c': {year: 9e99}, # OASDI FICA tax on all earnings
'FICA_ss_trt': {year: 0.107484} # lower rate to keep revenue unchanged
}
pol.implement_reform(reform)
calc2 = Calculator(policy=pol, records=rec)
calc2.advance_to_year(year)
assert calc1.current_year == calc2.current_year
calc1.calc_all()
calc2.calc_all()
fig = calc1.decile_graph(calc2)
assert fig
dt1, dt2 = calc1.distribution_tables(calc2, 'weighted_deciles')
dta = dec_graph_data(dt1, dt2, year,
include_zero_incomes=True,
include_negative_incomes=False)
assert isinstance(dta, dict)
dta = dec_graph_data(dt1, dt2, year,
include_zero_incomes=False,
include_negative_incomes=True)
assert isinstance(dta, dict)
dta = dec_graph_data(dt1, dt2, year,
include_zero_incomes=False,
include_negative_incomes=False)
assert isinstance(dta, dict)
示例8: test_make_Calculator_with_reform_after_start_year
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_make_Calculator_with_reform_after_start_year(records_2009):
# create Policy object using custom indexing rates
irates = {2013: 0.01, 2014: 0.01, 2015: 0.02, 2016: 0.01, 2017: 0.03}
parm = Policy(start_year=2013, num_years=len(irates),
inflation_rates=irates)
# specify reform in 2015, which is two years after Policy start_year
reform = {2015: {}, 2016: {}}
reform[2015]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600, 1300]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
parm.implement_reform(reform)
calc = Calculator(policy=parm, records=records_2009)
# compare actual and expected parameter values over all years
assert np.allclose(calc.policy._STD_Aged,
np.array([[1500, 1200, 1200, 1500, 1500, 1200],
[1550, 1200, 1200, 1550, 1550, 1200],
[1600, 1300, 1600, 1300, 1600, 1300],
[1632, 1326, 1632, 1326, 1632, 1326],
[1648, 1339, 1648, 1339, 1648, 1339]]),
atol=0.5, rtol=0.0) # handles rounding to dollars
assert np.allclose(calc.policy._II_em,
np.array([3900, 3950, 5000, 6000, 6000]))
# compare actual and expected values for 2015
calc.increment_year()
calc.increment_year()
assert calc.current_year == 2015
assert np.allclose(calc.policy.II_em, 5000)
assert np.allclose(calc.policy.STD_Aged,
np.array([1600, 1300, 1600, 1300, 1600, 1300]))
示例9: test_calculator_mtr_when_PT_rates_differ
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_calculator_mtr_when_PT_rates_differ():
"""
Test Calculator mtr method in special case.
"""
reform = {2013: {'_II_rt1': [0.40],
'_II_rt2': [0.40],
'_II_rt3': [0.40],
'_II_rt4': [0.40],
'_II_rt5': [0.40],
'_II_rt6': [0.40],
'_II_rt7': [0.40],
'_PT_rt1': [0.30],
'_PT_rt2': [0.30],
'_PT_rt3': [0.30],
'_PT_rt4': [0.30],
'_PT_rt5': [0.30],
'_PT_rt6': [0.30],
'_PT_rt7': [0.30]}}
funit = (
u'RECID,MARS,FLPDYR,e00200,e00200p,e00900,e00900p,extraneous\n'
u'1, 1, 2009, 200000,200000, 100000,100000, 9999999999\n'
)
rec = Records(pd.read_csv(StringIO(funit)))
pol = Policy()
calc1 = Calculator(policy=pol, records=rec)
(_, mtr1, _) = calc1.mtr(variable_str='p23250')
pol.implement_reform(reform)
calc2 = Calculator(policy=pol, records=rec)
(_, mtr2, _) = calc2.mtr(variable_str='p23250')
assert np.allclose(mtr1, mtr2, rtol=0.0, atol=1e-06)
示例10: taxcalc_results
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def taxcalc_results(start_year, reform_dict, itax_clp, ptax_clp):
"""
Use taxcalc package on this computer to compute aggregate income tax and
payroll tax revenue difference (between reform and current-law policy)
for ten years beginning with the specified start_year using the specified
reform_dict dictionary and the two specified current-law-policy results
dictionaries.
Return two aggregate tax revenue difference dictionaries indexed by
calendar year.
"""
pol = Policy()
pol.implement_reform(reform_dict)
calc = Calculator(policy=pol,
records=Records(data=PUF_PATH),
verbose=False)
calc.advance_to_year(start_year)
nyears = NUMBER_OF_YEARS
adts = list()
for iyr in range(-1, nyears - 1):
calc.calc_all()
adts.append(create_diagnostic_table(calc))
if iyr < nyears:
calc.increment_year()
adt = pd.concat(adts, axis=1)
# note that adt is Pandas DataFrame object
itax_ref = adt.xs('Ind Income Tax ($b)').to_dict()
ptax_ref = adt.xs('Payroll Taxes ($b)').to_dict()
itax_diff = {}
ptax_diff = {}
for year in itax_ref:
itax_diff[year] = round(itax_ref[year] - itax_clp[year], 1)
ptax_diff[year] = round(ptax_ref[year] - ptax_clp[year], 1)
return (itax_diff, ptax_diff)
示例11: test_distribution_tables
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_distribution_tables(cps_subsample):
"""
Test distribution_tables method.
"""
pol = Policy()
recs = Records.cps_constructor(data=cps_subsample)
calc1 = Calculator(policy=pol, records=recs)
assert calc1.current_year == 2014
calc1.calc_all()
dt1, dt2 = calc1.distribution_tables(None, 'weighted_deciles')
assert isinstance(dt1, pd.DataFrame)
assert dt2 is None
dt1, dt2 = calc1.distribution_tables(calc1, 'weighted_deciles')
assert isinstance(dt1, pd.DataFrame)
assert isinstance(dt2, pd.DataFrame)
reform = {2014: {'_UBI_u18': [1000],
'_UBI_1820': [1000],
'_UBI_21': [1000]}}
pol.implement_reform(reform)
assert not pol.parameter_errors
calc2 = Calculator(policy=pol, records=recs)
calc2.calc_all()
dt1, dt2 = calc1.distribution_tables(calc2, 'weighted_deciles')
assert isinstance(dt1, pd.DataFrame)
assert isinstance(dt2, pd.DataFrame)
示例12: test_make_calculator_with_multiyear_reform
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_make_calculator_with_multiyear_reform(cps_subsample):
"""
Test Calculator class ctor with multi-year policy reform.
"""
rec = Records.cps_constructor(data=cps_subsample)
year = rec.current_year
# create a Policy object and apply a policy reform
pol = Policy()
reform = {2015: {}, 2016: {}}
reform[2015]['_II_em'] = [5000, 6000] # reform values for 2015 and 2016
reform[2015]['_II_em_cpi'] = False
reform[2016]['_STD_Aged'] = [[1600, 1300, 1600, 1300, 1600]]
pol.implement_reform(reform)
# create a Calculator object using this policy-reform
calc = Calculator(policy=pol, records=rec)
# 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.policy_param('II_em') == 3950
exp_II_em = [3900, 3950, 5000] + [6000] * (Policy.DEFAULT_NUM_YEARS - 3)
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.policy_param('STD_Aged'),
np.array([1600, 1300, 1600, 1300, 1600]))
示例13: test_ID_HC_vs_BS
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_ID_HC_vs_BS(puf_1991, weights_1991):
"""
Test that complete haircut of itemized deductions produces same
results as a 100% benefit surtax with no benefit deduction.
"""
# specify complete-haircut reform policy and Calculator object
hc_reform = {2013: {'_ID_Medical_hc': [1.0],
'_ID_StateLocalTax_hc': [1.0],
'_ID_RealEstate_hc': [1.0],
'_ID_Casualty_hc': [1.0],
'_ID_Miscellaneous_hc': [1.0],
'_ID_InterestPaid_hc': [1.0],
'_ID_Charity_hc': [1.0]}}
hc_policy = Policy()
hc_policy.implement_reform(hc_reform)
hc_records = Records(data=puf_1991, weights=weights_1991, start_year=2009)
hc_calc = Calculator(policy=hc_policy, records=hc_records)
# specify benefit-surtax reform policy and Calculator object
bs_reform = {2013: {'_ID_BenefitSurtax_crt': [0.0],
'_ID_BenefitSurtax_trt': [1.0]}}
bs_policy = Policy()
bs_policy.implement_reform(bs_reform)
bs_records = Records(data=puf_1991, weights=weights_1991, start_year=2009)
bs_calc = Calculator(policy=bs_policy, records=bs_records)
# compare calculated tax results generated by the two reforms
hc_calc.calc_all()
bs_calc.calc_all()
assert np.allclose(hc_calc.records._payrolltax,
bs_calc.records._payrolltax)
assert np.allclose(hc_calc.records._iitax,
bs_calc.records._iitax)
示例14: test_read_json_param_with_suffixes_and_errors
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def test_read_json_param_with_suffixes_and_errors():
"""
Test interaction of policy parameter suffixes and reform errors
(fails without 0.10.2 bug fix as reported by Hank Doupe in PB PR#641)
"""
reform = {
u'policy': {
u'_II_brk4_separate': {u'2017': [5000.0]},
u'_STD_separate': {u'2017': [8000.0]},
u'_STD_single': {u'2018': [1000.0]},
u'_II_brk2_headhousehold': {u'2017': [1000.0]},
u'_II_brk4_single': {u'2017': [500.0]},
u'_STD_joint': {u'2017': [10000.0], u'2020': [150.0]},
u'_II_brk2_separate': {u'2017': [1000.0]},
u'_II_brk2_single': {u'2017': [1000.0]},
u'_II_brk2_joint': {u'2017': [1000.0]},
u'_FICA_ss_trt': {u'2017': [-1.0], u'2019': [0.1]},
u'_II_brk4_headhousehold': {u'2017': [500.0]},
u'_STD_headhousehold': {u'2017': [10000.0], u'2020': [150.0]},
u'_ID_Medical_frt': {u'2019': [0.06]},
u'_II_brk4_joint': {u'2017': [500.0]},
u'_ID_BenefitSurtax_Switch_medical': {u'2017': [True]}
}
}
json_reform = json.dumps(reform)
params = Calculator.read_json_param_objects(json_reform, None)
assert isinstance(params, dict)
pol = Policy()
pol.ignore_reform_errors()
pol.implement_reform(params['policy'],
print_warnings=False, raise_errors=False)
assert pol.parameter_errors
assert pol.parameter_warnings
示例15: diff_in_revenue
# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import implement_reform [as 别名]
def diff_in_revenue(reform_on_II, orig_reform):
policy_func = Policy()
puf = pd.read_csv("./puf.csv")
records_func = Records(puf)
calc_func = Calculator(policy = policy_func, records = records_func)
policy_bench = Policy()
records_bench = Records(puf)
calc_bench = Calculator(policy = policy_bench, records = records_bench)
reform = {
CURRENT_YEAR:{
"_II_rt1":[max(policy_bench._II_rt1[0] *(1 - reform_on_II),0.0)],
"_II_rt2":[max(policy_bench._II_rt2[0] *(1 - reform_on_II),0.0)],
"_II_rt3":[max(policy_bench._II_rt3[0] *(1 - reform_on_II),0.0)],
"_II_rt4":[max(policy_bench._II_rt4[0] *(1 - reform_on_II),0.0)],
"_II_rt5":[max(policy_bench._II_rt5[0] *(1 - reform_on_II),0.0)],
"_II_rt6":[max(policy_bench._II_rt6[0] *(1 - reform_on_II),0.0)],
"_II_rt7":[max(policy_bench._II_rt7[0] *(1 - reform_on_II),0.0)]}
}
policy_func.implement_reform(reform)
policy_func.implement_reform(orig_reform)
calc_func.advance_to_year(CURRENT_YEAR)
calc_bench.advance_to_year(CURRENT_YEAR)
calc_func.calc_all()
calc_bench.calc_all()
ans = ((calc_bench.records._combined*calc_bench.records.s006).sum()-(calc_func.records._combined*calc_func.records.s006).sum())
print("diff in revenue is ", ans)
return ans