Parameters#

The policyengine_core.parameters module contains the classes that define how parameters function. This mainly revolves around the ‘at-instant’ pattern: parameters are defined as a function of time, and are evaluated at a given instant.

Parameter#

class policyengine_core.parameters.parameter.Parameter(name: str, data: dict, file_path: Optional[str] = None)[source]#

Bases: AtInstantLike

A parameter of the legislation.

Parameters can change over time.

values_list#

List of the values, in reverse chronological order.

Parameters:
  • name – Name of the parameter, e.g. “taxes.some_tax.some_param”.

  • data – Data loaded from a YAML file.

  • file_path – File the parameter was loaded from.

Instantiate a parameter without metadata:

>>>  Parameter('rate', data = {
        "2015-01-01": 550,
        "2016-01-01": 600
        })

Instantiate a parameter with metadata:

>>>  Parameter('rate', data = {
        'description': 'Income tax rate applied on salaries',
        'values': {
            "2015-01-01": {'value': 550, 'metadata': {'reference': 'http://taxes.gov/income_tax/2015'}},
            "2016-01-01": {'value': 600, 'metadata': {'reference': 'http://taxes.gov/income_tax/2016'}}
            }
        })
clone()[source]#
get_descendants()[source]#
mark_as_modified()[source]#
relative_change(start_instant, end_instant)[source]#
update(value=None, period=None, start=None, stop=None)[source]#

Change the value for a given period.

Parameters:
  • period – Period where the value is modified. If set, start and stop should be None.

  • start – Start of the period. Instance of policyengine_core.Instant. If set, period should be None.

  • stop – Stop of the period. Instance of policyengine_core.Instant. If set, period should be None.

  • value – New value. If None, the parameter is removed from the legislation parameters for the given period.

ParameterNode#

class policyengine_core.parameters.parameter_node.ParameterNode(name: str = '', directory_path: str = None, data: dict = None, file_path: str = None)[source]#

Bases: AtInstantLike

A node in the legislation parameter tree.

add_child(name: str, child: Union[ParameterNode, Parameter])[source]#

Add a new child to the node.

Parameters:
  • name – Name of the child that must be used to access that child. Should not contain anything that could interfere with the operator . (dot).

  • child – The new child, an instance of ParameterScale or Parameter or ParameterNode.

attach_to_parent(parent: ParameterNode)[source]#
clear_parent_cache()[source]#
clone() ParameterNode[source]#
get_child(path: str) ParameterNode[source]#
get_descendants() Iterable[Union[ParameterNode, Parameter]][source]#

Return a generator containing all the parameters and nodes recursively contained in this ParameterNode

mark_as_modified()[source]#
merge(other: ParameterNode) None[source]#

Merges another ParameterNode into the current node.

In case of child name conflict, the other node child will replace the current node child.

parent: ParameterNode = None#

The parent of the node, or None if the node is the root of the tree.

ParameterAtInstant#

class policyengine_core.parameters.parameter_at_instant.ParameterAtInstant(name: str, instant_str: str, data: dict = None, file_path: str = None, metadata: dict = None)[source]#

Bases: object

A value of a parameter at a given instant.

clone() ParameterAtInstant[source]#
validate(data: dict) None[source]#

ParameterNodeAtInstant#

class policyengine_core.parameters.parameter_node_at_instant.ParameterNodeAtInstant(name: str, node: ParameterNode, instant_str: str)[source]#

Bases: object

Parameter node of the legislation, at a given instant.

add_child(child_name: str, child_at_instant: ParameterNodeAtInstant)[source]#

ParameterScale#

class policyengine_core.parameters.parameter_scale.ParameterScale(name: str, data: dict, file_path: str)[source]#

Bases: AtInstantLike

A parameter scale (for instance a marginal scale).

clone() ParameterScale[source]#
get_descendants() Iterable[source]#
propagate_units() None[source]#
propagate_uprating() None[source]#

ParameterScaleBracket#

class policyengine_core.parameters.parameter_scale_bracket.ParameterScaleBracket(name: str = '', directory_path: str = None, data: dict = None, file_path: str = None)[source]#

Bases: ParameterNode

A parameter scale bracket.

static allowed_unit_keys()[source]#
get_descendants() Iterable[Parameter][source]#

Return a generator containing all the parameters and nodes recursively contained in this ParameterNode

propagate_uprating(uprating: str, threshold: bool = False) None[source]#

AtInstantLike#

class policyengine_core.parameters.at_instant_like.AtInstantLike[source]#

Bases: ABC

Base class for various types of parameters implementing the at instant protocol.

get_at_instant(instant: Instant) Any[source]#

VectorialParameterNodeAtInstant#

class policyengine_core.parameters.vectorial_parameter_node_at_instant.VectorialParameterNodeAtInstant(name: str, vector: Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], instant_str: str)[source]#

Bases: object

Parameter node of the legislation at a given instant which has been vectorized. Vectorized parameters allow requests such as parameters.housing_benefit[zipcode], where zipcode is a vector

static build_from_node(node: ParameterNode) VectorialParameterNodeAtInstant[source]#
static check_node_vectorisable(node: ParameterNode) None[source]#

Check that a node can be casted to a vectorial node, in order to be able to use fancy indexing.

contains_nan#

policyengine_core.parameters.helpers.contains_nan(vector)[source]#

load_parameter_file#

policyengine_core.parameters.helpers.load_parameter_file(file_path, name='')[source]#

Load parameters from a YAML file (or a directory containing YAML files).

Returns:

An instance of ParameterNode or ParameterScale or Parameter.