Skip to content

Commit

Permalink
Merge pull request #58 from jdebacker/cs_updates
Browse files Browse the repository at this point in the history
Updates for dependency compatibility
  • Loading branch information
jdebacker authored Feb 16, 2024
2 parents 5efcf9f + 53e2000 commit a891a37
Show file tree
Hide file tree
Showing 18 changed files with 641 additions and 286 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .git-blame-ignore-revs
# ignore initial move to black formatting
0c5478bfb211de34346e5b92d5a298e371b8b1bd
44 changes: 44 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build Package and Test Source Code [Python 3.9, 3.10, 3.11]

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11"]

steps:
- name: Checkout
uses: actions/checkout@master
with:
persist-credentials: false
- name: Setup Miniconda using Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: taxcrunch-env
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
auto-activate-base: false
- name: Build
shell: bash -l {0}
run: |
pip install -e .
pip install pytest-cov
pip install pytest-pycodestyle
- name: Test
shell: bash -l {0}
working-directory: ./
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cs-config/cs_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .functions import *
from .functions import *
57 changes: 35 additions & 22 deletions cs-config/cs_config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,60 @@
"labels": {
"year": {
"type": "int",
"validators": {
"choice": {"choices": [yr for yr in range(2013, 2030 + 1)]}
},
},
"MARS": {
"type": "str",
"validators": {
"choice": {
"choices": [
yr for yr in range(2013, 2030 + 1)
"single",
"mjoint",
"mseparate",
"headhh",
"widow",
]
}
}
},
"MARS": {
"type": "str",
"validators": {"choice": {"choices": ["single", "mjoint",
"mseparate", "headhh",
"widow"]}}
},
},
"idedtype": {
"type": "str",
"validators": {"choice": {"choices": ["med", "sltx", "retx", "cas",
"misc", "int", "char"]}}
"validators": {
"choice": {
"choices": [
"med",
"sltx",
"retx",
"cas",
"misc",
"int",
"char",
]
}
},
},
"EIC": {
"type": "str",
"validators": {"choice": {"choices": ["0kids", "1kid",
"2kids", "3+kids"]}}
"validators": {
"choice": {"choices": ["0kids", "1kid", "2kids", "3+kids"]}
},
},
"data_source": {
"type": "str",
"validators": {"choice": {"choices": ["PUF", "CPS", "other"]}}
}
"validators": {"choice": {"choices": ["PUF", "CPS", "other"]}},
},
},
"additional_members": {
"section_1": {"type": "str"},
"section_2": {"type": "str"},
"start_year": {"type": "int"},
"checkbox": {"type": "bool"}
}
"checkbox": {"type": "bool"},
},
}


class MetaParameters(paramtools.Parameters):
array_first = True
defaults = {
Expand All @@ -51,11 +68,7 @@ class MetaParameters(paramtools.Parameters):
"type": "int",
"value": 2019,
"validators": {
"choice": {
"choices": [
yr for yr in range(2013, 2030 + 1)
]
}
}
"choice": {"choices": [yr for yr in range(2013, 2030 + 1)]}
},
}
}
83 changes: 46 additions & 37 deletions cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def fix_checkbox(params):

return pol_params


def get_version():
version = taxcrunch.__version__
return f"Tax-Cruncher v{version}"
Expand All @@ -51,14 +52,15 @@ def get_inputs(meta_params_dict):
params = CruncherParams()
policy_params = Policy()

policy_params.set_state(
year=metaparams.year.tolist())
policy_params.set_state(year=metaparams.year.tolist())

policy_params.array_first = False
# Hack to work smoothly with convert_policy_defaults since
# it expects a data_source attribute.
metaparams.data_source = "CPS"
filtered_pol_params = inputs.convert_policy_defaults(metaparams, policy_params)
filtered_pol_params = inputs.convert_policy_defaults(
metaparams, policy_params
)

keep = [
"mstat",
Expand Down Expand Up @@ -88,13 +90,15 @@ def get_inputs(meta_params_dict):
"w2paid",
"qualprop",
"mtr_options",
"schema"
"schema",
]
cruncher_dict = params.dump()

default_params = {
"Tax Information": {k: v for k, v in cruncher_dict.items() if k in keep},
"Policy": filtered_pol_params
"Tax Information": {
k: v for k, v in cruncher_dict.items() if k in keep
},
"Policy": filtered_pol_params,
}

meta = metaparams.dump()
Expand Down Expand Up @@ -136,52 +140,51 @@ def run_model(meta_params_dict, adjustment):
increments = pd.DataFrame(list(range(0, 2000000, 200)))

