Skip to content

Commit

Permalink
Merge pull request #27 from PSLmodels/bokeh-update
Browse files Browse the repository at this point in the history
Updates for bokeh 2.0.0 and taxcalc 2.8.0
  • Loading branch information
Peter-Metz authored Mar 13, 2020
2 parents 5311559 + 79af215 commit 9c18ffe
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 52 deletions.
92 changes: 52 additions & 40 deletions cs-config/cs_config/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ def liability_plot(df_base, df_reform, span, mtr_opt):
fig.yaxis.axis_label = "Tax Liabilities"
fig.yaxis.formatter = NumeralTickFormatter(format="$0,000")

filer_income = Span(location=span, dimension='height', line_color='black', line_dash='dotted', line_width=1.5)
filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=25, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size = "10pt")
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width', line_color='#bfbfbf', line_width=1.5)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)

iitax_base = fig.line(x="Axis", y="Individual Income Tax", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend="Individual Income Tax Liability", muted_alpha=0.1, source=df_base)
line_width=2, legend_label="Individual Income Tax Liability", muted_alpha=0.1, source=df_base)
payroll_base = fig.line(x="Axis", y="Payroll Tax", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend='Payroll Tax Liability', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Payroll Tax Liability', muted_alpha=0.1, source=df_base)

iitax_reform = fig.line(x="Axis", y="Individual Income Tax", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, line_dash='dashed', legend="Individual Income Tax Liability", muted_alpha=0.1, source=df_reform)
line_width=2, line_dash='dashed', legend_label="Individual Income Tax Liability", muted_alpha=0.1, source=df_reform)
payroll_reform = fig.line(x="Axis", y="Payroll Tax", line_color='#abdda4', muted_color='#abdda4',
line_width=2, line_dash='dashed', legend='Payroll Tax Liability', muted_alpha=0.1, source=df_reform)
line_width=2, line_dash='dashed', legend_label='Payroll Tax Liability', muted_alpha=0.1, source=df_reform)

iitax_base.muted = False
payroll_base.muted = False
Expand All @@ -44,15 +46,17 @@ def liability_plot(df_base, df_reform, span, mtr_opt):
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
callback=base_callback, active=True)
active=True)
base_callback.args = {"toggle": base_toggle, "object1": iitax_base,
"object2": payroll_base}
base_toggle.js_on_change('active', base_callback)

reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
callback=reform_callback, active=True)
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": iitax_reform,
"object2": payroll_reform}
reform_toggle.js_on_change('active', reform_callback)

fig.xaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.xaxis.axis_label = mtr_opt
Expand All @@ -78,36 +82,38 @@ def rate_plot(df_base, df_reform, span, mtr_opt):
df_reform = ColumnDataSource(df_reform)
tools = "pan, zoom_in, zoom_out, reset"
fig = figure(plot_width=600, plot_height=500,
x_range=(-10000, 300000), y_range=(-0.3, 0.5), tools=tools, active_drag="pan")
x_range=(-10000, 300000), y_range=(-0.3, 0.5), tools=tools, active_drag="pan")
fig.yaxis.axis_label = "Tax Rate"
fig.yaxis.formatter = NumeralTickFormatter(format="0%")

filer_income = Span(location=span, dimension='height', line_color='black', line_dash='dotted', line_width=1.5)

filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=25, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size = "10pt")
filer_income_label = Label(x=span, y=25, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width', line_color='#bfbfbf', line_width=1.5)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)

iitax_atr_base = fig.line(x="Axis", y="IATR", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend="Income Tax Average Rate", muted_alpha=0.1, source=df_base)
line_width=2, legend_label="Income Tax Average Rate", muted_alpha=0.1, source=df_base)
payroll_atr_base = fig.line(x="Axis", y="PATR", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend='Payroll Tax Average Rate', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Payroll Tax Average Rate', muted_alpha=0.1, source=df_base)
iitax_mtr_base = fig.line(x="Axis", y="Income Tax MTR", line_color='#fdae61', muted_color='#fdae61',
line_width=2, legend="Income Tax Marginal Rate", muted_alpha=0.1, source=df_base)
line_width=2, legend_label="Income Tax Marginal Rate", muted_alpha=0.1, source=df_base)
payroll_mtr_base = fig.line(x="Axis", y="Payroll Tax MTR", line_color='#d7191c', muted_color='#d7191c',
line_width=2, legend='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_base)

iitax_atr_reform = fig.line(x="Axis", y="IATR", line_color='#2b83ba', muted_color='#2b83ba', line_width=2,
line_dash='dashed', legend="Income Tax Average Rate", muted_alpha=0.1, source=df_reform)
line_dash='dashed', legend_label="Income Tax Average Rate", muted_alpha=0.1, source=df_reform)
payroll_atr_reform = fig.line(x="Axis", y="PATR", line_color='#abdda4', muted_color='#abdda4', line_width=2,
line_dash='dashed', legend='Payroll Tax Average Rate', muted_alpha=0.1, source=df_reform)
line_dash='dashed', legend_label='Payroll Tax Average Rate', muted_alpha=0.1, source=df_reform)
iitax_mtr_reform = fig.line(x="Axis", y="Income Tax MTR", line_color='#fdae61', muted_color='#fdae61',
line_width=2, line_dash='dashed', legend="Income Tax Marginal Rate", muted_alpha=0.1, source=df_reform)
line_width=2, line_dash='dashed', legend_label="Income Tax Marginal Rate", muted_alpha=0.1, source=df_reform)
payroll_mtr_reform = fig.line(x="Axis", y="Payroll Tax MTR", line_color='#d7191c', muted_color='#d7191c',
line_width=2, line_dash='dashed', legend='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_reform)
line_width=2, line_dash='dashed', legend_label='Payroll Tax Marginal Rate', muted_alpha=0.1, source=df_reform)

iitax_atr_base.muted = False
iitax_mtr_base.muted = True
Expand All @@ -126,17 +132,19 @@ def rate_plot(df_base, df_reform, span, mtr_opt):
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
callback=base_callback, active=True)
active=True)
base_callback.args = {"toggle": base_toggle, "object1": iitax_atr_base,
"object2": payroll_atr_base, "object3": iitax_mtr_base,
"object4": payroll_mtr_base}
base_toggle.js_on_change('active', base_callback)

reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
callback=reform_callback, active=True)
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": iitax_atr_reform,
"object2": payroll_atr_reform, "object3": iitax_mtr_reform,
"object4": payroll_mtr_reform}
reform_toggle.js_on_change('active', reform_callback)

fig.xaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.xaxis.axis_label = mtr_opt
Expand Down Expand Up @@ -164,32 +172,34 @@ def credit_plot(df_base, df_reform, span, mtr_opt):
fig = figure(plot_width=600, plot_height=500, x_range=(
-2500, 70000), tools=tools, active_drag="pan")

filer_income = Span(location=span, dimension='height', line_color='black', line_dash='dotted', line_width=1.5)
filer_income = Span(location=span, dimension='height',
line_color='black', line_dash='dotted', line_width=1.5)
fig.add_layout(filer_income)
label_format = f'{span:,}'
filer_income_label = Label(x=span, y=45, y_units='screen', x_offset=10, text="{}: $".format(mtr_opt) + label_format,
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size = "10pt")
text_color='#303030', text_font="arial", text_font_style="italic", text_font_size="10pt")
fig.add_layout(filer_income_label)
axis = Span(location=0, dimension='width', line_color='#bfbfbf', line_width=1.5)
axis = Span(location=0, dimension='width',
line_color='#bfbfbf', line_width=1.5)
fig.add_layout(axis)

