Tax-Calculator Public API

The Tax-Calculator’s core capabilities are in the Python package called taxcalc, the source code for which is located in the tax-calculator/taxcalc directory tree.

Here we provide a high-level view of the public API of the taxcalc conda package with links to the source code. This high-level view is organized around the modules in the taxcalc package. Below is a list of the taxcalc package modules (in alphabetical order) with documentation about how to call each public class method and function. There is also a link to the source code for each documented member. However, it may be more convenient to access this list interactively via the alphabetical Index of taxcalc members.

Developers who want to use Tax-Calculator capabilities in their own projects should restrict themselves to using this public API. All other Tax-Calculator members are private and subject to change without advance notice.

taxcalc.Behavior

class taxcalc.Behavior(behavior_dict=None, start_year=2013, num_years=15)[source]

Behavior is a subclass of the abstract ParametersBase class, and therefore, inherits its methods (none of which are shown here).

Constructor for elasticity-based behavioral-response class.

Parameters:
  • behavior_dict (dictionary of PARAM:DESCRIPTION pairs) – dictionary of behavioral-response elasticities; if None, default elasticities are read from the behavior.json file.
  • start_year (integer) – first calendar year for behavioral-response elasticities.
  • num_years (integer) – number of calendar years for which to specify elasticity values beginning with start_year.
Raises:

ValueError: – if behavior_dict is neither None nor a dictionary. if num_years is less than one.

Returns:

class instance

Return type:

Behavior

_validate_parameter_values()[source]

Check that all behavioral-response parameters have valid values.

has_any_response()[source]

Returns true if any behavioral-response elasticity is non-zero in any year; returns false if all elasticities are zero in all years.

has_response()[source]

Returns true if any behavioral-response elasticity is non-zero for the current_year; returns false if all elasticities are zero.

static response(calc_x, calc_y)[source]

Implements TaxBrain “Partial Equilibrium Simulation” dynamic analysis.

Modify calc_y records to account for behavioral responses that arise
from the policy reform that involves moving from calc_x.policy to calc_y.policy. Neither calc_x nor calc_y need to have had calc_all() executed before calling the Behavior.response(calc_x, calc_y) method.
Returns new Calculator object — a deepcopy of calc_y — that
incorporates behavioral responses to the reform.
Note: the use here of a dollar-change income elasticity (rather than
a proportional-change elasticity) is consistent with Feldstein and Feenberg, “The Taxation of Two Earner Families”, NBER Working Paper No. 5155 (June 1995). A proportional-change elasticity was used by Gruber and Saez, “The elasticity of taxable income: evidence and implications”, Journal of Public Economics 84:1-32 (2002) [see equation 2 on page 10].
Note: the nature of the capital-gains elasticity used here is similar
to that used in Joint Committee on Taxation, “New Evidence on the Tax Elasticity of Capital Gains: A Joint Working Paper of the Staff of the Joint Committee on Taxation and the Congressional Budget Office”, (JCX-56-12), June 2012. In particular, the elasticity use here is equivalent to the term inside the square brackets on the right-hand side of equation (4) on page 11 — not the epsilon variable on the left-hand side of equation (4), which is equal to the elasticity used here times the weighted average marginal tax rate on long-term capital gains. So, the JCT-CBO estimate of -0.792 for the epsilon elasticity (see JCT-CBO, Table 5) translates into a much larger absolute value for the _BE_cg semi-elasticity used by Tax-Calculator. To calculate the elasticity from a semi-elasticity, we multiply by MTRs from TC and weight by shares of taxable gains. To avoid those with zero MTRs, we restrict this to the top 40% of tax units by AGI. Using this method, a semi-elasticity of -3.45 corresponds to a tax rate elasticity of -0.792.
update_behavior(revisions)[source]

Update behavior for given revisions, a dictionary consisting of one or more year:modification dictionaries. For example: {2014: {‘_BE_sub’: [0.4, 0.3]}} Also checks for valid elasticity values in revisions dictionary.

Note that this method uses the specified revisions to update the default elasticity values, so use this method just once rather than calling it sequentially in an attempt to update elasticities in several steps.

taxcalc.Calculator

class taxcalc.Calculator(policy=None, records=None, verbose=True, sync_years=True, consumption=None, behavior=None)[source]

Constructor for the Calculator class.

Parameters:
  • policy (Policy class object) – this argument must be specified and object is copied for internal use
  • records (Records class object) – this argument must be specified and object is copied for internal use
  • verbose (boolean) – specifies whether or not to write to stdout data-loaded and data-extrapolated progress reports; default value is true.
  • sync_years (boolean) – specifies whether or not to synchronize policy year and records year; default value is true.
  • consumption (Consumption class object) – specifies consumption response assumptions used to calculate “effective” marginal tax rates; default is None, which implies no consumption responses assumed in marginal tax rate calculations; when argument is an object it is copied for internal use
  • behavior (Behavior class object) – specifies behavioral responses used by Calculator; default is None, which implies no behavioral responses to policy reform; when argument is an object it is copied for internal use
Raises:

ValueError: – if parameters are not the appropriate type.

Returns:

class instance

Return type:

Calculator

Notes

The most efficient way to specify current-law and reform Calculator objects is as follows:

pol = Policy() rec = Records() calc1 = Calculator(policy=pol, records=rec) # current-law pol.implement_reform(…) calc2 = Calculator(policy=pol, records=rec) # reform

All calculations are done on the internal copies of the Policy and Records objects passed to each of the two Calculator constructors.

advance_to_year(year)[source]

The advance_to_year function gives an optional way of implementing increment year functionality by immediately specifying the year as input. New year must be at least the current year.

calc_all(zero_out_calc_vars=False)[source]

Call all tax-calculation functions.

current_law_version()[source]

Return Calculator object same as self except with current-law policy.

current_year

Calculator class current calendar year property.

data_year

Calculator class initial (i.e., first) records data year property.

increment_year()[source]

Advance all objects to next year.

mtr(variable_str='e00200p', negative_finite_diff=False, zero_out_calculated_vars=False, wrt_full_compensation=True)[source]

Calculates the marginal payroll, individual income, and combined tax rates for every tax filing unit.

The marginal tax rates are approximated as the change in tax liability caused by a small increase (the finite_diff) in the variable specified by the variable_str divided by that small increase in the variable, when wrt_full_compensation is false.

If wrt_full_compensation is true, then the marginal tax rates are computed as the change in tax liability divided by the change in total compensation caused by the small increase in the variable (where the change in total compensation is the sum of the small increase in the variable and any increase in the employer share of payroll taxes caused by the small increase in the variable).

