当前位置: 首页>>代码示例>>Python>>正文


Python Policy.expand_array方法代码示例

本文整理汇总了Python中taxcalc.Policy.expand_array方法的典型用法代码示例。如果您正苦于以下问题:Python Policy.expand_array方法的具体用法?Python Policy.expand_array怎么用?Python Policy.expand_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在taxcalc.Policy的用法示例。


在下文中一共展示了Policy.expand_array方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_parameters_from_file

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_create_parameters_from_file(policyfile):
    with open(policyfile.name) as pfile:
        policy = json.load(pfile)
    ppo = Policy(parameter_dict=policy)
    irates = Policy.default_inflation_rates()
    inf_rates = [irates[ppo.start_year + i] for i in range(0, ppo.num_years)]
    assert_allclose(ppo._almdep,
                    Policy.expand_array(np.array([7150, 7250, 7400]),
                                        inflate=True,
                                        inflation_rates=inf_rates,
                                        num_years=ppo.num_years),
                    atol=0.01, rtol=0.0)
    assert_allclose(ppo._almsep,
                    Policy.expand_array(np.array([40400, 41050]),
                                        inflate=True,
                                        inflation_rates=inf_rates,
                                        num_years=ppo.num_years),
                    atol=0.01, rtol=0.0)
    assert_allclose(ppo._rt5,
                    Policy.expand_array(np.array([0.33]),
                                        inflate=False,
                                        inflation_rates=inf_rates,
                                        num_years=ppo.num_years),
                    atol=0.01, rtol=0.0)
    assert_allclose(ppo._rt7,
                    Policy.expand_array(np.array([0.396]),
                                        inflate=False,
                                        inflation_rates=inf_rates,
                                        num_years=ppo.num_years),
                    atol=0.01, rtol=0.0)
开发者ID:chrisrytting,项目名称:Tax-Calculator,代码行数:32,代码来源:test_policy.py

示例2: test_expand_2D_accept_None_additional_row

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_expand_2D_accept_None_additional_row():
    _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],
                [43000, 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
    exp6 = exp1 * 1.03
    exp7 = exp2 * 1.03
    exp8 = exp3 * 1.03
    exp9 = exp4 * 1.03
    exp10 = exp5 * 1.03
    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],
           [43000, exp6, exp7, exp8, exp9, exp10]]
    exp = np.array(exp).astype('i4', casting='unsafe')
    inflation_rates = [0.015, 0.02, 0.02, 0.03]
    res = Policy.expand_array(_II_brk2, inflate=True,
                              inflation_rates=inflation_rates, num_years=5)
    npt.assert_array_equal(res, exp)
开发者ID:chun1211,项目名称:Tax-Calculator,代码行数:28,代码来源:test_utils.py

示例3: test_make_Calculator_user_mods_with_cpi_flags

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_make_Calculator_user_mods_with_cpi_flags(policyfile, puf_1991):
    with open(policyfile.name) as pfile:
        policy = json.load(pfile)
    ppo = Policy(parameter_dict=policy, start_year=1991,
                 num_years=len(IRATES), inflation_rates=IRATES,
                 wage_growth_rates=WRATES)
    rec = Records(data=puf_1991, start_year=1991)
    calc = Calculator(policy=ppo, records=rec)
    user_mods = {1991: {"_almdep": [7150, 7250, 7400],
                        "_almdep_cpi": True,
                        "_almsep": [40400, 41050],
                        "_almsep_cpi": False,
                        "_rt5": [0.33],
                        "_rt7": [0.396]}}
    calc.policy.implement_reform(user_mods)
    # compare actual and expected values
    inf_rates = [IRATES[1991 + i] for i in range(0, Policy.DEFAULT_NUM_YEARS)]
    exp_almdep = Policy.expand_array(np.array([7150, 7250, 7400]),
                                     inflate=True,
                                     inflation_rates=inf_rates,
                                     num_years=Policy.DEFAULT_NUM_YEARS)
    act_almdep = getattr(calc.policy, '_almdep')
    assert np.allclose(act_almdep, exp_almdep)
    exp_almsep_values = [40400] + [41050] * (Policy.DEFAULT_NUM_YEARS - 1)
    exp_almsep = np.array(exp_almsep_values)
    act_almsep = getattr(calc.policy, '_almsep')
    assert np.allclose(act_almsep, exp_almsep)
