Skip to content

Derive microsimulation weights from household weights#497

Merged
MaxGhenis merged 1 commit into
masterfrom
derive-weights-from-household
May 17, 2026
Merged

Derive microsimulation weights from household weights#497
MaxGhenis merged 1 commit into
masterfrom
derive-weights-from-household

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

Fixes #438.
Refs #384.

Summary

  • Change Microsimulation.get_weights() to derive all entity weights from household_weight instead of looking up {entity}_weight variables.
  • Project household weights to persons and other group entities without relying on redundant stored weight variables.
  • Pass map_to through calculate_dataframe() weight lookup so mapped dataframes receive weights for the dataframe entity.

Verification

  • uv run --no-sync pytest tests/core/test_microsimulation_weights.py tests/core/test_microsimulation_person_accessor.py tests/core/test_subsample_invalidates_cache.py policyengine_core/country_template/tests/test_microsimulation.py -q
  • uv run --no-sync ruff format --check policyengine_core/simulations/microsimulation.py tests/core/test_microsimulation_weights.py
  • uv run --no-sync ruff check policyengine_core/simulations/microsimulation.py tests/core/test_microsimulation_weights.py
  • uvx --from towncrier towncrier build --draft --version 3.26.10

Documentation Review

  • Durable docs beyond source docstrings are not required: docs/python_api/simulations.md uses autodoc :members:, and get_weights() now documents that weights come from household_weight.
  • Impact: medium. Confidence: high.

@MaxGhenis MaxGhenis force-pushed the derive-weights-from-household branch from 9523e05 to 5dc1909 Compare May 17, 2026 18:39
@MaxGhenis MaxGhenis marked this pull request as ready for review May 17, 2026 18:44
@MaxGhenis MaxGhenis merged commit e9d8411 into master May 17, 2026
23 checks passed
@MaxGhenis MaxGhenis deleted the derive-weights-from-household branch May 17, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Microsimulation.get_weights() to always derive from household_weight

1 participant