Repository navigation
Conversation
anth-volk
marked this pull request as ready for review
October 29, 2026 17:55
2 of 3 tasks
anth-volk
force-pushed
the
skip-pycache-parameter-directories
branch
from
October 30, 2026 12:54
134734b to
6ab1d4f
Compare
anth-volk
changed the base branch from
master
to
fix-yaml-runner-tests-pytest-9-2
October 30, 2026 12:54
The subdirectory branch of ParameterNode's directory loader never checked EXCLUDED_PARAMETER_CHILD_NAMES, so a __pycache__ directory that Python writes into a parameter directory that is also an imported package became an empty child node. Whether that node existed depended on whether bytecode had been written, which changed policyengine.py's count of non-empty US parameter nodes by six. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
skip-pycache-parameter-directories
branch
from
October 30, 2026 13:03
6ab1d4f to
d4ff89c
Compare
This branch has not been deployed
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 #638
make format && make documentationhas been run. (ruff format --checkandruff checkwere run on the changed files only;make documentationwas not run.)Bug fix
What this fixes and how it's fixed
ParameterNode(directory_path=...)turns every subdirectory into a child node.EXCLUDED_PARAMETER_CHILD_NAMESalready lists__pycache__, but only the YAML-file branch and the inline-data branch check it; the subdirectory branch does not. Once Python has written bytecode into a parameter directory that is also a Python package, the tree gains an empty<directory>.__pycache__node.policyengine-us 2.2.1 has six parameter directories that hold only an
__init__.pyand CSV files:gov.hhs.medicaid.geographygov.hud.fmrgov.hud.income_limitsgov.hud.payment_standardsgov.states.fl.doe.sr.rates.reimbursementgov.states.tx.twc.ccs.payment.rates_expanded_age_groupsUS variable modules import these packages, so building the US system writes
__pycache__into them unless bytecode writing is off. Without the cache, each of these nodes has no children; with it, each has one empty__pycache__child. policyengine.py skips parameter nodes that have no children, so its US parameter-node count changes by 6 depending on whether those caches are on disk. The Public API's v2 catalog takes its parameter nodes from policyengine.py, which is why its exact-count integration test reported 29,361 nodes on macOS withPYTHONDONTWRITEBYTECODE=1and 29,367 elsewhere. The count follows the files on disk: with caches already written (for example bypip install's bytecode compilation or an earlier run),PYTHONDONTWRITEBYTECODE=1still gives the higher count.Change
__pycache__and hidden subdirectories (names starting with., such as.ipynb_checkpoints). A hidden directory name cannot form a valid dotted parameter name, and a Jupyter checkpoint directory would otherwise load duplicate copies of the parameters next to it.referenceis still excluded only as a YAML file name or data key, as before. A directory namedreferencestill loads.After this change, the loaded tree matches what loads when no bytecode cache exists.
Checked against policyengine-us 2.2.1 with policyengine-core 3.33.3 (the versions policyengine.py 6.11.1 pins) and this patch applied: 28,565
ParameterNodes, 28,559 of them with children, both with the nine__pycache__directories underparameters/on disk and with none. Without the patch, the run with caches had 28,574 and 28,565. policyengine-uk 2.132.6 has one package directory underparameters/(gov.dwp.LHA), and it also holds YAML parameters, so UK counts in policyengine.py do not change.Downstream effect: once policyengine.py bundles a release with this fix, the Public API's
tests/integration/test_v2_catalog_installed.pywill needparameter_nodesset to 29,361 instead of 29,367. The other counts in that test do not change.Tests
tests/core/parameters/test_parameter_directory_loading.py:test_bytecode_cache_does_not_change_parameter_nodesbuilds a parameter directory with one YAML parameter and one package directory that holds only a CSV, loads it, writes the package's bytecode cache withpy_compile, loads it again, and asserts the same node names both times and no children under the package node. Without the fix it fails becauselookup.__pycache__appears.test_hidden_directories_are_not_loadedasserts that a.ipynb_checkpointsdirectory inside a parameter directory is not loaded. Without the fix it fails because.ipynb_checkpointsbecomes a child node.uv run pytest tests(Python 3.14, macOS): 2,716 passed, 4 skipped, 3 xfailed.ruff format --checkandruff checkon the changed files: pass.policyengine-core test policyengine_core/country_template/tests -c policyengine_core.country_template: 39 passed.mypy.🤖 Generated with Claude Code