If using ‘e00200s’ as variable_str, the marginal tax rate for all records where MARS != 2 will be missing. If you want to perform a function such as np.mean() on the returned arrays, you will need to account for this.

Parameters:
  • variable_str (string) – specifies type of income or expense that is increased to compute the marginal tax rates. See Notes for list of valid variables.
  • negative_finite_diff (boolean) – specifies whether or not marginal tax rates are computed by subtracting (rather than adding) a small finite_diff amount to the specified variable.
  • zero_out_calculated_vars (boolean) – specifies value of zero_out_calc_vars parameter used in calls of Calculator.calc_all() method.
  • wrt_full_compensation (boolean) – specifies whether or not marginal tax rates on earned income are computed with respect to (wrt) changes in total compensation that includes the employer share of OASDI and HI payroll taxes.
Returns:

  • mtr_payrolltax (an array of marginal payroll tax rates.)
  • mtr_incometax (an array of marginal individual income tax rates.)
  • mtr_combined (an array of marginal combined tax rates, which is) – the sum of mtr_payrolltax and mtr_incometax.

Notes

Valid variable_str values are: ‘e00200p’, taxpayer wage/salary earnings (also included in e00200); ‘e00200s’, spouse wage/salary earnings (also included in e00200); ‘e00900p’, taxpayer Schedule C self-employment income (also in e00900); ‘e00300’, taxable interest income; ‘e00400’, federally-tax-exempt interest income; ‘e00600’, all dividends included in AGI ‘e00650’, qualified dividends (also included in e00600) ‘e01400’, federally-taxable IRA distribution; ‘e01700’, federally-taxable pension benefits; ‘e02000’, Schedule E total net income/loss ‘e02400’, all social security (OASDI) benefits; ‘p22250’, short-term capital gains; ‘p23250’, long-term capital gains; ‘e18500’, Schedule A real-estate-tax paid; ‘e19200’, Schedule A interest paid; ‘e26270’, S-corporation/partnership income (also included in e02000); ‘e19800’, Charity cash contributions; ‘e20100’, Charity non-cash contributions.

static read_json_param_objects(reform, assump)[source]

Read JSON reform and assump objects and return a single dictionary containing five key:dict pairs: ‘policy’:dict, ‘consumption’:dict, ‘behavior’:dict, ‘growdiff_baseline’:dict and ‘growdiff_response’:dict.

Note that either of the first two parameters may be None. If reform is None, the dict in the ‘policy’:dict pair is empty. If assump is None, the dict in the ‘consumption’:dict pair, in the ‘behavior’:dict pair, in the ‘growdiff_baseline’:dict pair, and in the ‘growdiff_response’:dict pair, are all empty.

Also note that either of the first two parameters can be strings containing a valid JSON string (rather than a filename), in which case the file reading is skipped and the appropriate read_json_*_text method is called.

The reform file contents or JSON string must be like this: {“policy”: {…}} and the assump file contents or JSON string must be like: {“consumption”: {…},

“behavior”: {…}, “growdiff_baseline”: {…}, “growdiff_response”: {…}

}

The returned dictionary contains parameter lists (not arrays).

static reform_documentation(params)[source]

Generate reform documentation.

Parameters:params (dict) – compound dictionary structured as dict returned from the static Calculator method read_json_param_objects()
Returns:doc – the documentation for the policy reform specified in params
Return type:String

taxcalc.cli.tc

Command-line interface (CLI) to Tax-Calculator, which can be accessed as ‘tc’ from an installed taxcalc conda package.

taxcalc.cli.tc._write_expected_test_output()[source]

Private function that writes tc –test input and expected output files.

taxcalc.cli.tc.cli_tc_main()[source]

Contains command-line interface (CLI) to Tax-Calculator TaxCalcIO class.

taxcalc.Consumption

class taxcalc.Consumption(consumption_dict=None, start_year=2013, num_years=15)[source]

Consumption is a subclass of the abstract ParametersBase class, and therefore, inherits its methods (none of which are shown here).

Constructor for marginal Consumption class.

Parameters:
  • consumption_dict (dictionary of PARAM:DESCRIPTION pairs) – dictionary of marginal propensity to consume (MPC) parameters; if None, all MPC parameters are read from DEFAULTS_FILENAME file.
  • start_year (integer) – first calendar year for MPC parameters.
  • num_years (integer) – number of calendar years for which to specify MPC parameter values beginning with start_year.
Raises:

ValueError: – if consumption_dict is neither None nor a dictionary. if num_years is less than one.

Returns:

class instance

Return type:

Consumption

has_response()[source]

Return true if any MPC parameters are positive for current_year; return false if all MPC parameters are zero.

response(records, income_change)[source]

Changes consumption-related records variables given income_change.

update_consumption(revisions)[source]

Update consumption for given revisions, a dictionary consisting of one or more year:modification dictionaries. For example: {2014: {‘_MPC_xxx’: [0.2, 0.1]}}

Note that this method uses the specified revisions to update the default MPC parameter values, so use this method just once rather than calling it sequentially in an attempt to update MPC parameters in several steps.

taxcalc.decorators

Implement numba JIT decorators used to speed-up Tax-Calculator functions in the functions.py module.

class taxcalc.decorators.GetReturnNode[source]

A NodeVisitor to get the return tuple names from a calc-style function.

visit_Return(node)[source]

visit_Return is used by NodeVisitor.visit method.

taxcalc.decorators.apply_jit(dtype_sig_out, dtype_sig_in, parameters=None, **kwargs)[source]

Make a decorator that takes in a calc-style function, handle apply step.

taxcalc.decorators.create_apply_function_string(sigout, sigin, parameters)[source]

Create a string for a function of the form:

def ap_fuc(x_0, x_1, x_2, ...):
    for i in range(len(x_0)):
        x_0[i], ... = jitted_f(x_j[i], ...)
    return x_0[i], ...

where the specific args to jitted_f and the number of values to return is determined by sigout and sigin.

Parameters:
  • sigout (iterable of the out arguments) –
  • sigin (iterable of the in arguments) –
  • parameters (iterable of which of the args (from in_args) are parameter) – variables (as opposed to column records). This influences how we construct the apply-style function
Returns:

Return type:

a String representing the function

taxcalc.decorators.create_toplevel_function_string(args_out, args_in, pm_or_pf)[source]

Create a string for a function of the form:

def hl_func(x_0, x_1, x_2, …):
outputs = (…) = calc_func(…) header = […] return DataFrame(data, columns=header)
Parameters:
  • args_out (iterable of the out arguments) –
  • args_in (iterable of the in arguments) –
  • pm_or_pf (iterable of strings for object that holds each arg) –
