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


Python Calculator.read_json_param_objects方法代码示例

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


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

示例1: test_translate_json_reform_suffixes_mars_non_indexed

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_translate_json_reform_suffixes_mars_non_indexed():
    """
    Test read_json_param_objects method using MARS-indexed parameter suffixes.
    """
    json1 = """{"policy": {
      "_II_em": {"2020": [20000], "2015": [15000]},
      "_AMEDT_ec_joint": {"2018": [400000], "2016": [300000]},
      "_AMEDT_ec_separate": {"2017": [150000], "2019": [200000]}
    }}"""
    pdict1 = Calculator.read_json_param_objects(reform=json1, assump=None)
    rdict1 = pdict1['policy']
    json2 = """{"policy": {
      "_AMEDT_ec": {"2016": [[200000, 300000, 125000, 200000, 200000]],
                    "2017": [[200000, 300000, 150000, 200000, 200000]],
                    "2018": [[200000, 400000, 150000, 200000, 200000]],
                    "2019": [[200000, 400000, 200000, 200000, 200000]]},
      "_II_em": {"2015": [15000], "2020": [20000]}
    }}"""
    pdict2 = Calculator.read_json_param_objects(reform=json2, assump=None)
    rdict2 = pdict2['policy']
    assert len(rdict2) == len(rdict1)
    for year in rdict2.keys():
        if '_II_em' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_II_em'],
                               rdict2[year]['_II_em'],
                               atol=0.01, rtol=0.0)
        if '_AMEDT_ec' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_AMEDT_ec'],
                               rdict2[year]['_AMEDT_ec'],
                               atol=0.01, rtol=0.0)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:32,代码来源:test_calculator.py

示例2: test_translate_json_reform_suffixes_eic

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_translate_json_reform_suffixes_eic():
    """
    Test read_json_param_objects method using EIC-indexed parameter suffixes.
    """
    json1 = """{"policy": {
      "_II_em": {"2020": [20000], "2015": [15000]},
      "_EITC_c_0kids": {"2018": [510], "2019": [510]},
      "_EITC_c_1kid": {"2019": [3400], "2018": [3400]},
      "_EITC_c_2kids": {"2018": [5616], "2019": [5616]},
      "_EITC_c_3+kids": {"2019": [6318], "2018": [6318]}
    }}"""
    pdict1 = Calculator.read_json_param_objects(reform=json1, assump=None)
    rdict1 = pdict1['policy']
    json2 = """{"policy": {
      "_EITC_c": {"2019": [[510, 3400, 5616, 6318]],
                  "2018": [[510, 3400, 5616, 6318]]},
      "_II_em": {"2020": [20000], "2015": [15000]}
    }}"""
    pdict2 = Calculator.read_json_param_objects(reform=json2, assump=None)
    rdict2 = pdict2['policy']
    assert len(rdict2) == len(rdict1)
    for year in rdict2.keys():
        if '_II_em' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_II_em'],
                               rdict2[year]['_II_em'],
                               atol=0.01, rtol=0.0)
        if '_EITC_c' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_EITC_c'],
                               rdict2[year]['_EITC_c'],
                               atol=0.01, rtol=0.0)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:32,代码来源:test_calculator.py

示例3: test_json_reform_url

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_json_reform_url():
    """
    Test reading a JSON reform from a URL. Results from the URL are expected
    to match the results from the string.
    """
    reform_str = """
    {
    "policy": {
        // raise FICA payroll tax rate in 2018 and 2020
        "FICA_ss_trt": {
            "2018": 0.130,
            "2020": 0.140
        },
        // raise Medicare payroll tax rate in 2019 and 2021
        "FICA_mc_trt": {
            "2019": 0.030,
            "2021": 0.032
        }
      }
    }
    """
    reform_url = ('https://raw.githubusercontent.com/PSLmodels/'
                  'Tax-Calculator/master/taxcalc/reforms/ptaxes0.json')
    params_str = Calculator.read_json_param_objects(reform_str, None)
    params_url = Calculator.read_json_param_objects(reform_url, None)
    assert params_str == params_url
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:28,代码来源:test_calculator.py

示例4: test_read_bad_json_assump_file

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_read_bad_json_assump_file(bad1assumpfile, bad2assumpfile,
                                   bad3assumpfile):
    """
    Test invalid JSON assumption files.
    """
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, bad1assumpfile.name)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, bad2assumpfile.name)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, bad3assumpfile.name)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, 'unknown_file_name')
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, list())
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:17,代码来源:test_calculator.py

示例5: test_read_json_param_with_suffixes_and_errors

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

