Fix enum encoding for UTF-8 byte strings#488
Merged
Conversation
f88de77 to
d6f0183
Compare
d6f0183 to
a658c1f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #487
Context
This came up while comparing a staged PolicyEngine US data publication. The staged
US.h5file storedcounty/2024as an HDF5 fixed-width byte-string array, and 15 rows contained the valid enum member nameDOÑA_ANA_COUNTY_NMas UTF-8 bytes:policyengine-usalready hasDOÑA_ANA_COUNTY_NMin its county enum, and normal situation input with the Unicode string works. The failure was specific to dataset-backed simulation loading: h5py returns HDF5 string data as bytes, then Core's enum encoding path usedarray.astype(str), which attempts ASCII decoding and raises beforeMicrosimulation(dataset=...)can finish constructing.The intended conversion is:
Summary
ñcharacter is intentional because it exercises the non-ASCII byte-string decode failure.changelog.d/.Testing
uv run pytest tests/core/enums/test_enum.pyuv run ruff format policyengine_core/enums/enum.py tests/core/enums/test_enum.pyuv run ruff check policyengine_core/enums/enum.py tests/core/enums/test_enum.pyuv run --no-sync --with towncrier towncrier build --draft --version 0.0.0