diff --git a/taxcalc/calculate.py b/taxcalc/calculate.py index 14f34ee48..63d1a4315 100644 --- a/taxcalc/calculate.py +++ b/taxcalc/calculate.py @@ -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 @@ -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 @@ -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, diff --git a/taxcalc/tests/test_utils.py b/taxcalc/tests/test_utils.py index e362847e7..ef57441e3 100644 --- a/taxcalc/tests/test_utils.py +++ b/taxcalc/tests/test_utils.py @@ -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 diff --git a/taxcalc/utils.py b/taxcalc/utils.py index 6f232fd69..cd1f7fc59 100644 --- a/taxcalc/utils.py +++ b/taxcalc/utils.py @@ -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. @@ -1457,6 +1457,17 @@ 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 @@ -1464,7 +1475,7 @@ def dec_graph_data(diff_table, year, hide_negative_incomes=True): # 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 @@ -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 @@ -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: