Repository navigation
Conversation
The group-to-group divide branch divided each (source, target) pair row by the source's member count, so a source whose n members touched k targets kept k/n of its value. It now weights each pair row by the members that pair holds, value * pair_count / source_count, so a source's shares add up to its value. Hypothesis properties cover crossing and nested tax units, SPM units and households in both person-link layouts. Fixes #768 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round-1 review and a mutation sweep found test gaps. The random cases now shuffle every table, add memberless groups, draw household weights and map two value columns. New properties check weighted totals, each target's share against a person-by-person count, and the values= return type. The coarse-to-fine sum pin covers household and SPM unit sources, and a fixed case pins a member with no target link. Totals compare with an absolute tolerance so exact zeros pass. The map_to_entity docstrings, the divide comment and the guide now say how group-to-group divide splits a value and what happens to unlinked members and memberless groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…olumns Round-2 review found three regressions against main in the divide branch. value * pair_count overflowed int64 and turned large floats into inf; merging the counts into the source rows collided with source columns of the same name; and a NaN pair count for an unlinked member made the counts float, so Decimal amounts raised TypeError. The branch now drops rows without a target first, looks the integer counts up on a frame of keys alone, and divides before it multiplies. All three groupbys pass observed=True, so categorical links on pandas 2.x no longer build every category pair. New tests pin each counterexample, check that reweighting people changes no share, and check categorical links against plain ones. The changelog now says a group passes on its whole value when all its members link to target groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #768
Group-to-group
map_to_entity(how="divide")now splits each source value equally among the source's members and gives each target the shares of the members it holds. Each (source, target) pair row carriesvalue * pair_count / source_count, and the branch sums those rows by target. A source's shares add up to its value whichever targets its members sit in, so the $100 two-person tax unit in #768 maps to $100 in its household instead of $50. A member with no target link keeps its share out of every target, and a source with no members adds nothing, as in a group-to-persondividethat feeds a person-to-groupsum.tests/test_entity_mapping_group_properties.pyadds Hypothesis properties over random households of tax units and SPM units, crossing and nested, in both person-link layouts. The random tables list their rows in shuffled order and may hold a group with no members. Each household draws a weight its people and groups share, and every group carries two value columns.dividekeeps each column's total over the sources with members, for every ordered pair of tax unit, SPM unit and household, and returns the target table's groups in the table's order;dividematches a group-to-persondividethat feeds a person-to-groupsum;values=returns a weightedMicroSeriesthat matches naming the column;sumkeeps the total and agrees withdivide;sumfrom a household or SPM unit gives each group inside it the containing group's value, as it does today.Three fixed cases cover the $100 unit, a $300 unit that splits 200/100 across two SPM units, and a member with no household link. On main, seven of the ten tests fail. The
values=test, thesumpin and the missing-link case pass on both. The tests callpolicyengine.core.map_to_entityon plain tables and run without a country model underpytest --noconftest. Themap_to_entitydocstrings and.claude/policyengine-guide.mdnow describe the group-to-group split.sumkeeps its current behavior. #769 asks howAggregateshould total a group value at a finer entity.🤖 Generated with Claude Code