示例6: test_noreform_documentation

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_noreform_documentation():
    """
    Test automatic documentation creation.
    """
    reform_json = """
    {
    "policy": {}
    }
    """
    assump_json = """
    {
    "consumption": {},
    "growdiff_baseline": {},
    "growdiff_response": {}
    }
    """
    params = Calculator.read_json_param_objects(reform_json, assump_json)
    assert isinstance(params, dict)
    actual_doc = Calculator.reform_documentation(params)
    expected_doc = (
        'REFORM DOCUMENTATION\n'
        'Baseline Growth-Difference Assumption Values by Year:\n'
        'none: using default baseline growth assumptions\n'
        'Policy Reform Parameter Values by Year:\n'
        'none: using current-law policy parameters\n'
    )
    assert actual_doc == expected_doc
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:29,代码来源:test_calculator.py

示例7: fixture_baseline_2017_law

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def fixture_baseline_2017_law(tests_path):
    """
    Read ../reforms/2017_law.json and return its policy dictionary.
    """
    pre_tcja_jrf = os.path.join(tests_path, '..', 'reforms', '2017_law.json')
    pre_tcja = Calculator.read_json_param_objects(pre_tcja_jrf, None)
    return pre_tcja['policy']
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:9,代码来源:test_reforms.py

示例8: test_2017_law_reform

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

示例9: test_bad_json_names

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_bad_json_names(tests_path):
    """
    Test that ValueError raised with assump or reform do not end in '.json'
    """
    csvname = os.path.join(tests_path, '..', 'growfactors.csv')
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(csvname, None)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects('http://name.json.html', None)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, csvname)
    with pytest.raises(ValueError):
        Calculator.read_json_param_objects(None, 'http://name.json.html')
开发者ID:open-source-economics,项目名称:Tax-Calculator,代码行数:15,代码来源:test_calculator.py

示例10: test_translate_json_reform_suffixes_idedtype

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_translate_json_reform_suffixes_idedtype():
    """
    Test read_json_param_objects method using idedtype-indexed param suffixes.
    """
    # test read_json_param_objects(...)
    # using idedtype-indexed parameter suffixes
    json1 = """{"policy": {
      "_ID_BenefitCap_rt": {"2019": [0.2]},
      "_ID_BenefitCap_Switch_medical": {"2019": [false]},
      "_ID_BenefitCap_Switch_casualty": {"2019": [false]},
      "_ID_BenefitCap_Switch_misc": {"2019": [false]},
      "_ID_BenefitCap_Switch_interest": {"2019": [false]},
      "_ID_BenefitCap_Switch_charity": {"2019": [false]},
      "_II_em": {"2020": [20000], "2015": [15000]}
    }}"""
    pdict1 = Calculator.read_json_param_objects(reform=json1, assump=None)
    rdict1 = pdict1['policy']
    json2 = """{"policy": {
      "_II_em": {"2020": [20000], "2015": [15000]},
      "_ID_BenefitCap_Switch": {
        "2019": [[false, true, true, false, false, false, false]]
      },
      "_ID_BenefitCap_rt": {"2019": [0.2]}
    }}"""
    pdict2 = Calculator.read_json_param_objects(reform=json2, assump=None)
    rdict2 = pdict2['policy']
    assert len(rdict2) == len(rdict1)
    for year in rdict2.keys():
        if '_II_em' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_II_em'],
                               rdict2[year]['_II_em'],
                               atol=0.01, rtol=0.0)
        if '_ID_BenefitCap_rt' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_ID_BenefitCap_rt'],
                               rdict2[year]['_ID_BenefitCap_rt'],
                               atol=0.01, rtol=0.0)
        if '_ID_BenefitCap_Switch' in rdict2[year].keys():
            assert np.allclose(rdict1[year]['_ID_BenefitCap_Switch'],
                               rdict2[year]['_ID_BenefitCap_Switch'],
                               atol=0.01, rtol=0.0)
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:42,代码来源:test_calculator.py

示例11: test_reform_documentation

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_reform_documentation():
    """
    Test automatic documentation creation.
    """
    reform_json = """
{
"policy": {
    "II_em-indexed": {
        "2016": false,
        "2018": true
    },
    "II_em": {
        "2016": 5000,
        "2018": 6000,
        "2020": 7000
    },
    "EITC_indiv": {
        "2017": true
    },
    "STD_Aged-indexed": {
        "2016": false
    },
    "STD_Aged": {
        "2016": [1600, 1300, 1300, 1600, 1600],
        "2020": [2000, 2000, 2000, 2000, 2000]
    },
    "ID_BenefitCap_Switch": {
        "2020": [false, false, false, false, false, false, false]
    }
}
}
"""
    assump_json = """
{
"consumption": {},
// increase baseline inflation rate by one percentage point in 2014+
// (has no effect on known policy parameter values)
"growdiff_baseline": {"ACPIU": {"2014": 0.010}},
"growdiff_response": {"ACPIU": {"2014": 0.015}}
}
"""
    params = Calculator.read_json_param_objects(reform_json, assump_json)
    assert isinstance(params, dict)
    second_reform = {'II_em': {2019: 6500}}
    doc = Calculator.reform_documentation(params, [second_reform])
    assert isinstance(doc, str)
    dump = False  # set to True to print documentation and force test failure
    if dump:
        print(doc)
        assert 1 == 2
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:52,代码来源:test_calculator.py

