You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wealth and consumption shares divide by a weighted total that can be zero #2296
shareholding, consumption_shareholding and consumer_incident_tax_revenue_change return inf or NaN for a simulation built from data when some household holds corporate wealth (or consumption) but the weighted total is zero. corporate_tax_incidence and household_tax inherit it.
Reproduction
Run on #2270's branch, policyengine-core 3.32.27; #2270 does not touch the dataset-built path this uses, so main gives the same:
Each formula tests the unweighted total and divides by the weighted one. In policyengine_uk/variables/household/wealth/shareholding.py:
if (
household.simulation.datasetisnotNoneandhousehold("corporate_sector_wealth", period).sum() !=0
):
weight=household("household_weight", period)
returnwealth/ (wealth*weight).sum()
consumption_share.py and contrib/policyengine/consumer_incident_tax_revenue_change.py do the same with consumption. When every household that holds the value has zero weight, the first total is not zero and the second is.
Suggested fix
Test the weighted total ((wealth * weight).sum() != 0), and take the existing no-data branch otherwise. Add a test with a zero-weight holder.
Scope
A full dataset has positive weighted totals, so its results are not affected. Subsamples and small frames can hit it: #2265 gives households that are not drawn a weight of zero, and from #2270 a simulation built from a DataFrame takes this branch too. Found in review of #2270, which leaves these formulas alone.
Activity