The policyengine_core.variables module contains the definition of Variable, which can have a value for each entity instance in a simulation, for each period in a simulation, dependent on the parameters in that period, as well as other entity instances.


class policyengine_core.variables.variable.Variable(baseline_variable=None)[source]#

Bases: object

A variable of the legislation.

adds: List[str] = None#

List of variables that are added to the variable. Alternatively, can be a parameter name.

baseline_variable: str#

//>`_ to replace another variable, baseline_variable is the replaced variable.


If the variable has been introduced in a `reform <https

default_value: object#

//>`_ of the variable.


`Default value <https

defined_for: str = None#

The name of another variable, nonzero values of which are used to define the set of entities for which this variable is defined.

definition_period: str#



`Period <https


//>`_ the variable is defined for. Possible value

documentation: str#

Free multilines text field describing the variable context and usage.

dtype: dtype#

//>`_ used under the hood for the variable.


Numpy `dtype <https

end: date#

//>`_ when the variable disappears from the legislation.


`Date <https

entity: Entity#

Person, Household.


`Entity <https


//,_entities,_role.html>`_ the variable is defined for. For instance

exhaustive_parameter_dependencies: List[str] = None#

If these parameters (plus the dataset, branch and period) haven’t changed, Core will use caching on this variable.

formulas: List[Callable]#

Formulas used to calculate the variable


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.


Formula used to compute the variable

classmethod get_introspection_data(tax_benefit_system)[source]#

Get instrospection data about the code of the variable.


(comments, source file path, source code, start line number)

Return type:


hidden_input: bool = False#

Whether the variable is hidden from the input screen entirely on PolicyEngine.

index_in_module: int = None#

Index of the variable in the module it is defined in.


Returns True if the variable is an input variable.

is_neutralized: bool#

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

json_type: str#

JSON type corresponding to the variable.

label: str#

Description of the variable

max_length: int#

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

metadata: dict = None#

Free dictionary field used to store any metadata.

module_name: str = None#

The name of the module it is defined in.

name: str#

Name of the variable


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

possible_values: EnumArray#

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

quantity_type: str#

Categorical attribute describing whether the variable is a stock or a flow.

reference: str#

Legislative reference describing the variable.

requires_computation_after: str = None#

Name of a variable that must be computed before this variable.

set_input: Callable#

//>`_. Possible values are set_input_dispatch_by_period, set_input_divide_by_period, or nothing.


Function used to automatically process variable inputs defined for periods not matching the definition_period of the variable. See more on the `documentation <https

subtracts: List[str] = None#

List of variables that are subtracted from the variable. Alternatively, can be a parameter name.

unit: str#

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

uprating: str = None#

Name of a parameter used to uprate the variable.

value_type: type#

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