From 7557233b21c26d3af6c0c5f166dc490e23bc9e81 Mon Sep 17 00:00:00 2001 From: clallemand <=> Date: Fri, 8 Nov 2024 16:00:35 +0100 Subject: [PATCH 1/2] improve speed when input variables are enums --- openfisca_survey_manager/simulations.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openfisca_survey_manager/simulations.py b/openfisca_survey_manager/simulations.py index b42f5b95..e700a39b 100644 --- a/openfisca_survey_manager/simulations.py +++ b/openfisca_survey_manager/simulations.py @@ -14,7 +14,7 @@ from openfisca_core import periods from openfisca_core.memory_config import MemoryConfig -from openfisca_core.indexed_enums import Enum +from openfisca_core.indexed_enums import (Enum, EnumArray) from openfisca_core.periods import ETERNITY, MONTH, YEAR from openfisca_core.types import Array, CoreEntity as Entity, Period, TaxBenefitSystem from openfisca_core.simulations import Simulation @@ -1094,6 +1094,10 @@ def init_variable_in_entity(simulation: Simulation, entity, variable_name, serie array = series.values.astype(variable.dtype) np_array = np.array(array, dtype = variable.dtype) + + if (variable.value_type == Enum) and (np.issubdtype(series.values.dtype, np.integer) or np.issubdtype(series.values.dtype, float)): + np_array = EnumArray(np_array, variable.possible_values) + if variable.definition_period == YEAR and period.unit == MONTH: # Some variables defined for a year are present in month/quarter dataframes # Cleaning the dataframe would probably be better in the long run From 181410daed27f55a7aad6d27c97aad7c3009d348 Mon Sep 17 00:00:00 2001 From: clallemand <=> Date: Fri, 8 Nov 2024 16:08:26 +0100 Subject: [PATCH 2/2] setup + changelog --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c88ef64..681af78e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog + +### 3.3.2 [#319](https://github.com/openfisca/openfisca-survey-manager/pull/315) + +* Technical changes + - Transform input arrays of Enums variables in EnumArray type to improve computation speed due to changes in Openfisca-core 42 + ### 2.3.1 [#300](https://github.com/openfisca/openfisca-survey-manager/pull/300) * New features diff --git a/setup.py b/setup.py index 89d0c42f..57a99426 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ setup( name = 'OpenFisca-Survey-Manager', - version = '2.3.1', + version = '2.3.2', author = 'OpenFisca Team', author_email = 'contact@openfisca.fr', classifiers = [classifier for classifier in classifiers.split('\n') if classifier],