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:
policyengine_core.parameters.at_instant_like.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'}} } })
- update(period=None, start=None, stop=None, value=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: Optional[str] = None, data: Optional[dict] = None, file_path: Optional[str] = None)[source]#
Bases:
policyengine_core.parameters.at_instant_like.AtInstantLike
A node in the legislation parameter tree.
- add_child(name: str, child: Union[policyengine_core.parameters.parameter_node.ParameterNode, policyengine_core.parameters.parameter.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
orParameter
orParameterNode
.
- attach_to_parent(parent: policyengine_core.parameters.parameter_node.ParameterNode)[source]#
- get_descendants() Iterable[Union[policyengine_core.parameters.parameter_node.ParameterNode, policyengine_core.parameters.parameter.Parameter]] [source]#
Return a generator containing all the parameters and nodes recursively contained in this ParameterNode
- merge(other: policyengine_core.parameters.parameter_node.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: policyengine_core.parameters.parameter_node.ParameterNode = None#
The parent of the node, or None if the node is the root of the tree.
ParameterAtInstant#
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: policyengine_core.parameters.parameter_node_at_instant.ParameterNodeAtInstant)[source]#
ParameterScale#
- class policyengine_core.parameters.parameter_scale.ParameterScale(name: str, data: dict, file_path: str)[source]#
Bases:
policyengine_core.parameters.at_instant_like.AtInstantLike
A parameter scale (for instance a marginal scale).
ParameterScaleBracket#
- class policyengine_core.parameters.parameter_scale_bracket.ParameterScaleBracket(name: str = '', directory_path: Optional[str] = None, data: Optional[dict] = None, file_path: Optional[str] = None)[source]#
Bases:
policyengine_core.parameters.parameter_node.ParameterNode
A parameter scale bracket.
- get_descendants() Iterable[policyengine_core.parameters.parameter.Parameter] [source]#
Return a generator containing all the parameters and nodes recursively contained in this ParameterNode
AtInstantLike#
- class policyengine_core.parameters.at_instant_like.AtInstantLike[source]#
Bases:
abc.ABC
Base class for various types of parameters implementing the at instant protocol.
- get_at_instant(instant: policyengine_core.periods.instant_.Instant) Any [source]#
VectorialParameterNodeAtInstant#
- class policyengine_core.parameters.vectorial_parameter_node_at_instant.VectorialParameterNodeAtInstant(name: str, vector: Union[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._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#
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
orParameterScale
orParameter
.