开发者ID:kerkphil,项目名称:Tax-Calculator,代码行数:29,代码来源:test_calculate.py

示例4: test_make_Calculator_user_mods_with_cpi_flags

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_make_Calculator_user_mods_with_cpi_flags(policyfile):
    with open(policyfile.name) as pfile:
        policy = json.load(pfile)
    ppo = Policy(parameter_dict=policy, start_year=1991,
                 num_years=len(IRATES), inflation_rates=IRATES,
                 wage_growth_rates=WRATES)
    calc = Calculator(policy=ppo, records=TAX_DTA_PATH, start_year=1991,
                      inflation_rates=IRATES)
    user_mods = {1991: {"_almdep": [7150, 7250, 7400],
                        "_almdep_cpi": True,
                        "_almsep": [40400, 41050],
                        "_almsep_cpi": False,
                        "_rt5": [0.33],
                        "_rt7": [0.396]}}
    calc.policy.implement_reform(user_mods)

    inf_rates = [IRATES[1991 + i] for i in range(0, 12)]
    exp_almdep = Policy.expand_array(np.array([7150, 7250, 7400]),
                                     inflate=True,
                                     inflation_rates=inf_rates, num_years=12)
    act_almdep = getattr(calc.policy, '_almdep')
    assert_array_equal(act_almdep, exp_almdep)
    exp_almsep_values = [40400] + [41050] * 11
    exp_almsep = np.array(exp_almsep_values)
    act_almsep = getattr(calc.policy, '_almsep')
    assert_array_equal(act_almsep, exp_almsep)
开发者ID:MattHJensen,项目名称:taxcalc,代码行数:28,代码来源:test_calculate.py

示例5: test_expand_2D_accept_None

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [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)
开发者ID:GoFroggyRun,项目名称:Tax-Calculator,代码行数:32,代码来源:test_utils.py

示例6: test_expand_1D_accept_None

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_expand_1D_accept_None():
    x = [4.0, 5.0, None]
    irates = [0.02, 0.02, 0.03, 0.035]
    exp = []
    cur = 5.0 * 1.02
    exp = [4.0, 5.0, cur]
    cur *= 1.03
    exp.append(cur)
    cur *= 1.035
    exp.append(cur)
    exp = np.array(exp)
    res = Policy.expand_array(x, inflate=True, inflation_rates=irates, num_years=5)
    npt.assert_allclose(exp.astype("f4", casting="unsafe"), res)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:15,代码来源:test_utils.py

示例7: test_expand_2D_accept_None

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [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)
开发者ID:chun1211,项目名称:Tax-Calculator,代码行数:21,代码来源:test_utils.py

示例8: test_expand_2D_accept_None_additional_row

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_expand_2D_accept_None_additional_row():
    _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],
        [43000, 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
    exp6 = exp1 * 1.03
    exp7 = exp2 * 1.03
    exp8 = exp3 * 1.03
    exp9 = exp4 * 1.03
    exp10 = exp5 * 1.03
    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],
        [43000, exp6, exp7, exp8, exp9, exp10],
    ]
    inflation_rates = [0.015, 0.02, 0.02, 0.03]
    res = Policy.expand_array(_II_brk2, inflate=True, inflation_rates=inflation_rates, num_years=5)
    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(2020)
    irates = Policy.default_inflation_rates()
    # The 2020 policy should be the combination of the user-defined
    # value and CPI-inflated values from 2018
    exp_2020 = [43000.0] + [(1 + irates[2019]) * (1 + irates[2018]) * i for i in _II_brk2[2][1:]]
    exp_2020 = np.array(exp_2020)
    npt.assert_allclose(pol.II_brk2, exp_2020)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:41,代码来源:test_utils.py

