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


Python Policy.set_year方法代码示例

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


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

示例1: test_Policy_reform_makes_no_changes_before_year

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

示例2: test_variable_inflation_rate_with_reform

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_variable_inflation_rate_with_reform():
    """
    Test indexing of policy parameters involved in a reform.
    """
    pol = Policy()
    syr = Policy.JSON_START_YEAR
    assert pol._II_em[2013 - syr] == 3900
    # implement reform in 2020 which is two years before the last year, 2022
    reform = {
        'II_em': {2018: 1000,  # to avoid divide-by-zero under TCJA
                  2020: 20000}
    }
    pol.implement_reform(reform)
    pol.set_year(2020)
    assert pol.current_year == 2020
    # extract price inflation rates
    pirates = pol.inflation_rates()
    irate2018 = pirates[2018 - syr]
    irate2020 = pirates[2020 - syr]
    irate2021 = pirates[2021 - syr]
    # check implied inflation rate between 2018 and 2019 (before the reform)
    grate = float(pol._II_em[2019 - syr]) / float(pol._II_em[2018 - syr])
    assert round(grate - 1.0, 5) == round(irate2018, 5)
    # check implied inflation rate between 2020 and 2021 (after the reform)
    grate = float(pol._II_em[2021 - syr]) / float(pol._II_em[2020 - syr])
    assert round(grate - 1.0, 5) == round(irate2020, 5)
    # check implied inflation rate between 2021 and 2022 (after the reform)
    grate = float(pol._II_em[2022 - syr]) / float(pol._II_em[2021 - syr])
    assert round(grate - 1.0, 5) == round(irate2021, 5)
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:31,代码来源:test_policy.py