Returns:

Return type:

a String representing the function

taxcalc.decorators.id_wrapper(*dec_args, **dec_kwargs)[source]

Function wrapper when numba package is not available or when debugging

taxcalc.decorators.iterate_jit(parameters=None, **kwargs)[source]

Public decorator for a calc-style function (see functions.py) that transforms the calc-style function into an apply-style function that can be called by Calculator class methods (see calculate.py).

taxcalc.decorators.make_apply_function(func, out_args, in_args, parameters, do_jit=True, **kwargs)[source]

Takes a calc-style function and creates the necessary Python code for an apply-style function. Will also jit the function if desired.

Parameters:
  • func (the calc-style function) –
  • out_args (list of out arguments for the apply-style function) –
  • in_args (list of in arguments for the apply-style function) –
  • parameters (iterable of which of the args (from in_args) are parameter) – variables (as opposed to column records). This influences how we construct the apply-style function.
  • do_jit (Bool, if True, jit the resulting apply-style function) –
Returns:

Return type:

apply-style function

taxcalc.functions

Tax-Calculator functions that calculate payroll and individual income taxes.

Note: the cpi_offset policy parameter is the only policy parameter that does not appear here; it is used in the policy.py file to possibly adjust the price inflation rate used to index policy parameters (as would be done in a reform that introduces chained-CPI indexing).

taxcalc.functions.BenefitLimitation(calc)[source]

BenefitLimitation function: limits the benefits of select itemized deductions to a fraction of deductible expenses.

taxcalc.functions.BenefitSurtax(calc)[source]

BenefitSurtax function: computes itemized-deduction-benefit surtax and adds the surtax amount to income tax, combined tax, and surtax liabilities.

taxcalc.functions.ComputeBenefit(calc, ID_switch)[source]

Calculates the value of the benefits accrued from itemizing.

taxcalc.functions.EITCamount[source]

Return EITC amount given specified parameters

taxcalc.functions.SchXYZ[source]

Return Schedule X, Y, Z tax amount for specified taxable_income.

taxcalc.functions.Taxes[source]

Taxes function returns tax amount given the progressive tax rate schedule specified by the rate* and (upper) tbrk* parameters and given income, filing status (MARS), and tax bracket base (tbrk_base).

taxcalc.Growdiff

class taxcalc.Growdiff(growdiff_dict=None, start_year=2013, num_years=15)[source]

Growdiff is a subclass of the abstract ParametersBase class, and therefore, inherits its methods (none of which are shown here).

Constructor for growth difference class.

Parameters:
  • growdiff_dict (dictionary of PARAM:DESCRIPTION pairs) – dictionary of growth difference parameters; if None, default parameters are read from the growdiff.json file.
  • start_year (integer) – first calendar year for growth difference parameters.
  • num_years (integer) – number of calendar years for which to specify parameter values beginning with start_year.
Raises:

ValueError: – if growdiff_dict is neither None nor a dictionary. if num_years is less than one.

Returns:

class instance

Return type:

Growdiff

apply_to(growfactors)[source]

Apply updated growdiff values to specified Growfactors instance.

has_any_response()[source]

Returns true if any parameter is non-zero for any year; returns false if all parameters are zero in all years.

update_growdiff(revisions)[source]

Update growdiff default values using specified revisions, which is a dictionary containing one or more year:modification dictionaries. For example: {2014: {‘_AWAGE’: [0.01]}}.

taxcalc.Growfactors

class taxcalc.Growfactors(growfactors_filename='/home/docs/checkouts/readthedocs.org/user_builds/taxcalc/checkouts/latest/taxcalc/growfactors.csv')[source]

Constructor for the Growfactors class.

Parameters:growfactors_filename (string) – string is name of CSV file in which grow factors reside; default value is name of file containing baseline grow factors.
Raises:ValueError: – if growfactors_filename is not a string.
Returns:class instance
Return type:Growfactors

Notes

Typical usage is “gfactor = Growfactors()”, which produces an object containing the default grow factors in the Growfactors.FILENAME file.

factor_value(name, year)[source]

Return value of factor with specified name for specified year.

first_year

Growfactors class start_year property.

last_year

Growfactors class last_year property.

price_inflation_rates(firstyear, lastyear)[source]

Return list of price inflation rates rounded to four decimal digits.

update(name, year, diff)[source]

Add to self.gfdf[name][year] the specified diff amount.

wage_growth_rates(firstyear, lastyear)[source]

Return list of wage growth rates rounded to four decimal digits.

taxcalc.macro_elasticity

Implements TaxBrain “Macroeconomic Elasticities Simulation” dynamic analysis.

taxcalc.macro_elasticity.proportional_change_in_gdp(year, calc1, calc2, elasticity)[source]

This function harnesses econometric estimates of the historic relationship between tax policy and the macro economy to predict the effect of tax reforms on economic growth.

In particular, this model relies on estimates of how GDP responds to changes in the average after tax rate on wage income across all taxpayers (one minus the average marginal tax rate, or 1-AMTR). These estimates are derived from calculations of income-weighted marginal tax rates under the baseline and reform. The reform-induced change in GDP in year t is assumed to be equal to the assumed elasticity times the absolute (not proportional) change in one minus the average marginal tax rate in year t-1. In other words, the current-year change in GDP is assumed to be related to the prior-year change in the average marginal tax rate.

Empirical evidence on this elasticity can be found in Robert Barro and Charles Redlick, “Macroeconomic Effects from Government Purchases and Taxes” (2011 Quarterly Journal of Economics). A pre-publication version of this paper is available at the following URL: <siteresources.worldbank.org/INTMACRO/Resources/BarroBRedlickBpaper.pdf>. In particular, Barro and Redlick find that a 1 percentage point decrease in the AMTR leads to a 0.54 percent increase in GDP. Evaluated at the sample mean, this translates to an elasticity of GDP with respect to the average after-tax marginal rate of about 0.36.

A more recent paper by Karel Mertens and Jose L. Montiel Olea, entitled “Marginal Tax Rates and Income: New Time Series Evidence”, NBER working paper 19171 (June 2013 with September 2017 revisions) <www.nber.org/papers/w19171.pdf>, contains additional empirical evidence suggesting the elasticity is no less than the 0.36 Barro- Redlick estimate and perhaps somewhat higher (see section 4.6). Their summary of the Barro and Redlick findings (on page 5) are as follows: “Barro and Redlick (2011) however find that a one percentage point cut in the AMTR raises per capita GDP by around 0.5% in the following year. This estimate is statistically significant and amounts to a short run GDP elasticity to the net-of-tax rate of 0.36”.

