from paramtools import Parameters
class TaxParams(Parameters):
defaults = {
"schema": {
"labels": {
"year": {
"type": "int",
"validators": {"range": {"min": 2013, "max": 2027}}
},
"marital_status": {
"type": "str",
"validators": {"choice": {"choices": ["single", "joint"]}}
},
},
"additional_members": {
"cpi_inflatable": {"type": "bool", "number_dims": 0},
"cpi_inflated": {"type": "bool", "number_dims": 0}
}
},
"standard_deduction": {
"title": "Standard deduction amount",
"description": "Amount filing unit can use as a standard deduction.",
"cpi_inflatable": True,
"cpi_inflated": True,
"type": "float",
"value": [
{"year": 2024, "marital_status": "single", "value": 13673.68},
{"year": 2024, "marital_status": "joint", "value": 27347.36},
{"year": 2025, "marital_status": "single", "value": 13967.66},
{"year": 2025, "marital_status": "joint", "value": 27935.33},
{"year": 2026, "marital_status": "single", "value": 7690.0},
{"year": 2026, "marital_status": "joint", "value": 15380.0}],
"validators": {
"range": {
"min": 0,
"max": 9e+99
}
}
},
}
params = TaxParams(
initial_state={"year": [2024, 2025, 2026]},
array_first=True
)
params.view_state()
{'year': [2024, 2025, 2026]}
params.standard_deduction
array([[13673.68, 27347.36], [13967.66, 27935.33], [ 7690. , 15380. ]])
params.from_array("standard_deduction")
[{'year': 2024, 'marital_status': 'single', 'value': 13673.68}, {'year': 2024, 'marital_status': 'joint', 'value': 27347.36}, {'year': 2025, 'marital_status': 'single', 'value': 13967.66}, {'year': 2025, 'marital_status': 'joint', 'value': 27935.33}, {'year': 2026, 'marital_status': 'single', 'value': 7690.0}, {'year': 2026, 'marital_status': 'joint', 'value': 15380.0}]
# query parameters
params.specification(year=2026, marital_status="single", use_state=False)
OrderedDict([('standard_deduction', [OrderedDict([('marital_status', 'single'), ('year', 2026), ('value', 7690.0)])])])
adjustment = {
"standard_deduction": [
{"year": 2026, "marital_status": "single", "value": 10000.0}
],
}
params.adjust(adjustment)
params.standard_deduction
array([[13673.68, 27347.36], [13967.66, 27935.33], [10000. , 15380. ]])
adjustment = {
"standard_deduction": 0,
}
params.adjust(adjustment)
params.standard_deduction
array([[0., 0.], [0., 0.], [0., 0.]])
adjustment["standard_deduction"] = "higher"
params.adjust(adjustment)
--------------------------------------------------------------------------- ValidationError Traceback (most recent call last) <ipython-input-8-d9ad03cf54d8> in <module> 1 adjustment["standard_deduction"] = "higher" ----> 2 params.adjust(adjustment) ~/Documents/ParamTools/paramtools/parameters.py in adjust(self, params_or_path, raise_errors, extend_adj) 183 184 if raise_errors and self._errors: --> 185 raise self.validation_error 186 187 if self.label_to_extend is not None and extend_adj: ValidationError: { "standard_deduction": [ "Not a valid number: higher." ] }
adjustment["standard_deduction"] = [{"marital_status": "single", "year": 2025, "value": -1}]
params.adjust(adjustment)
--------------------------------------------------------------------------- ValidationError Traceback (most recent call last) <ipython-input-14-208948dfbd1d> in <module> 1 adjustment["standard_deduction"] = [{"marital_status": "single", "year": 2025, "value": -1}] ----> 2 params.adjust(adjustment) ~/Documents/ParamTools/paramtools/parameters.py in adjust(self, params_or_path, raise_errors, extend_adj) 183 184 if raise_errors and self._errors: --> 185 raise self.validation_error 186 187 if self.label_to_extend is not None and extend_adj: ValidationError: { "standard_deduction": [ "standard_deduction[marital_status=single, year=2025] -1.0 < min 0 " ] }
defaults = {
"schema": {
"labels": {
"year": {
"type": "int",
"validators": {"range": {"min": 2013, "max": 2027}}
},
"marital_status": {
"type": "str",
"validators": {"choice": {"choices": ["single", "joint", "separate",
"headhousehold", "widow"]}}
},
},
"additional_members": {
"cpi_inflatable": {"type": "bool"},
"cpi_inflated": {"type": "bool"}
}
},
"personal_exemption": {
"title": "Personal Exemption",
"description": "A simple version of the personal exemption.",
"notes": "",
"cpi_inflatable": True,
"cpi_inflated": True,
"type": "float",
"value": 0,
"validators": {
"range": {
"min": 0,
}
}
},
"standard_deduction": {
"title": "Standard deduction amount",
"description": "Amount filing unit can use as a standard deduction.",
"cpi_inflatable": True,
"cpi_inflated": True,
"type": "float",
"value": [
{"year": 2024, "marital_status": "single", "value": 13673.68},
{"year": 2024, "marital_status": "joint", "value": 27347.36},
{"year": 2024, "marital_status": "separate", "value": 13673.68},
{"year": 2024, "marital_status": "headhousehold", "value": 20510.52},
{"year": 2024, "marital_status": "widow", "value": 27347.36},
{"year": 2025, "marital_status": "single", "value": 13967.66},
{"year": 2025, "marital_status": "joint", "value": 27935.33},
{"year": 2025, "marital_status": "separate", "value": 13967.66},
{"year": 2025, "marital_status": "headhousehold", "value": 20951.49},
{"year": 2025, "marital_status": "widow", "value": 27935.33}],
"validators": {
"range": {
"min": 0,
"max": 9e+99
}
}
},
}
class Params(Parameters):
defaults = defaults
params = Params()
params.personal_exemption
[OrderedDict([('value', 0.0)])]