Variables

class openfisca_core.variables.Variable(baseline_variable=None)[source]

A variable of the legislation.

Main attributes:

name

Name of the variable

value_type

The value type of the variable. Possible value types in OpenFisca are int float bool str date and Enum.

entity

Entity the variable is defined for. For instance : Person, Household.

definition_period

Period the variable is defined for. Possible value: MONTH, YEAR, ETERNITY.

formulas

Formulas used to calculate the variable

label

Description of the variable

reference

Legislative reference describing the variable.

default_value

Default value of the variable.

Secondary attributes:

baseline_variable

If the variable has been introduced in a reform to replace another variable, baseline_variable is the replaced variable.

dtype

Numpy dtype used under the hood for the variable.

end

Date when the variable disappears from the legislation.

is_neutralized

True if the variable is neutralized. Neutralized variables never use their formula, and only return their default values when calculated.

json_type

JSON type corresponding to the variable.

max_length

If the value type of the variable is str, max length of the string allowed. None if there is no limit.

possible_values

If the value type of the variable is Enum, contains the values the variable can take.

set_input

Function used to automatically process variable inputs defined for periods not matching the definition_period of the variable. See more on the documentation. Possible values are set_input_dispatch_by_period, set_input_divide_by_period, or nothing.

unit

Free text field describing the unit of the variable. Only used as metadata.

documentation

Free multilines text field describing the variable context and usage.

get_formula(period=None)[source]

Returns the formula used to compute the variable at the given period.

If no period is given and the variable has several formula, return the oldest formula.

Returns:Formula used to compute the variable
Return type:function
classmethod get_introspection_data(tax_benefit_system)[source]

Get instrospection data about the code of the variable.

Returns:(comments, source file path, source code, start line number)
Return type:tuple
is_input_variable()[source]

Returns True if the variable is an input variable.

parse_formula_name(attribute_name)[source]

Returns the starting date of a formula based on its name.

Valid dated name formats are : ‘formula’, ‘formula_YYYY’, ‘formula_YYYY_MM’ and ‘formula_YYYY_MM_DD’ where YYYY, MM and DD are a year, month and day.

By convention, the starting date of:
  • formula is 0001-01-01 (minimal date in Python)
  • formula_YYYY is YYYY-01-01
  • formula_YYYY_MM is YYYY-MM-01
openfisca_core.variables.get_annualized_variable(variable: openfisca_core.variables.Variable, annualization_period: typing.Union[openfisca_core.periods.Period, NoneType] = None) → openfisca_core.variables.Variable[source]

Returns a clone of variable that is annualized for the period annualization_period. When annualized, a variable’s formula is only called for a January calculation, and the results for other months are assumed to be identical.

openfisca_core.variables.get_neutralized_variable(variable)[source]

Return a new neutralized variable (to be used by reforms). A neutralized variable always returns its default value, and does not cache anything.