Enhance entity mapping with flexible aggregation methods and custom values#184
Merged
nwoodruff-co merged 6 commits intomainfrom Nov 17, 2025
Merged
Enhance entity mapping with flexible aggregation methods and custom values#184nwoodruff-co merged 6 commits intomainfrom
nwoodruff-co merged 6 commits intomainfrom
Conversation
…alues Add support for custom values and multiple aggregation methods to the entity mapping system, making it more flexible for complex analysis workflows. Features added: - values parameter: Map custom value arrays instead of existing columns - Extended how parameter with new aggregation methods: * Person → Group: 'sum' (default), 'first' * Group → Person: 'project' (default), 'divide' * Group → Group: 'sum', 'first', 'project', 'divide' Refactoring: - Created base YearData class to eliminate code duplication - UKYearData and USYearData now inherit from base class - Removed duplicate map_to_entity implementations Documentation: - Added comprehensive entity mapping section to core-concepts.md - Added examples to UK and US model documentation - Documented all aggregation methods with use cases All existing tests pass, confirming backward compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive guides for AI assistants to use policyengine.py: - .claude/policyengine-guide.md: Detailed patterns and examples - .claude/quick-reference.md: Quick lookup for common operations Includes: - 7 common workflow patterns (synthetic scenarios, parameter sweeps, reforms) - Minimal working examples for UK and US - Entity mapping examples with all aggregation methods - Critical fields reference - Common parameters cheat sheet - Troubleshooting guide These guides help AI assistants quickly understand and use the package for tax-benefit microsimulation analysis. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add convenience methods to look up parameters and variables by name:
- get_parameter(name): Returns Parameter object by name
- get_variable(name): Returns Variable object by name
- Both raise ValueError if not found with helpful error messages
Tests added (12 tests, all passing):
- UK and US variable lookup tests
- UK and US parameter lookup tests
- Error handling tests for non-existent parameters/variables
- Multiple parameter/variable lookup tests
Usage:
var = uk_latest.get_variable('income_tax')
param = uk_latest.get_parameter('gov.hmrc.income_tax.allowances.personal_allowance.amount')
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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
This PR enhances the entity mapping system to support custom value arrays and multiple aggregation methods, making it more flexible for complex analysis workflows.
Changes
Core enhancements:
valuesparameter to map custom value arrays instead of requiring existing columnshowparameter with new aggregation methods:sum(default),firstproject(default),dividesum,first,project,divideRefactoring:
YearDataclass insrc/policyengine/core/dataset.pyUKYearDataandUSYearDatanow inherit from base classmap_to_entityimplementationsDocumentation:
docs/core-concepts.mdTesting
All existing tests pass, confirming backward compatibility:
tests/test_entity_mapping.py: 9 tests passingtests/test_us_entity_mapping.py: 5 tests passingUse cases
Example usage
Closes #183