Parameters:
  • year (calendar year of the reform-induced proportion change in GDP) –
  • calc1 (Calculator object for the pre-reform baseline for prior year) –
  • calc2 (Calculator object for the policy reform for prior year) –
  • elasticity (Float estimate of elasticity of GDP wrt 1-AMTR) –
Returns:

  • Float estimate of proportional change in GDP induced by the reform
  • Note that proportional means a relative change but it is not expressed
  • in percentage terms

taxcalc.ParametersBase

class taxcalc.ParametersBase[source]

Inherit from this class for Policy, Behavior, Consumption, Growdiff, and other groups of parameters that need to have a set_year method. Override this __init__ method and DEFAULTS_FILENAME.

current_year

ParametersBase class current calendar year property.

classmethod default_data(metadata=False, start_year=None)[source]

Return parameter data read from the subclass’s json file.

Parameters:
  • metadata (boolean) –
  • start_year (int or None) –
Returns:

params

Return type:

dictionary of data

end_year

ParametersBase class lasst parameter year property.

indexing_rates(param_name)[source]

Return appropriate indexing rates for specified param_name.

inflation_rates()[source]

Override this method in subclass when appropriate.

initialize(start_year, num_years)[source]

Called from subclass __init__ function.

num_years

ParametersBase class number of parameter years property.

set_default_vals()[source]

Called by initialize method and from some subclass methods.

set_year(year)[source]

Set parameters to their values for the specified calendar year.

Parameters:year (int) – calendar year for which to current_year and parameter values
Raises:ValueError: – if year is not in [start_year, end_year] range.
Returns:nothing
Return type:void

Notes

To increment the current year, use the following statement:

behavior.set_year(behavior.current_year + 1)

where, in this example, behavior is a Behavior object.

start_year

ParametersBase class first parameter year property.

wage_growth_rates()[source]

Override this method in subclass when appropriate.

taxcalc.Policy

class taxcalc.Policy(gfactors=None, parameter_dict=None, start_year=2013, num_years=15)[source]

Policy is a subclass of the abstract ParametersBase class, and therefore, inherits its methods (none of which are shown here).

Constructor for the federal tax policy class.

Parameters:
  • gfactors (Growfactors class instance) – containing price inflation rates and wage growth rates
  • parameter_dict (dictionary of PARAM:DESCRIPTION pairs) – dictionary of policy parameters; if None, default policy parameters are read from the current_law_policy.json file.
  • start_year (integer) – first calendar year for historical policy parameters.
  • num_years (integer) – number of calendar years for which to specify policy parameter values beginning with start_year.
Raises:

ValueError: – if gfactors is not a Growfactors class instance. if parameter_dict is neither None nor a dictionary. if num_years is less than one.

Returns:

class instance

Return type:

Policy

_apply_cpi_offset(reform)[source]

Apply CPI offset to inflation rates and revert indexed parameter values in preparation for re-indexing.

_validate_parameter_names_types(reform)[source]

Check validity of parameter names and parameter types used in the specified reform dictionary.

_validate_parameter_values(parameters_set)[source]

Check values of parameters in specified parameter_set using range information from the current_law_policy.json file.

current_law_version()[source]

Return Policy object same as self except with current-law policy.

ignore_reform_errors()[source]

Sets self._ignore_errors to True.

implement_reform(reform)[source]

Implement multi-year policy reform and leave current_year unchanged.

Parameters:reform (dictionary of one or more YEAR:MODS pairs) – see Notes to Parameters _update method for info on MODS structure
Raises:ValueError: – if reform is not a dictionary. if each YEAR in reform is not an integer. if minimum YEAR in the YEAR:MODS pairs is less than start_year. if minimum YEAR in the YEAR:MODS pairs is less than current_year. if maximum YEAR in the YEAR:MODS pairs is greater than end_year. if Policy._validate_parameter_names generates any error messages.
Returns:nothing
Return type:void

Notes

Given a reform dictionary, typical usage of the Policy class is as follows:

policy = Policy()
policy.implement_reform(reform)

In the above statements, the Policy() call instantiates a policy object (policy) containing current-law policy parameters, and the implement_reform(reform) call applies the (possibly multi-year) reform specified in reform and then sets the current_year to the value of current_year when implement_reform was called with parameters set for that pre-call year.

An example of a multi-year, multi-parameter reform is as follows:

reform = {
    2016: {
        '_EITC_c': [[900, 5000, 8000, 9000]],
        '_II_em': [7000],
        '_SS_Earnings_c': [300000]
    },
    2017: {
        '_SS_Earnings_c': [500000], '_SS_Earnings_c_cpi': False
    },
    2019: {
        '_EITC_c': [[1200, 7000, 10000, 12000]],
        '_II_em': [9000],
        '_SS_Earnings_c': [700000], '_SS_Earnings_c_cpi': True
    }
}

Notice that each of the four YEAR:MODS pairs is specified as required by the private _update method, whose documentation provides several MODS dictionary examples.

IMPORTANT NOTICE: when specifying a reform dictionary always group all reform provisions for a specified year into one YEAR:MODS pair. If you make the mistake of specifying two or more YEAR:MODS pairs with the same YEAR value, all but the last one will be overwritten, and therefore, not part of the reform. This is because Python expects unique (not multiple) dictionary keys. There is no way to catch this error, so be careful to specify reform dictionaries correctly.

inflation_rates()[source]

Returns list of price inflation rates starting with JSON_START_YEAR.

static translate_json_reform_suffixes(indict, growdiff_baseline_dict, growdiff_response_dict)[source]

Replace any array parameters with suffixes in the specified JSON-derived “policy” dictionary, indict, and return a JSON-equivalent dictionary containing constructed array parameters and containing no parameters with suffixes, odict.

wage_growth_rates()[source]

Returns list of wage growth rates starting with JSON_START_YEAR.

taxcalc.Records

class taxcalc.Records(data='puf.csv', exact_calculations=False, gfactors=<taxcalc.growfactors.Growfactors object>, weights='puf_weights.csv', adjust_ratios='puf_ratios.csv', start_year=2009)[source]

Constructor for the tax-filing-unit Records class.

