Tax-Calculator Decorators

Tax-Calculator Decorators

taxcalc.decorators

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

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 being used during debugging.

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

Public decorator for a calc-style function (see calcfunctions.py) that transforms the calc-style function into an apply-style function that can be called by Calculator class methods (see calculator.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

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.