Beispiel #1
0
def test_puf_path():
    """
    Check that setting `data` to None uses the puf file
    """
    from ogusa import get_micro_data
    baseline = False
    start_year = 2016
    reform = {2017: {"_II_em": [10000]}}

    # get path to puf if puf.csv in ogusa/ directory
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    puf_path = os.path.join(cur_dir, "../puf.csv")

    # puf.csv in ogusa/
    if os.path.exists(puf_path):
        calc = get_micro_data.get_calculator(
            baseline, start_year, reform=reform, data=puf_path)
        # blind_head is only in the CPS file and e00700 is only in the PUF.
        # See taxcalc/records_variables.json
        assert (calc.array('blind_head').sum() == 0 and
                calc.array('e00700').sum() > 0)
    # we do not have puf.csv
    else:
        # make sure TC is looking for puf.csv
        with pytest.raises((IOError, ValueError), match="puf.csv"):
            get_micro_data.get_calculator(
                baseline, start_year, reform=reform,
                records_start_year=CPS_START_YEAR, data=None)
Beispiel #2
0
def test_get_micro_data_get_calculator():

    reform = {
    2016: {
        '_II_rt1': [.09],
        '_II_rt2': [.135],
        '_II_rt3': [.225],
        '_II_rt4': [.252],
        '_II_rt5': [.297],
        '_II_rt6': [.315],
        '_II_rt7': [0.3564],
    }, }

    calc = get_calculator(baseline=False, calculator_start_year=2016,
                          reform=reform, data=TAXDATA,
                          weights=WEIGHTS, records_start_year=2009)
    assert calc.current_year == 2016

    reform = {
    2016: {
        '_II_rt1': [.09],
        '_II_rt2': [.135],
        '_II_rt3': [.225],
        '_II_rt4': [.252],
        '_II_rt5': [.297],
        '_II_rt6': [.315],
        '_II_rt7': [0.3564],
        '_factor_adjustment': [0.1]
    }, }

    calc2 = get_calculator(baseline=False, calculator_start_year=2016,
                           reform=reform, data=TAXDATA,
                           weights=WEIGHTS, records_start_year=2009)
    assert calc2.current_year == 2016
Beispiel #3
0
def test_puf_path():
    """
    Check that setting `data` to None uses the puf file
    """
    from ogusa import get_micro_data
    baseline = False
    start_year = 2016
    reform = {2017: {"_II_em": [10000]}}

    # get path to puf if puf.csv in ogusa/ directory
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    puf_path = os.path.join(cur_dir, "../puf.csv")

    # puf.csv in ogusa/
    if os.path.exists(puf_path):
        calc = get_micro_data.get_calculator(baseline,
                                             start_year,
                                             reform=reform,
                                             data=puf_path)
        # blind_head is only in the CPS file and e00700 is only in the PUF.
        # See taxcalc/records_variables.json
        assert (calc.array('blind_head').sum() == 0
                and calc.array('e00700').sum() > 0)
    # we do not have puf.csv
    else:
        # make sure TC is looking for puf.csv
        with pytest.raises((IOError, ValueError), match="puf.csv"):
            get_micro_data.get_calculator(
                baseline,
                start_year,
                reform=reform,
                records_start_year=RECORDS_START_YEAR,
                data=None)
def test_puf_path():
    """
    Check that setting `data` to None uses the puf file
    """
    baseline = False
    start_year = 2016
    reform = {"II_em": {2017: 10000}}

    # puf.csv in ogusa/
    if os.path.exists(PUF_PATH):
        calc = get_micro_data.get_calculator(
            baseline, start_year, reform=reform, data=PUF_PATH
        )
        # blind_head is only in the CPS file and e00700 is only in the
        # PUF.  See taxcalc/records_variables.json
        assert (
            calc.array("blind_head").sum() == 0
            and calc.array("e00700").sum() > 0
        )
    # we do not have puf.csv
    else:
        # make sure TC is looking for puf.csv
        with pytest.raises((IOError, ValueError), match="puf.csv"):
            get_micro_data.get_calculator(
                baseline,
                start_year,
                reform=reform,
                records_start_year=CPS_START_YEAR,
                data=None,
            )