Parameters:
  • data (string or Pandas DataFrame) – string describes CSV file in which records data reside; DataFrame already contains records data; default value is the string ‘puf.csv’ For details on how to use your own data with the Tax-Calculator, look at the test_Calculator_using_nonstd_input() function in the tests/test_calculate.py file.
  • exact_calculations (boolean) – specifies whether or not exact tax calculations are done without any smoothing of “stair-step” provisions in income tax law; default value is false.
  • gfactors (Growfactors class instance or None) – containing record data extrapolation (or “blowup”) factors
  • weights (string or Pandas DataFrame or None) – string describes CSV file in which weights reside; DataFrame already contains weights; None creates empty sample-weights DataFrame; default value is filename of the PUF weights.
  • adjust_ratios (string or Pandas DataFrame or None) – string describes CSV file in which adjustment ratios reside; DataFrame already contains adjustment ratios; None creates empty adjustment-ratios DataFrame; default value is filename of the PUF adjustment ratios.
  • start_year (integer) – specifies calendar year of the input data; default value is PUFCSV_YEAR. Note that if specifying your own data (see above) as being a custom data set, be sure to explicitly set start_year to the custom data’s calendar year. For details on how to use your own data with the Tax-Calculator, read the DATAPREP.md file in the top-level directory and then look at the test_Calculator_using_nonstd_input() function in the taxcalc/tests/test_calculate.py file.
Raises:

ValueError: – if data is not the appropriate type. if taxpayer and spouse variables do not add up to filing-unit total. if dividends is less than qualified dividends. if gfactors is not None or a Growfactors class instance. if start_year is not an integer. if files cannot be found.

Returns:

class instance

Return type:

Records

Notes

Typical usage when using PUF input data is as follows:

recs = Records()

which uses all the default parameters of the constructor, and therefore, imputed variables are generated to augment the data and initial-year grow factors are applied to the data. There are situations in which you need to specify the values of the Record constructor’s arguments, but be sure you know exactly what you are doing when attempting this.

Use Records.cps_constructor() to get a Records object instantiated with CPS input data.

_read_ratios(ratios)[source]

Read Records adjustment ratios from file or uses specified DataFrame as data or creates empty DataFrame if None

static cps_constructor(data=None, exact_calculations=False, gfactors=<taxcalc.growfactors.Growfactors object>)[source]

Static method returns a Records object instantiated with CPS input data. This works in a analogous way to Records(), which returns a Records object instantiated with PUF input data. This is a convenience method that eliminates the need to specify all the details of the CPS input data just as the default values of the arguments of the Records class constructor eliminate the need to specify all the details of the PUF input data.

current_year

Records class current calendar year property.

data_year

Records class original data year property.

increment_year()[source]

Add one to current year. Also, does extrapolation, reweighting, adjusting for new current year.

static read_var_info()[source]

Read Records variables metadata from JSON file; returns dictionary and specifies static varname sets listed below.

set_current_year(new_current_year)[source]

Set current year to specified value and updates FLPDYR variable. Unlike increment_year method, extrapolation, reweighting, adjusting are skipped.

zero_out_changing_calculated_vars()[source]

Set to zero all variables in the Records.CHANGING_CALCULATED_VARS set.

taxcalc.TaxCalcIO

class taxcalc.TaxCalcIO(input_data, tax_year, reform, assump)[source]

Constructor for the Tax-Calculator Input-Output class.

TaxCalcIO class constructor call must be followed by init() call.

Parameters:
  • input_data (string or Pandas DataFrame) – string is name of INPUT file that is CSV formatted containing variable names in the Records.USABLE_READ_VARS set, or Pandas DataFrame is INPUT data containing variable names in the Records.USABLE_READ_VARS set. INPUT vsrisbles not in the Records.USABLE_READ_VARS set can be present but are ignored.
  • tax_year (integer) – calendar year for which taxes will be computed for INPUT.
  • reform (None or string) – None implies no policy reform (current-law policy), or string is name of optional REFORM file.
  • assump (None or string) – None implies economic assumptions are standard assumptions, or string is name of optional ASSUMP file.
Returns:

class instance

Return type:

TaxCalcIO

analyze(writing_output_file=False, output_tables=False, output_graphs=False, output_ceeu=False, output_dump=False, output_sqldb=False)[source]

Conduct tax analysis.

Parameters:
  • writing_output_file (boolean) – whether or not to generate and write output file
  • output_tables (boolean) – whether or not to generate and write distributional tables to a text file
  • output_graphs (boolean) – whether or not to generate and write HTML graphs of average and marginal tax rates by income percentile
  • output_ceeu (boolean) – whether or not to calculate and write to stdout standard certainty-equivalent expected-utility statistics
  • output_dump (boolean) – whether or not to replace standard output with all input and calculated variables using their Tax-Calculator names
  • output_sqldb (boolean) – whether or not to write SQLite3 database with dump table containing same output as written by output_dump to a csv file
Returns:

Return type:

Nothing

static annual_analysis(input_data, tax_year, reform, assump, aging_input_data, exact_calculations, growdiff_response, year, writing_output_file, output_tables, output_graphs, output_ceeu, output_dump)[source]

Conduct static analysis for specifed year and growdiff_response.

Parameters:
  • six parameters are same as the first six parameters of (First) –
  • TaxCalcIO.init method. (the) –
  • five parameters are same as the first five parameters of (Last) –
  • TaxCalcIO.analyze method. (the) –
Returns:

gd_dict

Return type:

Growdiff sub-dictionary for year+1

static ceeu_output(cedict)[source]

Extract –ceeu output and return as text string.

dump_output(mtr_inctax, mtr_paytax)[source]

Extract dump output and return it as Pandas DataFrame.

static growmodel_analysis(input_data, tax_year, reform, assump, aging_input_data, exact_calculations, writing_output_file=False, output_tables=False, output_graphs=False, output_ceeu=False, output_dump=False)[source]

High-level logic for dynamic analysis using GrowModel class.

Parameters:
  • six parameters are same as the first six parameters of (First) –
  • TaxCalcIO.init method. (the) –
  • five parameters are same as the first five parameters of (Last) –
  • TaxCalcIO.analyze method. (the) –
Returns:

Return type:

Nothing

init(input_data, tax_year, reform, assump, growdiff_response, aging_input_data, exact_calculations)[source]

TaxCalcIO class post-constructor method that completes initialization.

Parameters:
  • four parameters are same as for TaxCalcIO constructor (First) – input_data, tax_year, reform, assump.
  • growdiff_response (Growdiff object or None) – growdiff_response Growdiff object is used only by the TaxCalcIO.growmodel_analysis method; must be None in all other cases.
  • aging_input_data (boolean) – whether or not to extrapolate Records data from data year to tax_year.
  • exact_calculations (boolean) – specifies whether or not exact tax calculations are done without any smoothing of “stair-step” provisions in the tax law.
minimal_output()[source]

Extract minimal output and return it as Pandas DataFrame.

output_filepath()[source]

