Tax-Brain Report Utilities#

report_utils

taxbrain.report_utils#

Helper Functions for creating the automated reports

taxbrain.report_utils.behavioral_assumptions(tb)[source]#

Return list of behavioral assumptions used

Parameters:

tb (TaxBrain object) – instance of TaxBrain object for analysis

Returns:

assumptions – list of behavioral assumptions used

Return type:

list

taxbrain.report_utils.consumption_assumptions(tb)[source]#

Create table of consumption assumptions used in analysis

Parameters:

tb (TaxBrain object) – instance of TaxBrain object for analysis

Returns:

md_tables – table of consumption assumptions for report

Return type:

str

taxbrain.report_utils.convert_params(params)[source]#

Convert ParamTools style parameter inputs to traditional taxcalc style parameters for report policy table creation

Parameters:

params (dict) – ParamTools style reform dictionary

Returns:

reform – a dictionary in traditional taxcalc style

Return type:

dict

taxbrain.report_utils.convert_table(df, tablefmt: str = 'pipe') str[source]#

Convert pandas DataFrame to Markdown style table

Parameters:

df (Pandas DataFrame) – DataFrame to convert

Returns:

String that is a formatted markdown table

Return type:

str

taxbrain.report_utils.date()[source]#

Return formatted date

Parameters:

None

Return type:

None

taxbrain.report_utils.dollar_str_formatting(val: int | float) str[source]#

Format dollar figures into $val trillion, $val billion, etc.

Parameters:

val (float) – revenue amount

Returns:

formatted dollar figure

Return type:

str

taxbrain.report_utils.form_baseline_intro(current_law)[source]#

Form final sentence of introduction paragraph

Parameters:

current_law (bool) – whether report is for the current law baseline

Returns:

text or intro of baseline summary

Return type:

str

taxbrain.report_utils.form_intro(pol_areas, description=None)[source]#

Form the introduction line

Parameters:
  • pol_areas (list) – list of all the policy areas included in the reform used to create a description of the reform

  • description (str) – user provided description of the reform

Returns:

introduction text for report

Return type:

str

taxbrain.report_utils.growth_assumptions(tb)[source]#

Create a table with all of the growth assumptions used in the analysis

Parameters:

tb (TaxBrain object) – instance of TaxBrain object for analysis

Returns:

md_tables – table of growth assumptions for report

Return type:

str

taxbrain.report_utils.largest_tax_change(diff)[source]#

Function to find the largest change in tax liability

Parameters:

diff (Pandas DataFrame) – Differences table created by taxbrain

Returns:

  • largest_change_group (str) – string relating group with the largest change

  • largest_change_str (str) – string relating size of largest change

taxbrain.report_utils.md_to_pdf(md_text, outputfile_path)[source]#

Convert Markdown version of report to a PDF. Returns bytes that can be saved as a PDF

Parameters:
  • md_text (str) – report template written in markdown

  • outputfile_path (str) – path to where the final file sohould be written

Returns:

Markdown text is saved as a PDF and the HTML used to create the report

Return type:

None

taxbrain.report_utils.notable_changes(tb, threshold: float) str[source]#

Find any notable changes in certain variables. “Notable” is defined as a percentage change above the given threshold.

Parameters:
  • tb (TaxBrain object) – instance of TaxBrain object for analysis

  • threshold (float) – Percentage change in an aggregate variable for it to be considered notable

Returns:

section – text for section on notable changes

Return type:

str

taxbrain.report_utils.policy_table(params)[source]#

Create a table showing the policy parameters in a reform and their default value

Parameters:

params (dict) – policy parameters being implemented

Returns:

md_tables – String containing a markdown style table that summarized the given parameters

Return type:

str

taxbrain.report_utils.write_text(template_path, **kwargs)[source]#

Fill in text with specified template

Parameters:

template_path (str) – path to read template from

Returns:

rendered – rendered template

Return type:

str