Holders

class openfisca_core.holders.Holder(variable, entity)[source]

A holder keeps tracks of a variable values after they have been calculated, or set as an input.

clone(entity)[source]

Copy the holder just enough to be able to run a new simulation without modifying the original simulation.

default_array()[source]

Return a new array of the appropriate length for the entity, filled with the variable default values.

delete_arrays(period=None)[source]

If period is None, remove all known values of the variable.

If period is not None, only remove all values for any period included in period (e.g. if period is “2017”, values for “2017-01”, “2017-07”, etc. would be removed)

get_array(period, extra_params=None)[source]

Get the value of the variable for the given period (and possibly a list of extra parameters).

If the value is not known, return None.

get_known_periods()[source]

Get the list of periods the variable value is known for.

get_memory_usage()[source]

Get data about the virtual memory usage of the holder.

Returns:Memory usage data
Return type:dict

Exemple:

>>> holder.get_memory_usage()
>>> {
>>>    'nb_arrays': 12,  # The holder contains the variable values for 12 different periods
>>>    'nb_cells_by_array': 100, # There are 100 entities (e.g. persons) in our simulation
>>>    'cell_size': 8,  # Each value takes 8B of memory
>>>    'dtype': dtype('float64')  # Each value is a float 64
>>>    'total_nb_bytes': 10400  # The holder uses 10.4kB of virtual memory
>>>    'nb_requests': 24  # The variable has been computed 24 times
>>>    'nb_requests_by_array': 2  # Each array stored has been on average requested twice
>>>    }
set_input(period, array)[source]

Set a variable’s value (array) for a given period (period)

Parameters:
  • array – the input value for the variable
  • period – the period at which the value is setted

Exemple :

>>> holder.set_input([12, 14], '2018-04')
>>> holder.get_array('2018-04')
>>> [12, 14]

If a set_input property has been set for the variable, this method may accept inputs for periods not matching the definition_period of the variable. To read more about this, check the documentation.

openfisca_core.holders.set_input_dispatch_by_period(holder, period, array)[source]

This function can be declared as a set_input attribute of a variable.

In this case, the variable will accept inputs on larger periods that its definition period, and the value for the larger period will be applied to all its subperiods.

To read more about set_input attributes, check the documentation.

openfisca_core.holders.set_input_divide_by_period(holder, period, array)[source]

This function can be declared as a set_input attribute of a variable.

In this case, the variable will accept inputs on larger periods that its definition period, and the value for the larger period will be divided between its subperiods.

To read more about set_input attributes, check the documentation.