Return full path to output file named in TaxCalcIO constructor.

tax_year()[source]

Return calendar year for which TaxCalcIO calculations are being done.

static write_decile_table(dfx, tfile, tkind='Totals')[source]

Write to tfile the tkind decile table using dfx DataFrame.

write_doc_file()[source]

Write reform documentation to text file.

static write_empty_graph_file(fname, title, reason)[source]

Write HTML graph file with title but no graph for specified reason.

write_graph_files()[source]

Write graphs to HTML files.

write_output_file(output_dump, mtr_paytax, mtr_inctax)[source]

Write output to CSV-formatted file.

write_sqldb_file(mtr_paytax, mtr_inctax)[source]

Write dump output to SQLite3 database table dump.

write_tables_file()[source]

Write tables to text file.

taxcalc.tbi.tbi

The public API of the TaxBrain Interface (tbi).

The tbi functions are used by TaxBrain to call Tax-Calculator in order to do distributed processing of TaxBrain runs and in order to maintain the privacy of the IRS-SOI PUF data being used by TaxBrain. Maintaining privacy is done by “fuzzing” reform results for several randomly selected filing units in each table cell. The filing units randomly selected differ for each policy reform and the “fuzzing” involves replacing the post-reform tax results for the selected units with their pre-reform tax results.

taxcalc.tbi.tbi.reform_warnings_errors(user_mods)[source]

The reform_warnings_errors function assumes user_mods is a dictionary returned by the Calculator.read_json_param_objects() function.

This function returns a dictionary containing two STR:STR pairs: {‘warnings’: ‘<empty-or-message(s)>’, ‘errors’: ‘<empty-or-message(s)>’} In each pair the second string is empty if there are no messages. Any returned messages are generated using current_law_policy.json information on known policy parameter names and parameter value ranges.

Note that this function will return one or more error messages if the user_mods[‘policy’] dictionary contains any unknown policy parameter names or if any *_cpi parameters have values other than True or False. These situations prevent implementing the policy reform specified in user_mods, and therefore, no range-related warnings or errors will be returned in this case.

taxcalc.tbi.tbi.run_nth_year_gdp_elast_model(year_n, start_year, use_puf_not_cps, use_full_sample, user_mods, gdp_elasticity, return_dict=True)[source]
The run_nth_year_gdp_elast_model function assumes user_mods is a dictionary
returned by the Calculator.read_json_param_objects() function.
Setting use_puf_not_cps=True implies use puf.csv input file;
otherwise, use cps.csv input file.
Setting use_full_sample=False implies use sub-sample of input file;
otherwsie, use the complete sample.
taxcalc.tbi.tbi.run_nth_year_tax_calc_model(year_n, start_year, use_puf_not_cps, use_full_sample, user_mods, return_dict=True)[source]
The run_nth_year_tax_calc_model function assumes user_mods is a dictionary
returned by the Calculator.read_json_param_objects() function.
Setting use_puf_not_cps=True implies use puf.csv input file;
otherwise, use cps.csv input file.
Setting use_full_sample=False implies use sub-sample of input file;
otherwsie, use the complete sample.

taxcalc.utils

PUBLIC utility functions for Tax-Calculator.

taxcalc.utils.add_income_bins(pdf, income_measure, bin_type='soi', bins=None, right=True)[source]

Add a column of income bins of income_measure using Pandas ‘cut’ function.

Parameters:
  • pdf (Pandas DataFrame) – the object to which we are adding bins
  • income_measure (String) – specifies income variable used to construct bins
  • bin_type (String, optional) – options for input: ‘webapp’, ‘tpc’, ‘soi’ default: ‘soi’
  • bins (iterable of scalars, optional income breakpoints) – follows Pandas convention; the breakpoint is inclusive if right=True; this argument overrides the compare_with argument
  • right (bool, optional) – indicates whether the bins include the rightmost edge or not; if right == True (the default), then bins=[1,2,3,4] implies this bin grouping (1,2], (2,3], (3,4]
Returns:

pdf – the original input plus the added ‘bin’ column

Return type:

Pandas DataFrame

taxcalc.utils.add_quantile_bins(pdf, income_measure, num_bins, weight_by_income_measure=False, labels=None)[source]

Add a column of income bins to specified Pandas DataFrame, pdf, with the new column being named ‘bins’. The bins hold equal number of filing units when weight_by_income_measure=False or equal number of income dollars when weight_by_income_measure=True. Assumes that specified pdf contains columns for the specified income_measure and for sample weights, s006.

taxcalc.utils.atr_graph_data(calc1, calc2, mars='ALL', atr_measure='combined', min_avginc=1000)[source]

Prepare average tax rate data needed by xtr_graph_plot utility function.

Parameters:
  • calc1 (a Calculator object that refers to baseline policy) –
  • calc2 (a Calculator object that refers to reform policy) –
  • mars (integer or string) –

    specifies which filing status subgroup to show in the graph

    • ’ALL’: include all filing units in sample
    • 1: include only single filing units
    • 2: include only married-filing-jointly filing units
    • 3: include only married-filing-separately filing units
    • 4: include only head-of-household filing units
  • atr_measure (string) –

    specifies which average tax rate to show on graph’s y axis

    • ’itax’: average individual income tax rate
    • ’ptax’: average payroll tax rate
    • ’combined’: sum of average income and payroll tax rates
  • min_avginc (float) – specifies the minimum average expanded income for a percentile to be included in the graph data; value must be positive
Returns:

Return type:

dictionary object suitable for passing to xtr_graph_plot utility function

taxcalc.utils.bootstrap_se_ci(data, seed, num_samples, statistic, alpha)[source]

Return bootstrap estimate of standard error of statistic and bootstrap estimate of 100*(1-2*alpha)% confidence interval for statistic in a dictionary along with specified seed and nun_samples (B) and alpha.

taxcalc.utils.ce_aftertax_income(calc1, calc2, custom_params=None, require_no_agg_tax_change=True)[source]

Return dictionary that contains certainty-equivalent of the expected utility of after-tax income computed for constant-relative-risk-aversion parameter values for each of two Calculator objects: calc1, which represents the pre-reform situation, and calc2, which represents the post-reform situation, both of which MUST have had calc_call() called before being passed to this function.

IMPORTANT NOTES: These normative welfare calculations are very simple. It is assumed that utility is a function of only consumption, and that consumption is equal to after-tax income. This means that any assumed behavioral responses that change work effort will not affect utility via the correpsonding change in leisure. And any saving response to changes in after-tax income do not affect consumption.

taxcalc.utils.certainty_equivalent(exputil, crra, cmin)[source]