Beispiel #5
0
def test_get_calculator():
    iit_reform = {
        'II_rt1': {
            2017: 0.09
        },
        'II_rt2': {
            2017: 0.135
        },
        'II_rt3': {
            2017: 0.225
        },
        'II_rt4': {
            2017: 0.252
        },
        'II_rt5': {
            2017: 0.297
        },
        'II_rt6': {
            2017: 0.315
        },
        'II_rt7': {
            2017: 0.3564
        }
    }
    calc = get_micro_data.get_calculator(baseline=False,
                                         calculator_start_year=2017,
                                         reform=iit_reform,
                                         data='cps',
                                         gfactors=GrowFactors(),
                                         records_start_year=CPS_START_YEAR)
    assert calc.current_year == CPS_START_YEAR
Beispiel #6
0
def test_get_calculator_puf_from_file():
    iit_reform = {
        'II_rt1': {
            2017: 0.09
        },
        'II_rt2': {
            2017: 0.135
        },
        'II_rt3': {
            2017: 0.225
        },
        'II_rt4': {
            2017: 0.252
        },
        'II_rt5': {
            2017: 0.297
        },
        'II_rt6': {
            2017: 0.315
        },
        'II_rt7': {
            2017: 0.3564
        }
    }
    calc = get_micro_data.get_calculator(baseline=False,
                                         calculator_start_year=2017,
                                         reform=iit_reform,
                                         data=PUF_PATH,
                                         records_start_year=PUF_START_YEAR)
    assert calc.current_year == 2013
Beispiel #7
0
def test_get_calculator_exception():
    iit_reform = {
        'II_rt1': {
            2017: 0.09
        },
        'II_rt2': {
            2017: 0.135
        },
        'II_rt3': {
            2017: 0.225
        },
        'II_rt4': {
            2017: 0.252
        },
        'II_rt5': {
            2017: 0.297
        },
        'II_rt6': {
            2017: 0.315
        },
        'II_rt7': {
            2017: 0.3564
        }
    }
    with pytest.raises(Exception):
        assert get_micro_data.get_calculator(
            baseline=False,
            calculator_start_year=TC_LAST_YEAR + 1,
            reform=iit_reform,
            data='cps',
            gfactors=GrowFactors(),
            records_start_year=CPS_START_YEAR)
Beispiel #8
0
def test_get_micro_data_get_calculator():
    reform = {
        'II_rt1': {
            2017: 0.09
        },
        'II_rt2': {
            2017: 0.135
        },
        'II_rt3': {
            2017: 0.225
        },
        'II_rt4': {
            2017: 0.252
        },
        'II_rt5': {
            2017: 0.297
        },
        'II_rt6': {
            2017: 0.315
        },
        'II_rt7': {
            2017: 0.3564
        }
    }

    calc = get_calculator(baseline=False,
                          calculator_start_year=2017,
                          reform=reform,
                          data=TAXDATA,
                          gfactors=GrowFactors(),
                          weights=WEIGHTS,
                          records_start_year=CPS_START_YEAR)
    assert calc.current_year == 2017
Beispiel #9
0
def test_get_calculator_cps(baseline, iit_reform):
    calc = get_micro_data.get_calculator(baseline=baseline,
                                         calculator_start_year=2017,
                                         reform=iit_reform,
                                         data='cps',
                                         gfactors=GrowFactors(),
                                         records_start_year=CPS_START_YEAR)
    assert calc.current_year == CPS_START_YEAR
Beispiel #10
0
def test_set_path():
    """
    Check that 'notapath.csv' is passed to taxcalc. An error
    containing 'notapath.csv' is sufficient proof for this
    """
    baseline = False
    start_year = 2016
    reform = {"II_em": {2017: 10000}}

    # In theory this path doesn't exist so there should be an IOError
    # But taxcalc checks if the path exists and if it doesn't, it tries
    # to read from an egg file. This raises a ValueError. At some point,
    # this could change. So I think it's best to catch both errors
    with pytest.raises((IOError, ValueError), match="notapath.csv"):
        get_micro_data.get_calculator(
            baseline, start_year, reform=reform,
            records_start_year=CPS_START_YEAR, data="notapath.csv")
Beispiel #11
0
def test_set_path():
    """
    Check that 'notapath.csv' is passed to taxcalc. An error
    containing 'notapath.csv' is sufficient proof for this
    """
    from ogusa import get_micro_data
    baseline = False
    start_year = 2016
    reform = {2017: {"_II_em": [10000]}}

    # In theory this path doesn't exist so there should be an IOError
    # But taxcalc checks if the path exists and if it doesn't, it tries
    # to read from an egg file. This raises a ValueError. At some point,
    # this could change. So I think it's best to catch both errors
    with pytest.raises((IOError, ValueError), match="notapath.csv"):
        get_micro_data.get_calculator(
            baseline, start_year, reform=reform,
            records_start_year=CPS_START_YEAR, data="notapath.csv")
