From 6dc95ad336fbf806fbe92bf9eb9d1d02440ff0ec Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 16 May 2019 11:56:38 +0200 Subject: [PATCH] [Fix #64] Rename weight column Rename weight_column_name_by_entity to weight_variable_by_entity --- CHANGELOG.md | 10 +++++++--- openfisca_survey_manager/calibration.py | 2 +- openfisca_survey_manager/scenarios.py | 18 +++++++++--------- setup.py | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9455e0b3..17bac78d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/openfisca_survey_manager/calibration.py b/openfisca_survey_manager/calibration.py index 28a77750..580264b5 100644 --- a/openfisca_survey_manager/calibration.py +++ b/openfisca_survey_manager/calibration.py @@ -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) diff --git a/openfisca_survey_manager/scenarios.py b/openfisca_survey_manager/scenarios.py index 3dd360bb..c5ca796f 100644 --- a/openfisca_survey_manager/scenarios.py +++ b/openfisca_survey_manager/scenarios.py @@ -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): @@ -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 @@ -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)) @@ -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) @@ -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) @@ -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 diff --git a/setup.py b/setup.py index f3e619df..a754dbf0 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ setup( name = 'OpenFisca-Survey-Manager', - version = '0.20.1', + version = '0.23.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.fr', classifiers = [classifier for classifier in classifiers.split('\n') if classifier],