示例12: test_calc_all

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_calc_all(reform_file, rawinputfile):
    """
    Test calc_all method.
    """
    cyr = 2016
    pol = Policy()
    param_dict = Calculator.read_json_param_objects(reform_file.name, None)
    pol.implement_reform(param_dict['policy'])
    pol.set_year(cyr)
    nonstd = Records(data=rawinputfile.name, gfactors=None,
                     weights=None, start_year=cyr)
    assert nonstd.array_length == RAWINPUTFILE_FUNITS
    calc = Calculator(policy=pol, records=nonstd,
                      sync_years=False)  # keeps raw data unchanged
    assert calc.current_year == cyr
    assert calc.reform_warnings == ''
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:18,代码来源:test_calculator.py

示例13: test_calc_all

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_calc_all():
    """
    Test calc_all method.
    """
    cyr = 2016
    pol = Policy()
    param_dict = Calculator.read_json_param_objects(REFORM_JSON, None)
    pol.implement_reform(param_dict['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
    assert calc.reform_warnings == ''
开发者ID:andersonfrailey,项目名称:Tax-Calculator,代码行数:18,代码来源:test_calculator.py

示例14: test_read_json_reform_file_and_implement_reform

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_read_json_reform_file_and_implement_reform(reform_file,
                                                    assump_file,
                                                    set_year):
    """
    Test reading and translation of reform file into a reform dictionary
    that is then used to call implement_reform method and Calculate.calc_all()
    NOTE: implement_reform called when policy.current_year == policy.start_year
    """
    pol = Policy()
    if set_year:
        pol.set_year(2015)
    param_dict = Calculator.read_json_param_objects(reform_file.name,
                                                    assump_file.name)
    pol.implement_reform(param_dict['policy'])
    syr = pol.start_year
    # pylint: disable=protected-access,no-member
    amt_brk1 = pol._AMT_brk1
    assert amt_brk1[2015 - syr] == 200000
    assert amt_brk1[2016 - syr] > 200000
    assert amt_brk1[2017 - syr] == 300000
    assert amt_brk1[2018 - syr] > 300000
    ii_em = pol._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 = pol._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]
    add4aged = pol._ID_Medical_frt_add4aged
    assert add4aged[2015 - syr] == -0.025
    assert add4aged[2016 - syr] == -0.025
    assert add4aged[2017 - syr] == 0.0
    assert add4aged[2022 - syr] == 0.0
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:43,代码来源:test_calculator.py

示例15: test_reform_documentation

# 需要导入模块: from taxcalc import Calculator [as 别名]
# 或者: from taxcalc.Calculator import read_json_param_objects [as 别名]
def test_reform_documentation():
    """
    Test automatic documentation creation.
    """
    reform_json = """
    {
    "policy": {
      "_II_em_cpi": {"2016": false,
                     "2018": true},
      "_II_em": {"2016": [5000],
                 "2018": [6000],
                 "2020": [7000]},
      "_EITC_indiv": {"2017": [true]},
      "_STD_Aged_cpi": {"2016": false},
      "_STD_Aged": {"2016": [[1600, 1300, 1300, 1600, 1600]],
                    "2020": [[2000, 2000, 2000, 2000, 2000]]},
      "_ID_BenefitCap_Switch_medical": {"2020": [false]},
      "_ID_BenefitCap_Switch_casualty": {"2020": [false]},
      "_ID_BenefitCap_Switch_misc": {"2020": [false]},
      "_ID_BenefitCap_Switch_interest": {"2020": [false]},
      "_ID_BenefitCap_Switch_charity": {"2020": [false]}
      }
    }
    """
    assump_json = """
    {
    "consumption": {},
    // increase baseline inflation rate by one percentage point in 2014+
    // (has no effect on known policy parameter values)
    "growdiff_baseline": {"_ACPIU": {"2014": [0.01]}},
    "growdiff_response": {}
    }
    """
    params = Calculator.read_json_param_objects(reform_json, assump_json)
    assert isinstance(params, dict)
    doc = Calculator.reform_documentation(params)
    assert isinstance(doc, str)
    dump = False  # set to True to print documentation and force test failure
    if dump:
        print(doc)
        assert 1 == 2
开发者ID:codykallen,项目名称:Tax-Calculator,代码行数:43,代码来源:test_calculator.py


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