Skip to content

Commit

Permalink
Merge pull request #315 from openfisca/fix_enums
Browse files Browse the repository at this point in the history
improve speed when input variables are enums
  • Loading branch information
clallemand authored Nov 8, 2024
2 parents 71c8795 + 181410d commit f0606ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion openfisca_survey_manager/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit f0606ad

Please sign in to comment.