Variables#

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.

Variable#

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#

//openfisca.org/doc/key-concepts/reforms.html>`_ to replace another variable, baseline_variable is the replaced variable.

Type

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

default_value: object#

//openfisca.org/doc/key-concepts/variables.html#default-values>`_ of the variable.

Type

`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#

MONTH, YEAR, ETERNITY.

Type

`Period <https

Type

//openfisca.org/doc/coding-the-legislation/35_periods.html>`_ the variable is defined for. Possible value

documentation: str#

Free multilines text field describing the variable context and usage.

dtype: numpy.dtype#

//docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.dtype.html>`_ used under the hood for the variable.

Type

Numpy `dtype <https

end: datetime.date#

//openfisca.org/doc/coding-the-legislation/40_legislation_evolutions.html#variable-end>`_ when the variable disappears from the legislation.

Type

`Date <https

entity: policyengine_core.entities.entity.Entity#

Person, Household.

Type

`Entity <https

Type

//openfisca.org/doc/key-concepts/person,_entities,_role.html>`_ the variable is defined for. For instance

formulas: List[Callable]#

Formulas used to calculate the variable

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

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

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.

is_input_variable()[source]#

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

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

possible_values: policyengine_core.enums.enum_array.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.

set_input: Callable#

//openfisca.org/doc/coding-the-legislation/35_periods.html#set-input-automatically-process-variable-inputs-defined-for-periods-not-matching-the-definition-period>`_. Possible values are set_input_dispatch_by_period, set_input_divide_by_period, or nothing.

Type

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.