# use Calculation Option to determine what var to increment
if mtr_opt == 'Taxpayer Earnings':
span = int(ivar[9])
if mtr_opt == "Taxpayer Earnings":
span = int(ivar[9].values[0])
df[9] = increments
elif mtr_opt == 'Spouse Earnings':
span = int(ivar[10])
elif mtr_opt == "Spouse Earnings":
span = int(ivar[10].values[0])
df[10] = increments
elif mtr_opt == 'Qualified Dividends':
span = int(ivar[11])
elif mtr_opt == "Qualified Dividends":
span = int(ivar[11].values[0])
df[11] = increments
elif mtr_opt == 'Interest Received':
span = int(ivar[12])
elif mtr_opt == "Interest Received":
span = int(ivar[12].values[0])
df[12] = increments
elif mtr_opt == 'Short Term Gains':
span = int(ivar[13])
elif mtr_opt == "Short Term Gains":
span = int(ivar[13].values[0])
df[13] = increments
elif mtr_opt == 'Long Term Gains':
span = int(ivar[14])
elif mtr_opt == "Long Term Gains":
span = int(ivar[14].values[0])
df[14] = increments
elif mtr_opt == 'Business Income':
span = int(ivar[15])
elif mtr_opt == "Business Income":
span = int(ivar[15].values[0])
df[15] = increments
elif mtr_opt == 'Pensions':
span = int(ivar[21])
elif mtr_opt == "Pensions":
span = int(ivar[21].values[0])
df[21] = increments
elif mtr_opt == 'Gross Social Security Benefits':
span = int(ivar[22])
elif mtr_opt == "Gross Social Security Benefits":
span = int(ivar[22].values[0])
df[22] = increments
elif mtr_opt == 'Real Estate Taxes Paid':
span = int(ivar[24])
elif mtr_opt == "Real Estate Taxes Paid":
span = int(ivar[24].values[0])
df[24] = increments
elif mtr_opt == 'Mortgage':
span = int(ivar[27])
elif mtr_opt == "Mortgage":
span = int(ivar[27].values[0])
df[27] = increments


b = Batch(df)
df_base = b.create_table()
df_reform = b.create_table(policy_mods)

# compute average tax rates
df_base['IATR'] = df_base['Individual Income Tax'] / df_base['AGI']
df_base['PATR'] = df_base['Payroll Tax'] / df_base['AGI']
df_reform['IATR'] = df_reform['Individual Income Tax'] / df_reform['AGI']
df_reform['PATR'] = df_reform['Payroll Tax'] / df_reform['AGI']
df_base['Axis'] = increments
df_reform['Axis'] = increments
df_base["IATR"] = df_base["Individual Income Tax"] / df_base["AGI"]
df_base["PATR"] = df_base["Payroll Tax"] / df_base["AGI"]
df_reform["IATR"] = df_reform["Individual Income Tax"] / df_reform["AGI"]
df_reform["PATR"] = df_reform["Payroll Tax"] / df_reform["AGI"]
df_base["Axis"] = increments
df_reform["Axis"] = increments

return comp_output(crunch, df_base, df_reform, span, mtr_opt)

Expand All @@ -204,8 +207,14 @@ def comp_output(crunch, df_base, df_reform, span, mtr_opt):

comp_dict = {
"renderable": [
{"media_type": "table", "title": "Basic Liabilities", "data": table_basic},
liabilities, rates, credits,
{
"media_type": "table",
"title": "Basic Liabilities",
"data": table_basic,
},
liabilities,
rates,
credits,
{
"media_type": "table",
"title": "Calculation of Liabilities",
Expand Down
6 changes: 4 additions & 2 deletions cs-config/cs_config/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from paramtools import Parameters


def convert_policy_defaults(meta_params: Parameters, policy_params: Parameters):
def convert_policy_defaults(
meta_params: Parameters, policy_params: Parameters
):
"""
Convert defaults for taxcalc's Policy class to work with C/S.
"""
Expand Down Expand Up @@ -82,7 +84,7 @@ def convert_indexed_to_checkbox(defaults: dict):
new_defaults["schema"] = data

elif data["indexable"] and data.get("indexed", None) is True:
new_defaults[param] = dict(data, checkbox= True)
new_defaults[param] = dict(data, checkbox=True)

elif data["indexable"] and not data.get("indexed", None) is False:
new_defaults[param] = dict(data, checkbox=False)
Expand Down
Loading

0 comments on commit a891a37

Please sign in to comment.