Skip to content

Commit

Permalink
fix: Replace numpy-Python comparison with dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed May 8, 2024
1 parent ac7317c commit bf0a54d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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:
changed:
- Replaced unsafe numpy-Python comparison with use of numpy dtype to convert byte-string arrays to Unicode ones within enums
7 changes: 5 additions & 2 deletions policyengine_core/enums/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ def encode(cls, array: Union[EnumArray, np.ndarray]) -> EnumArray:
if isinstance(array, EnumArray):
return array

# if array.dtype.kind == "b":
if isinstance(array == 0, bool):
# First, convert byte-string arrays to Unicode-string arrays
# Confusingly, Numpy uses "S" to refer to byte-string arrays
# and "U" to refer to Unicode-string arrays, which are also
# referred to as the "str" type
if array.dtype.kind == "S":
# Convert boolean array to string array
array = array.astype(str)

Expand Down

0 comments on commit bf0a54d

Please sign in to comment.