Calculate and return certainty-equivalent of exputil of consumption assuming an isoelastic utility function with crra and cmin as parameters.

Parameters:
  • exputil (float) – expected utility value
  • crra (non-negative float) – constant relative risk aversion parameter of isoelastic utility function
  • cmin (positive float) – consumption level below which marginal utility is assumed to be constant
Returns:

Return type:

certainty-equivalent of specified expected utility, exputil

taxcalc.utils.create_diagnostic_table(calc)[source]

Extract diagnostic table from specified Calculator object. This function leaves the specified calc object unchanged.

Parameters:calc (Calculator class object) –
Returns:
Return type:Pandas DataFrame object containing the table for calc.current_year
taxcalc.utils.create_difference_table(res1, res2, groupby, income_measure, tax_to_diff)[source]

Get results from two different res, construct tax difference results, and return the difference statistics as a table.

Parameters:
  • res1 (baseline object is either a Tax-Calculator Records object or) – a Pandas DataFrame including columns in STATS_COLUMNS list
  • res2 (reform object is either a Tax-Calculator Records object or) – a Pandas DataFrame including columns in STATS_COLUMNS list
  • groupby (String object) –
    options for input: ‘weighted_deciles’, ‘webapp_income_bins’,
    ’large_income_bins’, ‘small_income_bins’

    specifies kind of bins used to group filing units

  • NOTE (when groupby is 'weighted_deciles', the returned table has three) – extra rows containing top-decile detail consisting of statistics for the 0.90-0.95 quantile range (bottom half of top decile), for the 0.95-0.99 quantile range, and for the 0.99-1.00 quantile range (top one percent).
  • income_measure (String object) – options for input: ‘expanded_income’, ‘c00100’(AGI) specifies statistic to place filing units in bins
  • tax_to_diff (String object) – options for input: ‘iitax’, ‘payrolltax’, ‘combined’ specifies which tax to difference
Returns:

  • difference table as a Pandas DataFrame, with DIFF_TABLE_COLUMNS and
  • groupby rows, where the rows run from lowest bin/decile to the highest
  • followed by a sums row with the top-decile detail in an additional three
  • rows following the sums row

taxcalc.utils.create_distribution_table(obj, groupby, income_measure, result_type)[source]

Get results from object, sort them based on groupby using income_measure, manipulate them based on result_type, and return them as a table.

Parameters:
  • obj (any object with array-like attributes named as in STATS_COLUMNS list) – Examples include a Tax-Calculator Records object and a Pandas DataFrame object.
  • groupby (String object) –
    options for input: ‘weighted_deciles’, ‘webapp_income_bins’,
    ’large_income_bins’, ‘small_income_bins’;

    determines how the columns in the resulting Pandas DataFrame are sorted

  • NOTE (when groupby is 'weighted_deciles', the returned table has three) – extra rows containing top-decile detail consisting of statistics for the 0.90-0.95 quantile range (bottom half of top decile), for the 0.95-0.99 quantile range, and for the 0.99-1.00 quantile range (top one percent).
  • result_type (String object) – options for input: ‘weighted_sum’ or ‘weighted_avg’; determines how the data should be manipulated
  • income_measure (String object) –
    options for input: ‘expanded_income’, ‘c00100’(AGI),
    ’expanded_income_baseline’, ‘c00100_baseline’

Notes

Taxpayer Characteristics:

c04470 : Total itemized deduction

c00100 : AGI (Defecit)

c09600 : Alternative minimum tax

s006 : filing unit sample weight

Returns:
  • distribution table as a Pandas DataFrame, with DIST_TABLE_COLUMNS and
  • groupby rows, where the rows run from lowest bin/decile to the highest
  • followed by a sums row with the top-decile detail in an additional three
  • rows following the sums row
taxcalc.utils.dec_graph_data(calc1, calc2)[source]

Prepare data needed by dec_graph_plot utility function.

Parameters:
  • calc1 (a Calculator object that refers to baseline policy) –
  • calc2 (a Calculator object that refers to reform policy) –
Returns:

Return type:

dictionary object suitable for passing to dec_graph_plot utility function

taxcalc.utils.dec_graph_plot(data, width=850, height=500, xlabel='', ylabel='', title='')[source]

Plot stacked decile graph using data returned from dec_graph_data function.

Parameters:
  • data (dictionary object returned from dec_graph_data() utility function) –
  • width (integer) – width of plot expressed in pixels
  • height (integer) – height of plot expressed in pixels
  • xlabel (string) – x-axis label; if ‘’, then use label generated by dec_graph_data
  • ylabel (string) – y-axis label; if ‘’, then use label generated by dec_graph_data
  • title (string) – graph title; if ‘’, then use title generated by dec_graph_data
Returns:

Return type:

bokeh.plotting figure object containing a raster graphics plot

Notes

USAGE EXAMPLE:

gdata = dec_graph_data(calc1, calc2)
gplot = dec_graph_plot(gdata)

THEN when working interactively in a Python notebook:

bp.show(gplot)

OR when executing script using Python command-line interpreter:

bio.output_file('graph-name.html', title='Change in After-Tax Income')
bio.show(gplot)  [OR bio.save(gplot) WILL JUST WRITE FILE TO DISK]

WILL VISUALIZE GRAPH IN BROWSER AND WRITE GRAPH TO SPECIFIED HTML FILE

To convert the visualized graph into a PNG-formatted file, click on the “Save” icon on the Toolbar (located in the top-right corner of the visualized graph) and a PNG-formatted file will written to your Download directory.

The ONLY output option the bokeh.plotting figure has is HTML format, which (as described above) can be converted into a PNG-formatted raster graphics file. There is no option to make the bokeh.plotting figure generate a vector graphics file such as an EPS file.

taxcalc.utils.delete_file(filename)[source]

Remove specified file if it exists.

taxcalc.utils.expected_utility(consumption, probability, crra, cmin)[source]

Calculate and return expected utility of consumption.

Parameters:
  • consumption (numpy array) – consumption for each filing unit
  • probability (numpy array) – samplying probability of each filing unit
  • crra (non-negative float) – constant relative risk aversion parameter of isoelastic utility function
  • cmin (positive float) – consumption level below which marginal utility is assumed to be constant
Returns:

Return type:

expected utility of consumption array

taxcalc.utils.get_sums(pdf)[source]

Compute unweighted sum of items in each column of Pandas DataFrame, pdf.

Returns:
Return type:Pandas Series object containing column sums indexed by pdf column names.
taxcalc.utils.isoelastic_utility_function(consumption, crra, cmin)[source]

Calculate and return utility of consumption.

