Skip to content

Commit

Permalink
Fix Enum bug (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff authored Nov 1, 2024
1 parent 6833c2b commit cf80926
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Bug causing Enums to fail in some simulations.
10 changes: 9 additions & 1 deletion policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,15 @@ def _calculate(
array = holder.default_array()

if variable.defined_for is not None:
array = np.where(mask, array, np.zeros_like(array))
array = np.where(mask, array, variable.default_value)
if variable.value_type == Enum:
array = np.array(
[
item.index if isinstance(item, Enum) else item
for item in array
]
)
array = EnumArray(array, variable.possible_values)

array = self._cast_formula_result(array, variable)
holder.put_in_cache(array, period, self.branch_name)
Expand Down

0 comments on commit cf80926

Please sign in to comment.