Open
Conversation
baogorek
approved these changes
Apr 6, 2026
Collaborator
baogorek
left a comment
There was a problem hiding this comment.
Looks good to me. Completely optional, but here's an argument for context managers over try/finally:
For a two-line body the try/finally is a lot of ceremony. pd.HDFStore supports with, so:
with self.raw_cps(require=True).load() as raw_data:
raw_person = raw_data["person"]
cps["is_married"] = raw_person.A_MARITL.isin([1, 2]).values
Same behavior, less noise. I'd recommend context managers throughout if the PR author wants to close these
handles.
| raw_data[entity] for entity in ENTITIES | ||
| ] | ||
| raw_data = self.raw_cps(require=True).load() | ||
| try: |
Collaborator
There was a problem hiding this comment.
the try/finally is arguably overkill as the list comprehension over a fixed ENTITIES constant is unlikely to fail. A context manager (with) would be cleaner if the HDFStore supports it (and Pandas HDFStore does)
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.
Summary
Testing
UV_PYTHON=3.14 uv run pytest tests/unit/datasets/test_cps_file_handles.py tests/unit/datasets/test_cps_takeup.py tests/unit/test_extended_cps.py -qpython3 -m py_compile policyengine_us_data/datasets/cps/cps.py tests/unit/datasets/test_cps_file_handles.pyUV_PYTHON=3.14 uv run ruff format --check policyengine_us_data/datasets/cps/cps.py tests/unit/datasets/test_cps_file_handles.py