示例3: test_expand_2D_accept_None

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [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

示例4: test_Policy_reform_after_start_year

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

示例5: test_round_trip_tcja_reform

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

示例6: test_convert

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
    def test_convert(self):

        values = {"II_brk2_0": [36000., 38000., 40000.],
                    "II_brk2_1": [72250., 74000.],
                    "II_brk2_2": [36500.]
                    }

        ans = package_up_vars(values, first_budget_year=FBY)
        pp = Policy(start_year=2013)
        pp.set_year(FBY)
        # irates are rates for 2015, 2016, and 2017
        irates = pp.indexing_rates_for_update(param_name='II_brk2', calyear=FBY,
                                            num_years_to_expand=3)

        # User choices propagate through to all future years
        # The user has specified part of the parameter up to 2017.
        # So, we choose to fill in the propagated value, which is
        # either inflated or not.

        f2_2016 = int(36500 * (1.0 + irates[0]))
        f3_2016 = int(50200 * (1.0 + irates[0]))
        f4_2016 = int(74900 * (1.0 + irates[0]))
        f5_2016 = int(37450 * (1.0 + irates[0]))

        f1_2017 = int(74000 * (1.0 + irates[1]))
        f2_2017 = int(f2_2016 * (1.0 + irates[1]))
    
        exp =  [[36000, 72250, 36500, 50200, 74900, 37450],
                [38000, 74000, f2_2016, 50400, 75300, 37650],
                [40000, f1_2017, f2_2017, None, None, None]]

        assert ans['_II_brk2'] == exp
        assert len(ans) == 1
开发者ID:Kalaiselvy,项目名称:webapp-public,代码行数:35,代码来源:test_all.py

示例7: test_read_json_reform_file_and_implement_reform_b

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_read_json_reform_file_and_implement_reform_b(reform_file):
    """
    Test reading and translation of reform file into a reform dictionary
    that is then used to call implement_reform method.
    NOTE: implement_reform called when policy.current_year > policy.start_year
    """
    reform = Policy.read_json_reform_file(reform_file.name)
    policy = Policy()
    policy.set_year(2015)  # the only difference between this and prior test
    policy.implement_reform(reform)
    syr = policy.start_year
    amt_tthd = policy._AMT_tthd
    assert amt_tthd[2015 - syr] == 200000
    assert amt_tthd[2016 - syr] > 200000
    assert amt_tthd[2017 - syr] == 300000
    assert amt_tthd[2018 - syr] > 300000
    ii_em = policy._II_em
    assert ii_em[2016 - syr] == 6000
    assert ii_em[2017 - syr] == 6000
    assert ii_em[2018 - syr] == 7500
    assert ii_em[2019 - syr] > 7500
    assert ii_em[2020 - syr] == 9000
    assert ii_em[2021 - syr] > 9000
    amt_em = policy._AMT_em
    assert amt_em[2016 - syr, 0] > amt_em[2015 - syr, 0]
    assert amt_em[2017 - syr, 0] > amt_em[2016 - syr, 0]
    assert amt_em[2018 - syr, 0] == amt_em[2017 - syr, 0]
    assert amt_em[2019 - syr, 0] == amt_em[2017 - syr, 0]
    assert amt_em[2020 - syr, 0] == amt_em[2017 - syr, 0]
    assert amt_em[2021 - syr, 0] > amt_em[2020 - syr, 0]
    assert amt_em[2022 - syr, 0] > amt_em[2021 - syr, 0]
开发者ID:chrisrytting,项目名称:Tax-Calculator,代码行数:33,代码来源:test_policy.py

示例8: test_calculator_using_nonstd_input

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_calculator_using_nonstd_input(rawinputfile):
    """
    Test Calculator using non-standard input records.
    """
    # check Calculator handling of raw, non-standard input data with no aging
    pol = Policy()
    pol.set_year(RAWINPUTFILE_YEAR)  # set policy params to input data year
    nonstd = Records(data=rawinputfile.name,
                     gfactors=None,  # keeps raw data unchanged
                     weights=None,
                     start_year=RAWINPUTFILE_YEAR)  # set raw input data year
    assert nonstd.array_length == RAWINPUTFILE_FUNITS
    calc = Calculator(policy=pol, records=nonstd,
                      sync_years=False)  # keeps raw data unchanged
    assert calc.current_year == RAWINPUTFILE_YEAR
    calc.calc_all()
    assert calc.weighted_total('e00200') == 0
    assert calc.total_weight() == 0
    varlist = ['RECID', 'MARS']
    dframe = calc.dataframe(varlist)
    assert isinstance(dframe, pd.DataFrame)
    assert dframe.shape == (RAWINPUTFILE_FUNITS, len(varlist))
    mars = calc.array('MARS')
    assert isinstance(mars, np.ndarray)
    assert mars.shape == (RAWINPUTFILE_FUNITS,)
    exp_iitax = np.zeros((nonstd.array_length,))
    assert np.allclose(calc.array('iitax'), exp_iitax)
    mtr_ptax, _, _ = calc.mtr(wrt_full_compensation=False)
    exp_mtr_ptax = np.zeros((nonstd.array_length,))
    exp_mtr_ptax.fill(0.153)
    assert np.allclose(mtr_ptax, exp_mtr_ptax)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:33,代码来源:test_calculator.py

示例9: test_2017_law_reform

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_2017_law_reform(tests_path):
    """
    Check that policy parameter values in a future year under current-law
    policy and under the reform specified in the 2017_law.json file are
    sensible.
    """
    # create pre metadata dictionary for 2017_law.json 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()
    reform = Calculator.read_json_param_objects(rtext, None)
    pol.implement_reform(reform['policy'])
    # 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
    pol.set_year(2018)
    pre_mdata = pol.metadata()
    # check some policy parameter values against expected values under 2017 law
    pre_expect = {
        # relation '<' implies asserting that actual < expect
        # relation '>' implies asserting that actual > expect
        # ... parameters not affected by TCJA and that are not indexed
        'AMEDT_ec': {'relation': '=', 'value': 200000},
        'SS_thd85': {'relation': '=', 'value': 34000},
        # ... parameters not affected by TCJA and that are indexed
        'STD_Dep': {'relation': '>', 'value': 1050},
        'CG_brk2': {'relation': '>', 'value': 425800},
        'AMT_CG_brk1': {'relation': '>', 'value': 38600},
        'AMT_brk1': {'relation': '>', 'value': 191100},
        'EITC_c': {'relation': '>', 'value': 519},
        'EITC_ps': {'relation': '>', 'value': 8490},
        'EITC_ps_MarriedJ': {'relation': '>', 'value': 5680},
        'EITC_InvestIncome_c': {'relation': '>', 'value': 3500},
        # ... parameters affected by TCJA and that are not indexed
        'ID_Charity_crt_all': {'relation': '=', 'value': 0.5},
        'II_rt3': {'relation': '=', 'value': 0.25},
        # ... parameters affected by TCJA and that are indexed
        'II_brk3': {'relation': '>', 'value': 91900},
        'STD': {'relation': '<', 'value': 7000},
        'II_em': {'relation': '>', 'value': 4050},
        'AMT_em_pe': {'relation': '<', 'value': 260000}
    }
    assert isinstance(pre_expect, dict)
    assert set(pre_expect.keys()).issubset(set(pre_mdata.keys()))
    for name in pre_expect:
        aval = pre_mdata[name]['value']
        if isinstance(aval, list):
            act = aval[0]  # comparing only first item in a vector parameter
        else:
            act = aval
        exp = pre_expect[name]['value']
        if pre_expect[name]['relation'] == '<':
            assert act < exp, '{} a={} !< e={}'.format(name, act, exp)
        elif pre_expect[name]['relation'] == '>':
            assert act > exp, '{} a={} !> e={}'.format(name, act, exp)
        elif pre_expect[name]['relation'] == '=':
            assert act == exp, '{} a={} != e={}'.format(name, act, exp)
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:61,代码来源:test_reforms.py

示例10: test_Policy_reform_with_default_cpi_flags

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_Policy_reform_with_default_cpi_flags():
    ppo = Policy(start_year=2013)
    reform = {2015: {'_II_em': [4300]}}
    ppo.implement_reform(reform)
    # '_II_em' has a default cpi_flag of True, so
    # in 2016 its value should be greater than 4300
    ppo.set_year(2016)
    assert ppo.II_em > 4300
开发者ID:chrisrytting,项目名称:Tax-Calculator,代码行数:10,代码来源:test_policy.py

示例11: main

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def main(start_year, delay_years, scale_factor, no_indexing, each_separate):
    """
    Highest-level logic of make_reforms.py script.
    """
    # check validity of function arguments
    if start_year < FIRST_YEAR:
        msg = 'ERROR: --year {} sets year before {}\n'
        sys.stderr.write(msg.format(start_year, FIRST_YEAR))
        return 1
    if scale_factor < 1.0:
        msg = 'ERROR: --scale {} sets scale below one\n'
        sys.stderr.write(msg.format(scale_factor))
        return 1
    if each_separate:
        reform = PROVISIONS_EACH_SEPARATE
    else:
        reform = PROVISIONS_ALL_TOGETHER

    # get current-law-policy parameters for start_year in a Policy object
    clp = Policy()
    clp.set_year(start_year)

    # construct of set of Policy parameter names
    policy_param_names = set(getattr(clp, '_vals').keys())

    # remove names of policy parameters not currently used by TaxBrain
    param_names = policy_param_names - PARAMS_NOT_USED_IN_TAXBRAIN

    # add *_cpi parameter names if no_indexing is true
    if no_indexing:
        param_names = param_names | indexed_parameter_names(clp, param_names)

    # remove "null" reform provisions
    if scale_factor == 1.0:
        excluded_names = set()
        for name in param_names:
            if not name.endswith('_cpi'):
                excluded_names.add(name)
        param_names = param_names - excluded_names

    # write a JSON entry for each parameter
    np.random.seed(seed=987654321)
    if reform == PROVISIONS_ALL_TOGETHER:
        write_all_together(param_names, clp,
                           start_year, delay_years,
                           scale_factor)
    elif reform == PROVISIONS_EACH_SEPARATE:
        write_each_separate(param_names, clp,
                            start_year, delay_years,
                            scale_factor)
    else:
        msg = 'ERROR: reform has illegal value {}\n'
        sys.stderr.write(msg.format(reform))
        return 1

    # return no-error exit code
    return 0
开发者ID:kerkphil,项目名称:Tax-Calculator,代码行数:59,代码来源:make_reforms.py

示例12: test_reform_with_default_indexed

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_reform_with_default_indexed():
    """
    Test that implement_reform indexes after first reform year.
    """
    ppo = Policy()
    reform = {'II_em': {2015: 4300}}
    ppo.implement_reform(reform)
    # II_em has a default indexing status of true, so
    # in 2016 its value should be greater than 4300
    ppo.set_year(2016)
    assert ppo.II_em > 4300
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:13,代码来源:test_policy.py

示例13: test_reform_makes_no_changes_before_year

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_reform_makes_no_changes_before_year():
    """
    Test that implement_reform makes no changes before first reform year.
    """
    ppo = Policy()
    reform = {'II_em': {2015: 4400}, 'II_em-indexed': {2015: True}}
    ppo.implement_reform(reform)
    ppo.set_year(2015)
    assert np.allclose(ppo._II_em[:3], np.array([3900, 3950, 4400]),
                       atol=0.01, rtol=0.0)
    assert ppo.II_em == 4400
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:13,代码来源:test_policy.py

示例14: propagate_user_list

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def propagate_user_list(x, defaults, cpi, first_budget_year):
    """
    Dispatch to either expand_1D or expand2D depending on the dimension of x

    Parameters:
    -----------
    x : list from user to propagate forward in time. The first value is for
        year 'first_budget_year'. The value at index i is the value for
        budget year first_budget_year + i. 

    defaults: list of default values; our result must be at least this long

    cpi: Bool

    first_budget_year: int 

    Returns:
    --------
    list of length 'num_years'. if 'cpi'==True, the values will be inflated
    based on the last value the user specified

    """
    # x can't be empty
    assert x

    num_years = max(len(defaults), len(x))

    is_rate = any([ i < 1.0 for i in x])

    pp = Policy(start_year=2013)
    pp.set_year(first_budget_year)
    # irates are rates for 2015, 2016, and 2017
    if cpi:
        irates = pp.indexing_rates_for_update(param_name='II_brk2',
                                              calyear=first_budget_year,
                                              num_years_to_expand=num_years)
    else:
        irates = [0.0] * num_years

    last_val = x[-1]
    ans = [None] * num_years
    for i in range(num_years):
        if i < len(x):
            if x[i] == '*':
                ans[i] = defaults[i]
            else:
                ans[i] = x[i]
        else:
            newval = ans[i-1] * (1.0 + irates[i-1])
            ans[i] = newval if is_rate else int(newval)


    return ans
开发者ID:Kalaiselvy,项目名称:webapp-public,代码行数:55,代码来源:helpers.py

示例15: test_calc_all

# 需要导入模块: from taxcalc import Policy [as 别名]
# 或者: from taxcalc.Policy import set_year [as 别名]
def test_calc_all():
    """
    Test calc_all method.
    """
    cyr = 2016
    pol = Policy()
    pol.set_year(cyr)
    nonstd = Records(data=pd.read_csv(StringIO(RAWINPUT_CONTENTS)),
                     start_year=cyr, gfactors=None, weights=None)
    assert nonstd.array_length == RAWINPUT_FUNITS
    calc = Calculator(policy=pol, records=nonstd,
                      sync_years=False)  # keeps raw data unchanged
    assert calc.current_year == cyr
开发者ID:open-source-economics,项目名称:Tax-Calculator,代码行数:15,代码来源:test_calculator.py


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