eitc_base = fig.line(x="Axis", y="EITC", line_color='#2b83ba', muted_color='#2b83ba',
line_width=2, legend="Earned Income Tax Credit", muted_alpha=0.1, source=df_base)
line_width=2, legend_label="Earned Income Tax Credit", muted_alpha=0.1, source=df_base)
ctc_base = fig.line(x="Axis", y="CTC", line_color='#abdda4', muted_color='#abdda4',
line_width=2, legend='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_base)
ctc_refund_base = fig.line(x="Axis", y="CTC Refundable", line_color='#fdae61', muted_color='#fdae61',
line_width=2, legend='Refundable Child Tax Credit', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Refundable Child Tax Credit', muted_alpha=0.1, source=df_base)
cdcc_base = fig.line(x="Axis", y="Child care credit", line_color='#d7191c', muted_color='#d7191c',
line_width=2, legend='Child and Dependent Care Credit', muted_alpha=0.1, source=df_base)
line_width=2, legend_label='Child and Dependent Care Credit', muted_alpha=0.1, source=df_base)

eitc_reform = fig.line(x="Axis", y="EITC", line_color='#2b83ba', muted_color='#2b83ba', line_width=2,
line_dash='dashed', legend="Earned Income Tax Credit", muted_alpha=0.1, source=df_reform)
line_dash='dashed', legend_label="Earned Income Tax Credit", muted_alpha=0.1, source=df_reform)
ctc_reform = fig.line(x="Axis", y="CTC", line_color='#abdda4', muted_color='#abdda4', line_width=2,
line_dash='dashed', legend='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
line_dash='dashed', legend_label='Nonrefundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
ctc_refund_reform = fig.line(x="Axis", y="CTC Refundable", line_color='#fdae61', muted_color='#fdae61',
line_width=2, line_dash='dashed', legend='Refundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
line_width=2, line_dash='dashed', legend_label='Refundable Child Tax Credit', muted_alpha=0.1, source=df_reform)
cdcc_reform = fig.line(x="Axis", y="Child care credit", line_color='#d7191c', muted_color='#d7191c', line_width=2,
line_dash='dashed', legend='Child and Dependent Care Credit', muted_alpha=0.1, source=df_reform)
line_dash='dashed', legend_label='Child and Dependent Care Credit', muted_alpha=0.1, source=df_reform)

ctc_base.muted = True
ctc_refund_base.muted = True
Expand All @@ -206,17 +216,19 @@ def credit_plot(df_base, df_reform, span, mtr_opt):
"""
base_callback = CustomJS(code=plot_js, args={})
base_toggle = Toggle(label="Base (Solid)", button_type="default",
callback=base_callback, active=True)
active=True)
base_callback.args = {"toggle": base_toggle, "object1": eitc_base,
"object2": cdcc_base, "object3": ctc_base,
"object4": ctc_refund_base}
base_toggle.js_on_change('active', base_callback)

reform_callback = CustomJS(code=plot_js, args={})
reform_toggle = Toggle(label="Reform (Dashed)", button_type="default",
callback=reform_callback, active=True)
active=True)
reform_callback.args = {"toggle": reform_toggle, "object1": eitc_reform,
"object2": cdcc_reform, "object3": ctc_reform,
"object4": ctc_refund_reform}
reform_toggle.js_on_change('active', reform_callback)

fig.yaxis.formatter = NumeralTickFormatter(format="$0,000")
fig.yaxis.axis_label = "Tax Credits"
Expand All @@ -236,4 +248,4 @@ def credit_plot(df_base, df_reform, span, mtr_opt):
"data": data
}

return outputs
return outputs
4 changes: 2 additions & 2 deletions cs-config/cs_config/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def test_convert_adj():

assert res == {
"STD": {
2019: [0, 1, 12268.8, 18403.2, 24537.6]
2019: [0, 1, 12200.0, 18350.0, 24400.0]
},
"EITC_c": {
2019: [1000.0, 3538.53, 5844.04, 6575.05]
2019: [1000.0, 3526.0, 5828.0, 6557.0]
},
"BEN_ssi_repeal": {
2019: True
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ channels:
- conda-forge
dependencies:
- python>=3.6.5
- taxcalc<2.8.0
- taxcalc
- behresp>=0.9.0
- pandas>=0.23
- numpy>=1.13
- paramtools>=0.10.1
- ipython
- pytest
- dask
- bokeh<2.0.0
- bokeh
- markdown
- pip
- pip:
Expand Down
4 changes: 2 additions & 2 deletions taxcrunch/tests/expected_calc_table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Adjusted Gross Income (AGI),100000.0,100000.0,100001.0
Unemployment Insurance in AGI,0.0,0.0,0.0
Social Security in AGI,0.0,0.0,0.0
Itemized Deductions,0.0,0.0,0.0
Taxable Income,87731.2,89115.07,89116.07
Taxable Income,87800.0,89115.07,89116.07
Child Tax Credit (CTC),0.0,0.0,0.0
CTC Refundable,0.0,0.0,0.0
Child Care Credit,0.0,0.0,0.0
Earned Income Tax Credit (EITC),0.0,0.0,0.0
Alternative Minimum Tax (AMT) Taxable Income,100000.0,100000.0,100001.0
AMT Liability,0.0,0.0,0.0
Net Investment Income Tax,0.0,0.0,0.0
Income Tax Before Credits,15217.07,17818.82,17819.07
Income Tax Before Credits,15246.5,17818.82,17819.07
12 changes: 6 additions & 6 deletions taxcrunch/tests/expected_multi_table.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
,ID,Individual Income Tax,Payroll Tax,Wages,AGI,UI in AGI,OASDI in AGI,Itemized Deductions,Taxable Inc,CTC,CTC Refundable,Child care credit,EITC,AMT Taxable Income,AMT Liability,Net Investment Income Tax,Income Tax Before Credits,FICA,Payroll Tax MTR,Income Tax MTR,Combined MTR
0,1.0,23397.147199999996,21137.961919999998,160000.0,164500.0,0.0,0.0,0.0,146096.8,4000.0,0.0,0.0,0.0,164500.0,0.0,0.0,27397.147199999996,21137.961919999998,0.02899999999499414,0.240000000121654,0.26900000011664815
1,2.0,-5385.396063999999,7267.5,47500.0,47800.0,0.0,0.0,0.0,23262.4,2365.9536000000003,3634.0463999999997,0.0,1751.3496639999994,47800.0,0.0,0.0,2365.9536000000003,7267.5,0.15300000004572212,0.3305999999611231,0.4836000000068452
2,3.0,10049.4088,10710.0,70000.0,80000.0,0.0,0.0,0.0,67731.2,0.0,0.0,0.0,0.0,80000.0,0.0,0.0,10049.4088,10710.0,0.15299999995477265,0.21999999989930075,0.37300000003597233
3,4.0,6538.8175999999985,18819.0,123000.0,124200.0,0.0,0.0,0.0,99662.4,6000.0,0.0,0.0,0.0,124200.0,0.0,0.0,13538.817599999998,18819.0,0.1530000001366716,0.22000000026309863,0.3730000003997702
4,5.0,40659.7456,23747.961919999998,250000.0,251200.0,0.0,0.0,0.0,226662.4,2000.0,0.0,0.0,0.0,251200.0,0.0,45.6,42614.1456,23747.961919999998,0.0380000001314329,0.23999999975785613,0.2780000002530869
0,1.0,23425.0,21119.6,160000.0,164500.0,0.0,0.0,0.0,146150.0,4000.0,0.0,0.0,0.0,164500.0,0.0,0.0,27425.0,21119.6,0.02899999999499414,0.240000000121654,0.26900000011664815
1,2.0,-5333.411999999999,7267.5,47500.0,47800.0,0.0,0.0,0.0,23400.0,2384.0,3616.0,0.0,1717.4119999999994,47800.0,0.0,0.0,2384.0,7267.5,0.15300000004572212,0.3305999999611231,0.4836000000068452
2,3.0,10074.5,10710.0,70000.0,80000.0,0.0,0.0,0.0,67800.0,0.0,0.0,0.0,0.0,80000.0,0.0,0.0,10074.5,10710.0,0.15299999995477265,0.21999999989930075,0.37299999967217445
3,4.0,6589.0,18819.0,123000.0,124200.0,0.0,0.0,0.0,99800.0,6000.0,0.0,0.0,0.0,124200.0,0.0,0.0,13589.0,18819.0,0.1530000001366716,0.21999999989930075,0.37300000003597233
4,5.0,40718.6,23729.6,250000.0,251200.0,0.0,0.0,0.0,226800.0,2000.0,0.0,0.0,0.0,251200.0,0.0,45.6,42673.0,23729.6,0.0380000001314329,0.23999999975785613,0.27799999952549115
5,6.0,0.0,1683.0,11000.0,11000.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,11000.0,0.0,0.0,0.0,1683.0,0.15300000000024738,0.0,0.15300000000024738
6,7.0,-3402.289388,5967.0,39000.0,39250.0,0.0,0.0,0.0,20846.8,2193.5231999999996,1806.4768000000004,0.0,1595.8125879999998,39250.0,0.0,0.0,2193.5231999999996,5967.0,0.15300000004572212,0.33060000014302204,0.48360000018874416
6,7.0,-3368.6679999999997,5967.0,39000.0,39250.0,0.0,0.0,0.0,20900.0,2201.0,1799.0,0.0,1569.6679999999997,39250.0,0.0,0.0,2201.0,5967.0,0.15300000004572212,0.33060000000659784,0.48360000005231996

0 comments on commit 9c18ffe

Please sign in to comment.