Beispiel #12
0
def test_get_micro_data_get_calculator():

    reform = {
        2016: {
            '_II_rt1': [.09],
            '_II_rt2': [.135],
            '_II_rt3': [.225],
            '_II_rt4': [.252],
            '_II_rt5': [.297],
            '_II_rt6': [.315],
            '_II_rt7': [0.3564],
        },
    }

    calc = get_calculator(baseline=False,
                          calculator_start_year=2016,
                          reform=reform,
                          data=TAXDATA,
                          weights=WEIGHTS,
                          records_start_year=2009)
    assert calc.current_year == 2016

    reform = {
        2016: {
            '_II_rt1': [.09],
            '_II_rt2': [.135],
            '_II_rt3': [.225],
            '_II_rt4': [.252],
            '_II_rt5': [.297],
            '_II_rt6': [.315],
            '_II_rt7': [0.3564],
            '_factor_adjustment': [0.1]
        },
    }

    calc2 = get_calculator(baseline=False,
                           calculator_start_year=2016,
                           reform=reform,
                           data=TAXDATA,
                           weights=WEIGHTS,
                           records_start_year=2009)
    assert calc2.current_year == 2016
Beispiel #13
0
def test_get_micro_data_get_calculator():

    reform = {
        2017: {
            '_II_rt1': [.09],
            '_II_rt2': [.135],
            '_II_rt3': [.225],
            '_II_rt4': [.252],
            '_II_rt5': [.297],
            '_II_rt6': [.315],
            '_II_rt7': [0.3564],
        },
    }

    calc = get_calculator(baseline=False,
                          calculator_start_year=2017,
                          reform=reform,
                          data=TAXDATA,
                          weights=WEIGHTS,
                          records_start_year=RECORDS_START_YEAR)
    assert calc.current_year == 2017

    reform = {
        2017: {
            '_II_rt1': [.09],
            '_II_rt2': [.135],
            '_II_rt3': [.225],
            '_II_rt4': [.252],
            '_II_rt5': [.297],
            '_II_rt6': [.315],
            '_II_rt7': [0.3564]
        },
    }

    calc2 = get_calculator(baseline=False,
                           calculator_start_year=2017,
                           reform=reform,
                           data=TAXDATA,
                           weights=WEIGHTS,
                           records_start_year=RECORDS_START_YEAR)
    assert calc2.current_year == 2017
Beispiel #14
0
def test_cap_inc_mtr():
    '''
    Test of the get_micro_data.cap_inc_mtr() function
    '''
    calc1 = get_micro_data.get_calculator(
        baseline=True, calculator_start_year=2028, reform={},
        data='cps')
    calc1.advance_to_year(2028)
    expected = np.genfromtxt(os.path.join(
            CUR_PATH, 'test_io_data',
            'mtr_combined_capinc_for_tests.csv'), delimiter=',')
    test_data = get_micro_data.cap_inc_mtr(calc1)

    assert np.allclose(expected, test_data, equal_nan=True)
Beispiel #15
0
def test_cps():
    """
    Check that setting `data` to 'cps' uses cps data
    """
    baseline = False
    start_year = 2016
    reform = {"II_em": {2017: 10000}}

    calc = get_micro_data.get_calculator(
        baseline, start_year, reform=reform,
        records_start_year=CPS_START_YEAR, data="cps")
    # blind_head is only in the CPS file and e00700 is only in the PUF.
    # See taxcalc/records_variables.json
    assert (calc.array("blind_head").sum() > 0 and
            calc.array("e00700").sum() == 0)
Beispiel #16
0
def test_cps():
    """
    Check that setting `data` to 'cps' uses cps data
    """
    from ogusa import get_micro_data
    baseline = False
    start_year = 2016
    reform = {2017: {"_II_em": [10000]}}

    calc = get_micro_data.get_calculator(
        baseline, start_year, reform=reform,
        records_start_year=CPS_START_YEAR, data="cps")
    # blind_head is only in the CPS file and e00700 is only in the PUF.
    # See taxcalc/records_variables.json
    assert (calc.array("blind_head").sum() > 0 and
            calc.array("e00700").sum() == 0)
