Skip to content

Commit

Permalink
Préfère numpy à np
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauko Quiroga committed Jan 5, 2020
1 parent ebef02d commit f0f60f2
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
python openfisca_france/scripts/performance/measure_calculations_performance.py
"""


import argparse
import logging
import sys
import time

import numpy as np
import numpy

from openfisca_core import periods, simulations
from openfisca_core.tools import assert_near
from openfisca_france import FranceTaxBenefitSystem


args = None
logger = logging.getLogger(__name__)

Expand All @@ -35,13 +34,13 @@ def add_member(entity, **variables_value_by_name):
for variable_name, variable_holder in entity.holder_by_name.items():
column = variable_holder.variable
if column.definition_period is ETERNITY: # noqa F821
variable_holder._array = np.hstack((variable_holder._array, [column.default_value]))
variable_holder._array = numpy.hstack((variable_holder._array, [column.default_value]))
else:
array_by_period = variable_holder._array_by_period
if array_by_period is None:
variable_holder._array_by_period = array_by_period = {}
for period, array in array_by_period.items():
array_by_period[period] = np.hstack((array, [column.default_value]))
array_by_period[period] = numpy.hstack((array, [column.default_value]))

# When entity is a person, ensure that the index & role of the person in the other entities are set.
value_by_name = variables_value_by_name.copy()
Expand All @@ -64,15 +63,15 @@ def add_member(entity, **variables_value_by_name):
for period, period_value in value.items():
array = variable_holder.get_array(period)
if array is None:
array = np.empty(entity.count, dtype = column.dtype)
array = numpy.empty(entity.count, dtype = column.dtype)
array.fill(column.default_value)
variable_holder.put_in_cache(array, period)
array[member_index] = period_value
else:
period = simulation.period
array = variable_holder.get_array(period)
if array is None:
array = np.empty(entity.count, dtype = column.dtype)
array = numpy.empty(entity.count, dtype = column.dtype)
array.fill(column.default_value)
variable_holder.put_in_cache(array, period)
array[member_index] = value
Expand Down

0 comments on commit f0f60f2

Please sign in to comment.