-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Summary
Add default_value and value_type fields to the Variable class in policyengine.py to expose these properties from policyengine-core.
Motivation
The policyengine-api-v2-alpha and policyengine-app-v2 need access to variable default values to properly initialize variables when users add them to household builders. Currently, the Variable class in policyengine.py only exposes:
id,name,entity,description,data_type,possible_values
But policyengine-core's Variable class also has:
default_value- the default value for the variable (e.g.,0for floats,Falsefor bools,"SINGLE"for enums)value_type- the Python type of the variable (float,bool,int,str,Enum,datetime.date)
Without these fields, downstream tools must load the entire country-specific CountryTaxBenefitSystem just to access default values, which defeats the purpose of policyengine.py as a consistent abstraction layer.
Changes Required
-
src/policyengine/core/variable.py: Add fields toVariableclass:default_value: Any = None value_type: type | None = None
-
src/policyengine/tax_benefit_models/us/model.pyanduk/model.py: Extract and serialize values:default_val = var_obj.default_value if var_obj.value_type is Enum: default_val = default_val.name elif var_obj.value_type is datetime.date: default_val = default_val.isoformat() variable = Variable( # ... existing fields ... default_value=default_val, value_type=var_obj.value_type, )
Supported value_types (from policyengine-core config)
| value_type | default |
|---|---|
bool |
False |
int |
0 |
float |
0 |
str |
"" |
Enum |
enum member name (string) |
datetime.date |
"1970-01-01" (ISO format) |
Branch
Implementation available on branch: feat/add-variable-default-value