本文整理汇总了Python中taxcalc.Records.cps_constructor方法的典型用法代码示例。如果您正苦于以下问题:Python Records.cps_constructor方法的具体用法?Python Records.cps_constructor怎么用?Python Records.cps_constructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taxcalc.Records
的用法示例。
在下文中一共展示了Records.cps_constructor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_consumption_response
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_consumption_response(cps_subsample):
consump = Consumption()
mpc = 0.5
consumption_response = {'MPC_e20400': {2013: mpc}}
consump.update_consumption(consumption_response)
# test incorrect call to response method
with pytest.raises(ValueError):
consump.response(list(), 1)
# test correct call to response method
rec = Records.cps_constructor(data=cps_subsample)
pre = copy.deepcopy(rec.e20400)
consump.response(rec, 1.0)
post = rec.e20400
actual_diff = post - pre
expected_diff = np.ones(rec.array_length) * mpc
assert np.allclose(actual_diff, expected_diff)
# compute earnings mtr with no consumption response
rec = Records.cps_constructor(data=cps_subsample)
ided0 = copy.deepcopy(rec.e20400)
calc0 = Calculator(policy=Policy(), records=rec, consumption=None)
(mtr0_ptax, mtr0_itax, _) = calc0.mtr(variable_str='e00200p',
wrt_full_compensation=False)
assert np.allclose(calc0.array('e20400'), ided0)
# compute earnings mtr with consumption response
calc1 = Calculator(policy=Policy(), records=rec, consumption=consump)
mtr1_ptax, mtr1_itax, _ = calc1.mtr(variable_str='e00200p',
wrt_full_compensation=False)
assert np.allclose(calc1.array('e20400'), ided0)
# confirm that payroll mtr values are no different
assert np.allclose(mtr1_ptax, mtr0_ptax)
# confirm that all mtr with cons-resp are no greater than without cons-resp
assert np.all(np.less_equal(np.around(mtr1_itax, decimals=5),
np.around(mtr0_itax, decimals=5)))
# confirm that some mtr with cons-resp are less than without cons-resp
assert np.any(np.less(mtr1_itax, mtr0_itax))
示例2: test_itax_compare
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_itax_compare(tests_path, using_puf, puf_fullsample, cps_fullsample):
"""
Conduct income tax comparisons using ITAX data.
"""
using_puf_adjust_ratios = True
# generate 2015 estimates by AGI category using Tax-Calculator
if using_puf:
if using_puf_adjust_ratios:
recs = Records(data=puf_fullsample)
else:
recs = Records(data=puf_fullsample, adjust_ratios=None)
else:
recs = Records.cps_constructor(data=cps_fullsample)
calc = Calculator(policy=Policy(), records=recs, verbose=False)
calc.advance_to_year(2015)
calc.calc_all()
# open actual output file
if using_puf:
afilename = os.path.join(tests_path, 'cmpi_puf_actual.txt')
else:
afilename = os.path.join(tests_path, 'cmpi_cps_actual.txt')
afile = open(afilename, 'w')
# write compare results to afile
for cname in sorted(ITAX.keys()):
comparison(cname, calc, ITAX, afile)
# close actual output file
afile.close()
# check for differences between actual and expect output files
efilename = afilename.replace('actual', 'expect')
differences(afilename, efilename)
示例3: test_make_calculator_with_multiyear_reform
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [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]))
示例4: test_make_calculator_with_policy_reform
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_make_calculator_with_policy_reform(cps_subsample):
"""
Test Calculator class ctor with 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 = {2013: {'_II_em': [4000], '_II_em_cpi': False,
'_STD_Aged': [[1600, 1300, 1300, 1600, 1600]],
'_STD_Aged_cpi': False}}
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 calc.current_year == year
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.policy_param('_STD_Aged'),
np.array(exp_STD_Aged))
assert np.allclose(calc.policy_param('STD_Aged'),
np.array([1600, 1300, 1300, 1600, 1600]))
示例5: test_n65
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_n65(cps_subsample):
"""
Test n65 method.
"""
recs = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=Policy(), records=recs)
assert calc.n65().sum() > 1500
示例6: test_make_calculator_raises_on_no_policy
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_make_calculator_raises_on_no_policy(cps_subsample):
"""
Test Calculator ctor error with no policy argument.
"""
rec = Records.cps_constructor(data=cps_subsample)
with pytest.raises(ValueError):
Calculator(records=rec)
示例7: test_distribution_tables
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [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)
示例8: test_write_graph_file
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_write_graph_file(cps_subsample):
recs = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=Policy(), records=recs)
mtr = 0.20 * np.ones_like(cps_subsample['e00200'])
vdf = calc.dataframe(['s006', 'e00200', 'c00100'])
vdf['mtr1'] = mtr
vdf['mtr2'] = mtr
gdata = mtr_graph_data(vdf, calc.current_year, mtr_measure='ptax',
alt_e00200p_text='Taxpayer Earnings',
income_measure='agi',
dollar_weighting=False)
gplot = xtr_graph_plot(gdata)
assert gplot
htmlfname = temporary_filename(suffix='.html')
try:
write_graph_file(gplot, htmlfname, 'title')
except Exception: # pylint: disable=broad-except
if os.path.isfile(htmlfname):
try:
os.remove(htmlfname)
except OSError:
pass # sometimes we can't remove a generated temporary file
assert 'write_graph_file()_ok' == 'no'
# if try was successful, try to remove the file
if os.path.isfile(htmlfname):
try:
os.remove(htmlfname)
except OSError:
pass # sometimes we can't remove a generated temporary file
示例9: test_make_calculator_increment_years_first
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_make_calculator_increment_years_first(cps_subsample):
"""
Test Calculator inflation indexing of policy parameters.
"""
# pylint: disable=too-many-locals
# create Policy object with policy reform
pol = Policy()
reform = {2015: {}, 2016: {}}
std5 = 2000
reform[2015]['_STD_Aged'] = [[std5, std5, std5, std5, std5]]
reform[2015]['_II_em'] = [5000]
reform[2016]['_II_em'] = [6000]
reform[2016]['_II_em_cpi'] = False
pol.implement_reform(reform)
# create Calculator object with Policy object as modified by reform
rec = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=pol, records=rec)
# compare expected policy parameter values with those embedded in calc
irates = pol.inflation_rates()
syr = Policy.JSON_START_YEAR
irate2015 = irates[2015 - syr]
irate2016 = irates[2016 - syr]
std6 = std5 * (1.0 + irate2015)
std7 = std6 * (1.0 + irate2016)
exp_STD_Aged = np.array([[1500, 1200, 1200, 1500, 1500],
[1550, 1200, 1200, 1550, 1550],
[std5, std5, std5, std5, std5],
[std6, std6, std6, std6, std6],
[std7, std7, std7, std7, std7]])
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.policy_param('_II_em')
assert np.allclose(act_II_em[:5], exp_II_em)
示例10: test_ID_HC_vs_BS
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_ID_HC_vs_BS(cps_subsample):
"""
Test that complete haircut of itemized deductions produces same
results as a 100% benefit surtax with no benefit deduction.
"""
recs = Records.cps_constructor(data=cps_subsample)
# 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_calc = Calculator(policy=hc_policy, records=recs)
hc_calc.calc_all()
hc_taxes = hc_calc.dataframe(['iitax', 'payrolltax'])
del hc_calc
# 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_calc = Calculator(policy=bs_policy, records=recs)
bs_calc.calc_all()
bs_taxes = bs_calc.dataframe(['iitax', 'payrolltax'])
del bs_calc
# compare calculated taxes generated by the two reforms
assert np.allclose(hc_taxes['payrolltax'], bs_taxes['payrolltax'])
assert np.allclose(hc_taxes['iitax'], bs_taxes['iitax'])
示例11: test_mtr_graph_data
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_mtr_graph_data(cps_subsample):
recs = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=Policy(), records=recs)
year = calc.current_year
with pytest.raises(ValueError):
mtr_graph_data(None, year, mars='bad',
income_measure='agi',
dollar_weighting=True)
with pytest.raises(ValueError):
mtr_graph_data(None, year, mars=0,
income_measure='expanded_income',
dollar_weighting=True)
with pytest.raises(ValueError):
mtr_graph_data(None, year, mars=list())
with pytest.raises(ValueError):
mtr_graph_data(None, year, mars='ALL', mtr_variable='e00200s')
with pytest.raises(ValueError):
mtr_graph_data(None, year, mtr_measure='badtax')
with pytest.raises(ValueError):
mtr_graph_data(None, year, income_measure='badincome')
mtr = 0.20 * np.ones_like(cps_subsample['e00200'])
vdf = calc.dataframe(['s006', 'MARS', 'e00200'])
vdf['mtr1'] = mtr
vdf['mtr2'] = mtr
vdf = vdf[vdf['MARS'] == 1]
gdata = mtr_graph_data(vdf, year, mars=1,
mtr_wrt_full_compen=True,
income_measure='wages',
dollar_weighting=True)
assert isinstance(gdata, dict)
示例12: test_dec_graph_plots
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [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)
示例13: test_diagnostic_table
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_diagnostic_table(cps_subsample):
"""
Test diagnostic_table method.
"""
recs = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=Policy(), records=recs)
adt = calc.diagnostic_table(3)
assert isinstance(adt, pd.DataFrame)
示例14: test_make_calculator_deepcopy
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_make_calculator_deepcopy(cps_subsample):
"""
Test deepcopy of Calculator object.
"""
pol = Policy()
rec = Records.cps_constructor(data=cps_subsample)
calc1 = Calculator(policy=pol, records=rec)
calc2 = copy.deepcopy(calc1)
assert isinstance(calc2, Calculator)
示例15: test_dist_table_sum_row
# 需要导入模块: from taxcalc import Records [as 别名]
# 或者: from taxcalc.Records import cps_constructor [as 别名]
def test_dist_table_sum_row(cps_subsample):
rec = Records.cps_constructor(data=cps_subsample)
calc = Calculator(policy=Policy(), records=rec)
calc.calc_all()
tb1 = create_distribution_table(calc.distribution_table_dataframe(),
'standard_income_bins', 'expanded_income')
tb2 = create_distribution_table(calc.distribution_table_dataframe(),
'soi_agi_bins', 'expanded_income')
assert np.allclose(tb1[-1:], tb2[-1:])