Skip to content

Commit

Permalink
Rename weight column
Browse files Browse the repository at this point in the history
Merge pull request #124 from openfisca/rename-weight-column-name
  • Loading branch information
Mauko Quiroga authored May 21, 2019
2 parents 728e2e4 + 6dc95ad commit 1ca1d06
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Changelog

## 0.22 [#123](https://github.com/openfisca/openfisca-survey-manager/pull/123)
## 0.23.0 [#124](https://github.com/openfisca/openfisca-survey-manager/pull/124)

* Rename weight_column_name_by_entity to weight_variable_by_entity

## 0.22.0 [#123](https://github.com/openfisca/openfisca-survey-manager/pull/123)

* Add github templates

## 0.21 [#122](https://github.com/openfisca/openfisca-survey-manager/pull/122)
## 0.21.0 [#122](https://github.com/openfisca/openfisca-survey-manager/pull/122)

* Use SimulationBuilder.join_with_persons to initialize entites

## 0.20 [#120](https://github.com/openfisca/openfisca-survey-manager/pull/120)
## 0.20.0 [#120](https://github.com/openfisca/openfisca-survey-manager/pull/120)

* Adapt to SimulatioBuilder shipping with openfisa-core v34

Expand Down
2 changes: 1 addition & 1 deletion openfisca_survey_manager/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _set_survey_scenario(self, survey_scenario):
self.filter_by = filter_by = survey_scenario.calculate_variable(
variable = self.filter_by_name, period = period)
# TODO: shoud not be france specific
self.weight_name = weight_name = self.survey_scenario.weight_column_name_by_entity['menage']
self.weight_name = weight_name = self.survey_scenario.weight_variable_by_entity['menage']
self.initial_weight_name = weight_name + "_ini"
self.initial_weight = initial_weight = survey_scenario.calculate_variable(
variable = weight_name, period = period)
Expand Down
18 changes: 9 additions & 9 deletions openfisca_survey_manager/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AbstractSurveyScenario(object):
trace = False
used_as_input_variables = None
used_as_input_variables_by_entity = None
weight_column_name_by_entity = None
weight_variable_by_entity = None
year = None

def build_input_data(self, **kwargs):
Expand Down Expand Up @@ -124,10 +124,10 @@ def compute_aggregate(self, variable = None, aggfunc = 'sum', filter_by = None,
assert filter_by in self.tax_benefit_system.variables, \
"{} is not a variables of the tax benefit system".format(filter_by)

if self.weight_column_name_by_entity:
weight_column_name_by_entity = self.weight_column_name_by_entity
if self.weight_variable_by_entity:
weight_variable_by_entity = self.weight_variable_by_entity
entity_key = tax_benefit_system.variables[variable].entity.key
entity_weight = weight_column_name_by_entity[entity_key]
entity_weight = weight_variable_by_entity[entity_key]
else:
entity_weight = None

Expand Down Expand Up @@ -195,8 +195,8 @@ def compute_pivot_table(self, aggfunc = 'mean', columns = None, difference = Fal

variables = set(index + values + columns)
# Select the entity weight corresponding to the variables that will provide values
if self.weight_column_name_by_entity is not None:
weight = self.weight_column_name_by_entity[entity_key]
if self.weight_variable_by_entity is not None:
weight = self.weight_variable_by_entity[entity_key]
variables.add(weight)
else:
log.debug('There is no weight variable for entity {}'.format(entity_key))
Expand Down Expand Up @@ -993,7 +993,7 @@ def neutralize_variables(self, tax_benefit_system):
continue
if self.non_neutralizable_variables and (variable_name in self.non_neutralizable_variables):
continue
if self.weight_column_name_by_entity and (variable_name in self.weight_column_name_by_entity.values()):
if self.weight_variable_by_entity and (variable_name in self.weight_variable_by_entity.values()):
continue

tax_benefit_system.neutralize_variable(variable_name)
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def summarize_variable(self, variable = None, use_baseline = False, weighted = F
value_type = variable_instance.value_type

if weighted:
weight_variable = self.weight_column_name_by_entity[variable_instance.entity.key]
weight_variable = self.weight_variable_by_entity[variable_instance.entity.key]
weights = simulation.calculate(weight_variable, simulation.period)

infos = simulation.get_memory_usage(variables = [variable])['by_variable'].get(variable)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def get_entity(survey_scenario, variable):

def get_weights(survey_scenario, variable):
entity = get_entity(survey_scenario, variable)
weight_variable = survey_scenario.weight_column_name_by_entity.get(entity.key)
weight_variable = survey_scenario.weight_variable_by_entity.get(entity.key)
return weight_variable


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
name = 'OpenFisca-Survey-Manager',
version = '0.20.1',
version = '0.23.0',
author = 'OpenFisca Team',
author_email = '[email protected]',
classifiers = [classifier for classifier in classifiers.split('\n') if classifier],
Expand Down

0 comments on commit 1ca1d06

Please sign in to comment.