示例9: test_multi_year_reform

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import expand_array [as 别名]
def test_multi_year_reform():
    """
    Test multi-year reform involving 1D and 2D parameters.
    """
    # specify dimensions of policy Policy object
    syr = 2013
    nyrs = 10
    # specify assumed inflation rates
    irates = {2013: 0.02, 2014: 0.02, 2015: 0.02, 2016: 0.03, 2017: 0.03,
              2018: 0.04, 2019: 0.04, 2020: 0.04, 2021: 0.04, 2022: 0.04}
    ifactor = {}
    for i in range(0, nyrs):
        ifactor[syr + i] = 1.0 + irates[syr + i]
    iratelist = [irates[syr + i] for i in range(0, nyrs)]
    # specify assumed inflation rates
    wrates = {2013: 0.0276, 2014: 0.0419, 2015: 0.0465, 2016: 0.0498,
              2017: 0.0507, 2018: 0.0481, 2019: 0.0451, 2020: 0.0441,
              2021: 0.0437, 2022: 0.0435}
    wfactor = {}
    for i in range(0, nyrs):
        wfactor[syr + i] = 1.0 + wrates[syr + i]
    wratelist = [wrates[syr + i] for i in range(0, nyrs)]
    # instantiate policy Policy object
    ppo = Policy(start_year=syr, num_years=nyrs, inflation_rates=irates,
                 wage_growth_rates=wrates)
    # confirm that parameters have current-law values
    assert_allclose(getattr(ppo, '_AMT_thd_MarriedS'),
                    Policy.expand_array(np.array([40400, 41050]),
                                        inflate=True,
                                        inflation_rates=iratelist,
                                        num_years=nyrs),
                    atol=0.01, rtol=0.0)
    assert_allclose(getattr(ppo, '_EITC_c'),
                    Policy.expand_array(np.array([[487, 3250, 5372, 6044],
                                                  [496, 3305, 5460, 6143],
                                                  [503, 3359, 5548, 6242],
                                                  [506, 3373, 5572, 6269]]),
                                        inflate=True,
                                        inflation_rates=iratelist,
                                        num_years=nyrs),
                    atol=0.01, rtol=0.0)
    assert_allclose(getattr(ppo, '_II_em'),
                    Policy.expand_array(np.array([3900, 3950, 4000, 4050]),
                                        inflate=True,
                                        inflation_rates=iratelist,
                                        num_years=nyrs),
                    atol=0.01, rtol=0.0)
    assert_allclose(getattr(ppo, '_CTC_c'),
                    Policy.expand_array(np.array([1000]),
                                        inflate=False,
                                        inflation_rates=iratelist,
                                        num_years=nyrs),
                    atol=0.01, rtol=0.0)
    # this parameter uses a different inflating rate
    assert_allclose(getattr(ppo, '_SS_Earnings_c'),
                    Policy.expand_array(np.array([113700, 117000,
                                                  118500, 118500]),
                                        inflate=True,
                                        inflation_rates=wratelist,
                                        num_years=nyrs),
                    atol=0.01, rtol=0.0)
    # specify multi-year reform using a dictionary of year_provisions dicts
    reform = {
        2015: {
            '_AMT_thd_MarriedS': [60000],
            '_CTC_c': [2000]
        },
        2016: {
            '_EITC_c': [[900, 5000, 8000, 9000]],
            '_II_em': [7000],
            '_SS_Earnings_c': [300000]
        },
        2017: {
            '_AMT_thd_MarriedS': [80000],
            '_SS_Earnings_c': [500000], '_SS_Earnings_c_cpi': False
        },
        2019: {
            '_EITC_c': [[1200, 7000, 10000, 12000]],
            '_II_em': [9000],
            '_SS_Earnings_c': [700000], '_SS_Earnings_c_cpi': True
        }
    }
    # implement multi-year reform
    ppo.implement_reform(reform)
    assert ppo.current_year == syr
    # move policy Policy object forward in time so current_year is syr+2
    #   Note: this would be typical usage because the first budget year
    #         is greater than Policy start_year.
    ppo.set_year(ppo.start_year + 2)
    assert ppo.current_year == syr + 2
    # confirm that actual parameters have expected post-reform values
    check_amt_thd_marrieds(ppo, reform, ifactor)
    check_eitc_c(ppo, reform, ifactor)
    check_ii_em(ppo, reform, ifactor)
    check_ss_earnings_c(ppo, reform, wfactor)
    check_ctc_c(ppo, reform)
开发者ID:chrisrytting,项目名称:Tax-Calculator,代码行数:98,代码来源:test_policy.py


注:本文中的taxcalc.Policy.expand_array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。