Beispiel #17
0
def test_get_micro_data_get_calculator():
    reform = {
        2017: {
            '_II_rt1': [.09],
            '_II_rt2': [.135],
            '_II_rt3': [.225],
            '_II_rt4': [.252],
            '_II_rt5': [.297],
            '_II_rt6': [.315],
            '_II_rt7': [0.3564],
        }, }

    calc = get_calculator(baseline=False, calculator_start_year=2017,
                          reform=reform, data=TAXDATA,
                          weights=WEIGHTS,
                          records_start_year=CPS_START_YEAR)
    assert calc.current_year == 2017
def test_get_calculator_puf_from_file():
    iit_reform = {
        "II_rt1": {2017: 0.09},
        "II_rt2": {2017: 0.135},
        "II_rt3": {2017: 0.225},
        "II_rt4": {2017: 0.252},
        "II_rt5": {2017: 0.297},
        "II_rt6": {2017: 0.315},
        "II_rt7": {2017: 0.3564},
    }
    calc = get_micro_data.get_calculator(
        baseline=False,
        calculator_start_year=2017,
        reform=iit_reform,
        data=PUF_PATH,
        records_start_year=PUF_START_YEAR,
    )
    assert calc.current_year == 2013
def test_taxcalc_advance():
    '''
    Test of the get_micro_data.taxcalc_advance() function

    Note that this test may fail if the Tax-Calculator is not v 2.4.0
    In that case, you can use the pickeld calculator object, however
    this is too large for GitHub, so it won't be available there.
    '''
    # calc1 = utils.safe_read_pickle(os.path.join(
    #         CUR_PATH, 'test_io_data', 'calc_object_for_tests.pkl'))
    calc1 = get_micro_data.get_calculator(
        baseline=True, calculator_start_year=2028, reform={},
        data='cps')
    expected_dict = utils.safe_read_pickle(os.path.join(
        CUR_PATH, 'test_io_data', 'tax_dict_for_tests.pkl'))
    test_dict = get_micro_data.taxcalc_advance(calc1, 2028)
    for k, v in test_dict.items():
        assert np.allclose(expected_dict[k], v, equal_nan=True)
def test_cap_inc_mtr():
    """
    Test of the get_micro_data.cap_inc_mtr() function

    Note that this test may fail if the Tax-Calculator is not v 3.2.1
    """
    calc1 = get_micro_data.get_calculator(
        baseline=True, calculator_start_year=2028, reform={}, data="cps"
    )
    calc1.advance_to_year(2028)
    expected = np.genfromtxt(
        os.path.join(
            CUR_PATH, "test_io_data", "mtr_combined_capinc_for_tests.csv"
        ),
        delimiter=",",
    )
    test_data = get_micro_data.cap_inc_mtr(calc1)

    assert np.allclose(expected, test_data, equal_nan=True)
def test_get_calculator_exception():
    iit_reform = {
        "II_rt1": {2017: 0.09},
        "II_rt2": {2017: 0.135},
        "II_rt3": {2017: 0.225},
        "II_rt4": {2017: 0.252},
        "II_rt5": {2017: 0.297},
        "II_rt6": {2017: 0.315},
        "II_rt7": {2017: 0.3564},
    }
    with pytest.raises(Exception):
        assert get_micro_data.get_calculator(
            baseline=False,
            calculator_start_year=TC_LAST_YEAR + 1,
            reform=iit_reform,
            data="cps",
            gfactors=GrowFactors(),
            records_start_year=CPS_START_YEAR,
        )
def test_cap_inc_mtr():
    '''
    Test of the get_micro_data.cap_inc_mtr() function

    Note that this test may fail if the Tax-Calculator is not v 2.4.0
    In that case, you can use the pickeld caculator object, however
    this is too large for GitHub, so it won't be available there.
    '''
    # calc1 = utils.safe_read_pickle(os.path.join(
    #         CUR_PATH, 'test_io_data', 'calc_object_for_tests.pkl'))
    calc1 = get_micro_data.get_calculator(
        baseline=True, calculator_start_year=2028, reform={},
        data='cps')
    calc1.advance_to_year(2028)
    expected = np.genfromtxt(os.path.join(
            CUR_PATH, 'test_io_data',
            'mtr_combined_capinc_for_tests.csv'), delimiter=',')
    test_data = get_micro_data.cap_inc_mtr(calc1)

    assert np.allclose(expected, test_data, equal_nan=True)