Parameters:
  • consumption (float) – consumption for a filing unit
  • crra (non-negative float) – constant relative risk aversion parameter
  • cmin (positive float) – consumption level below which marginal utility is assumed to be constant
Returns:

Return type:

utility of consumption

taxcalc.utils.mtr_graph_data(calc1, calc2, mars='ALL', mtr_measure='combined', mtr_variable='e00200p', alt_e00200p_text='', mtr_wrt_full_compen=False, income_measure='expanded_income', dollar_weighting=False)[source]

Prepare marginal tax rate data needed by xtr_graph_plot utility function.

Parameters:
  • calc1 (a Calculator object that refers to baseline policy) –
  • calc2 (a Calculator object that refers to reform policy) –
  • mars (integer or string) –

    specifies which filing status subgroup to show in the graph

    • ’ALL’: include all filing units in sample
    • 1: include only single filing units
    • 2: include only married-filing-jointly filing units
    • 3: include only married-filing-separately filing units
    • 4: include only head-of-household filing units
  • mtr_measure (string) –

    specifies which marginal tax rate to show on graph’s y axis

    • ’itax’: marginal individual income tax rate
    • ’ptax’: marginal payroll tax rate
    • ’combined’: sum of marginal income and payroll tax rates
  • mtr_variable (string) – any string in the Calculator.VALID_MTR_VARS set specifies variable to change in order to compute marginal tax rates
  • alt_e00200p_text (string) – text to use in place of mtr_variable when mtr_variable is ‘e00200p’; if empty string then use ‘e00200p’
  • mtr_wrt_full_compen (boolean) – see documentation of Calculator.mtr() argument wrt_full_compensation (value has an effect only if mtr_variable is ‘e00200p’)
  • income_measure (string) –

    specifies which income variable to show on the graph’s x axis

    • ’wages’: wage and salary income (e00200)
    • ’agi’: adjusted gross income, AGI (c00100)
    • ’expanded_income’: sum of AGI, non-taxable interest income, non-taxable social security benefits, and employer share of FICA taxes.
  • dollar_weighting (boolean) – False implies both income_measure percentiles on x axis and mtr values for each percentile on the y axis are computed without using dollar income_measure weights (just sampling weights); True implies both income_measure percentiles on x axis and mtr values for each percentile on the y axis are computed using dollar income_measure weights (in addition to sampling weights). Specifying True produces a graph x axis that shows income_measure (not filing unit) percentiles.
Returns:

Return type:

dictionary object suitable for passing to xtr_graph_plot utility function

taxcalc.utils.multiyear_diagnostic_table(calc, num_years=0)[source]

Generate multi-year diagnostic table from specified Calculator object. This function leaves the specified calc object unchanged.

Parameters:
  • calc (Calculator class object) –
  • num_years (integer (must be between 1 and number of available calc years)) –
Returns:

Return type:

Pandas DataFrame object containing the multi-year diagnostic table

taxcalc.utils.read_egg_csv(fname, index_col=None)[source]

Read from egg the file named fname that contains CSV data and return pandas DataFrame containing the data.

taxcalc.utils.read_egg_json(fname)[source]

Read from egg the file named fname that contains JSON data and return dictionary containing the data.

taxcalc.utils.results(obj, cols=None)[source]

Get cols results from object and organize them into a table.

Parameters:
  • obj (any object with array-like attributes named as in STATS_COLUMNS list) – Examples include a Tax-Calculator Records object and a Pandas DataFrame object
  • cols (list of object results columns to put into table) – if None, the use STATS_COLUMNS as cols list
Returns:

table

Return type:

Pandas DataFrame object

taxcalc.utils.unweighted_sum(pdf, col_name)[source]

Return unweighted sum of Pandas DataFrame col_name items.

taxcalc.utils.weighted(pdf, col_names)[source]

Return Pandas DataFrame in which each pdf column variable has been multiplied by the s006 weight variable in the specified Pandas DataFrame.

taxcalc.utils.weighted_sum(pdf, col_name)[source]

Return weighted sum of Pandas DataFrame col_name items.

taxcalc.utils.write_graph_file(figure, filename, title)[source]

Write HTML file named filename containing figure. The title is the text displayed in the browser tab.

Parameters:
  • figure (bokeh.plotting figure object) –
  • filename (string) – name of HTML file to which figure is written; should end in .html
  • title (string) – text displayed in browser tab when HTML file is displayed in browser
Returns:

Return type:

Nothing

taxcalc.utils.xtr_graph_plot(data, width=850, height=500, xlabel='', ylabel='', title='', legendloc='bottom_right')[source]

Plot marginal/average tax rate graph using data returned from either the mtr_graph_data function or the atr_graph_data function.

Parameters:
  • data (dictionary object returned from ?tr_graph_data() utility function) –
  • width (integer) – width of plot expressed in pixels
  • height (integer) – height of plot expressed in pixels
  • xlabel (string) – x-axis label; if ‘’, then use label generated by ?tr_graph_data
  • ylabel (string) – y-axis label; if ‘’, then use label generated by ?tr_graph_data
  • title (string) – graph title; if ‘’, then use title generated by ?tr_graph_data
  • legendloc (string) – options: ‘top_right’, ‘top_left’, ‘bottom_left’, ‘bottom_right’ specifies location of the legend in the plot
Returns:

Return type:

bokeh.plotting figure object containing a raster graphics plot

Notes

USAGE EXAMPLE:

gdata = mtr_graph_data(calc1, calc2)
gplot = xtr_graph_plot(gdata)

THEN when working interactively in a Python notebook:

bp.show(gplot)

OR when executing script using Python command-line interpreter:

bio.output_file('graph-name.html', title='?TR by Income Percentile')
bio.show(gplot)  [OR bio.save(gplot) WILL JUST WRITE FILE TO DISK]

WILL VISUALIZE GRAPH IN BROWSER AND WRITE GRAPH TO SPECIFIED HTML FILE

To convert the visualized graph into a PNG-formatted file, click on the “Save” icon on the Toolbar (located in the top-right corner of the visualized graph) and a PNG-formatted file will written to your Download directory.

The ONLY output option the bokeh.plotting figure has is HTML format, which (as described above) can be converted into a PNG-formatted raster graphics file. There is no option to make the bokeh.plotting figure generate a vector graphics file such as an EPS file.

taxcalc.utils.zsum(self)[source]

pandas 0.21.0 changes sum() behavior so that the result of applying sum over an empty Series is NaN. Since we apply the sum() function over grouped DataFrames that may contain an empty Series, it makes more sense for us to have a sum() function that returns zero instead of NaN.