Skip to content

Commit

Permalink
Merge pull request #1906 from martinholmer/fix-arg-name
Browse files Browse the repository at this point in the history
Rename hide_*_incomes function arguments to clarify their effect
  • Loading branch information
martinholmer authored Mar 8, 2018
2 parents 8fc3308 + 4c11dbe commit 13a9a33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 3 additions & 3 deletions taxcalc/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def pch_graph(self, calc):
title='')
return fig

def decile_graph(self, calc, hide_negative_incomes=True):
def decile_graph(self, calc, hide_nonpositive_incomes=True):
"""
Create graph that shows percentage change in aftertax expanded
income (from going from policy in self to policy in calc) for
Expand All @@ -1008,7 +1008,7 @@ def decile_graph(self, calc, hide_negative_incomes=True):
where both self and calc have calculated taxes for this year
before being used by this method
hide_negative_incomes : boolean
hide_nonpositive_incomes : boolean
if True (which is the default), the bottom table bin containing
filing units with non-positive expanded_income is not shown in
the graph and the table bin containing filing units with positive
Expand All @@ -1033,7 +1033,7 @@ def decile_graph(self, calc, hide_negative_incomes=True):
tax_to_diff='combined')
# construct data for graph
data = dec_graph_data(diff_table, year=self.current_year,
hide_negative_incomes=hide_negative_incomes)
hide_nonpos_incomes=hide_nonpositive_incomes)
# construct figure from data
fig = dec_graph_plot(data,
width=850,
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def test_dec_qin_graph_plots(cps_subsample):
calc2.calc_all()
fig_dec_hide = calc1.decile_graph(calc2)
assert fig_dec_hide
fig_dec_show = calc1.decile_graph(calc2, hide_negative_incomes=False)
fig_dec_show = calc1.decile_graph(calc2, hide_nonpositive_incomes=False)
assert fig_dec_show


Expand Down
19 changes: 15 additions & 4 deletions taxcalc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ def bootstrap_se_ci(data, seed, num_samples, statistic, alpha):
return bsest


def dec_graph_data(diff_table, year, hide_negative_incomes=True):
def dec_graph_data(diff_table, year, hide_nonpos_incomes=True):
"""
Prepare data needed by dec_graph_plot utility function.
Expand All @@ -1457,14 +1457,25 @@ def dec_graph_data(diff_table, year, hide_negative_incomes=True):
year : integer
specifies calendar year of the data in the diff_table
hide_nonpos_incomes : boolean
if True (which is the default), the bottom table bin containing
filing units with non-positive expanded_income is not shown in
the graph and the table bin containing filing units with positive
expanded_income in the bottom decile is shown with its bar width
adjusted to the number of weighted filing units in bottom decile
who have positive expanded_income; if False, the bottom table bin
containing filing units with non-positive expanded_income is shown,
which may be misleading because the percentage change is correctly
calculated with a negative divisor.
Returns
-------
dictionary object suitable for passing to dec_graph_plot utility function
"""
# construct dictionary containing the bar data required by dec_graph_plot
bars = dict()
nbins = len(DECILE_ROW_NAMES)
if hide_negative_incomes:
if hide_nonpos_incomes:
first_bin = 1
else:
first_bin = 0
Expand All @@ -1478,7 +1489,7 @@ def dec_graph_data(diff_table, year, hide_negative_incomes=True):
bars[idx] = info
# construct dictionary containing bar data and auto-generated labels
data = dict()
data['hide_neg'] = hide_negative_incomes
data['hide_nonpos'] = hide_nonpos_incomes
bottom_count = diff_table['count'][0] + diff_table['count'][1]
data['neg_bar_size'] = diff_table['count'][0] / bottom_count
data['pos_bar_size'] = diff_table['count'][1] / bottom_count
Expand Down Expand Up @@ -1584,7 +1595,7 @@ def dec_graph_plot(data,
bval = data['bars'][idx]['value']
blabel = data['bars'][idx]['label']
bheight = barheight
if data['hide_neg']:
if data['hide_nonpos']:
if yidx == 0:
bheight *= data['pos_bar_size']
else:
Expand Down

0 comments on commit 13a9a33

Please sign in to comment.