Populations

class openfisca_core.populations.Population(entity)[source]
__call__(variable_name, period=None, options=None)[source]

Calculate the variable variable_name for the entity and the period period, using the variable formula if it exists.

Example: >>> person(“salary”, “2017-04”) >>> array([300.0])

Return type:

ndarray[Any, dtype[float]] | None

Returns:

A numpy array containing the result of the calculation

get_rank(entity, criteria, condition=True)[source]

Get the rank of a person within an entity according to a criteria. The person with rank 0 has the minimum value of criteria. If condition is specified, then the persons who don’t respect it are not taken into account and their rank is -1.

Example: >>> age = person(“age”, period) # e.g [32, 34, 2, 8, 1] >>> person.get_rank(household, age) >>> [3, 4, 0, 2, 1]

>>> is_child = person.has_role(
...     Household.CHILD
... )  # [False, False, True, True, True]
>>> person.get_rank(
...     household, -age, condition=is_child
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~numpy.ndarray\`\\ \\\[\:py\:data\:\`\~typing.Any\`\, \:py\:class\:\`\~numpy.dtype\`\\ \\\[\:py\:class\:\`int\`\]\]`

… ) # Sort in reverse order so that the eldest child gets the rank 0. >>> [-1, -1, 1, 0, 2]

has_role(role)[source]

Check if a person has a given role within its GroupEntity.

Example: >>> person.has_role(Household.CHILD) >>> array([False])

Return type:

ndarray[Any, dtype[bool]] | None

class openfisca_core.populations.GroupPopulation(entity, members)[source]
all(array, role=None)[source]

Return True if array is True for all members of the entity.

array must have the dimension of the number of persons in the simulation

If role is provided, only the entity member with the given role are taken into account.

Example: >>> salaries = household.members( … “salary”, “2018-01” … ) # e.g. [2000, 1500, 0, 0, 0] >>> household.all(salaries >= 1800) >>> array([False])

any(array, role=None)[source]

Return True if array is True for any members of the entity.

array must have the dimension of the number of persons in the simulation

If role is provided, only the entity member with the given role are taken into account.

Example: >>> salaries = household.members( … “salary”, “2018-01” … ) # e.g. [2000, 1500, 0, 0, 0] >>> household.any(salaries >= 1800) >>> array([True])

max(array, role=None)[source]

Return the maximum value of array for the entity members.

array must have the dimension of the number of persons in the simulation

If role is provided, only the entity member with the given role are taken into account.

Example: >>> salaries = household.members( … “salary”, “2018-01” … ) # e.g. [2000, 1500, 0, 0, 0] >>> household.max(salaries) >>> array([2000])

min(array, role=None)[source]

Return the minimum value of array for the entity members.

array must have the dimension of the number of persons in the simulation

If role is provided, only the entity member with the given role are taken into account.

Example: >>> salaries = household.members( … “salary”, “2018-01” … ) # e.g. [2000, 1500, 0, 0, 0] >>> household.min(salaries) >>> array([0]) >>> household.min( … salaries, role=Household.PARENT … ) # Assuming the 1st two persons are parents >>> array([1500])

nb_persons(role=None)[source]

Returns the number of persons contained in the entity.

If role is provided, only the entity member with the given role are taken into account.

sum(array, role=None)[source]

Return the sum of array for the members of the entity.

array must have the dimension of the number of persons in the simulation

If role is provided, only the entity member with the given role are taken into account.

Example: >>> salaries = household.members( … “salary”, “2018-01” … ) # e.g. [2000, 1500, 0, 0, 0] >>> household.sum(salaries) >>> array([3500])