Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve speed when input variables are enums #315

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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