Reforms#

The policyengine_core.reforms module contains the definition for Reform, a class which can be used to edit a TaxBenefitSystem instance.

Reform#

class policyengine_core.reforms.Reform(baseline: TaxBenefitSystem)[source]#

A modified TaxBenefitSystem

All reforms must subclass Reform and implement a method apply().

In this method, the reform can add or replace variables and call modify_parameters to modify the parameters of the legislation.

Example:

>>> from policyengine_core import reforms
>>> from policyengine_core.parameters import load_parameter_file
>>>
>>> def modify_my_parameters(parameters):
>>>     # Add new parameters
>>>     new_parameters = load_parameter_file(name='reform_name', file_path='path_to_yaml_file.yaml')
>>>     parameters.add_child('reform_name', new_parameters)
>>>
>>>     # Update a value
>>>     parameters.taxes.some_tax.some_param.update(period=some_period, value=1000.0)
>>>
>>>    return parameters
>>>
>>> class MyReform(reforms.Reform):
>>>    def apply(self):
>>>        self.add_variable(some_variable)
>>>        self.update_variable(some_other_variable)
>>>        self.modify_parameters(modifier_function = modify_my_parameters)
country_id: str = None#

The country id of the reform. This is used to inform any calls to the PolicyEngine API.

static from_api(api_id: str, country_id: str = None) Reform[source]#

Create a reform from a dictionary of parameters.

Parameters:

parameters – A dictionary of parameter -> { period -> value } pairs.

Returns:

A reform.

static from_dict(parameter_values: dict, country_id: str = None, name: str = None) Reform[source]#

Create a reform from a dictionary of parameters.

Parameters:

parameters – A dictionary of parameter -> { period -> value } pairs.

Returns:

A reform.

modify_parameters(modifier_function: Callable[[ParameterNode], ParameterNode]) None[source]#

Make modifications on the parameters of the legislation.

Call this function in apply() if the reform asks for legislation parameter modifications.

Parameters:

modifier_function – A function that takes a ParameterNode and should return an object of the same type.

name: str = None#

The name of the reform. This is used to identify the reform in the UI.

parameter_values: dict = None#

The parameter values of the reform. This is used to inform any calls to the PolicyEngine API.