Skip to content

Commit

Permalink
Merge pull request #286 from openfisca/ponderations-compute-aggregate
Browse files Browse the repository at this point in the history
Améliore la gestion des poids dans compute_aggregate
  • Loading branch information
bfabre01 authored Feb 12, 2024
2 parents 5f3b802 + 50eaa4b commit 95351a0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions openfisca_survey_manager/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,24 @@ def compute_aggregate(simulation: Simulation, variable: str = None, aggfunc: str
if variable in simulation.tax_benefit_system.variables:
value = simulation.adaptative_calculate_variable(variable = variable, period = period)
else:
log.debug("Variable {} not found. Assiging {}".format(variable, missing_variable_default_value))
log.debug("Variable {} not found. Assigning {}".format(variable, missing_variable_default_value))
return missing_variable_default_value

# The following lines allow for under-yearly weighted aggregates even if weights are annual
if weighted and weight_variable is not None:
period_size_independent_weight = tax_benefit_system.get_variable(weight_variable).is_period_size_independent
definition_period_weight = tax_benefit_system.get_variable(weight_variable).definition_period
if not isinstance(period, periods.Period):
period = periods.period(str(period))
if period_size_independent_weight is True and definition_period_weight == 'year' and period.start.year == period.stop.year:
period_computation_weights = period.this_year
else:
period_computation_weights = period
else:
period_computation_weights = period

weight = (
simulation.calculate(weight_variable, period = period).astype(float)
simulation.calculate(weight_variable, period = period_computation_weights).astype(float)
if weight_variable else uniform_weight
)
if weight_variable:
Expand Down

0 comments on commit 95351a0

Please sign in to comment.