Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
pblayo committed Nov 28, 2018
1 parent cb89719 commit 89bfe88
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
59 changes: 0 additions & 59 deletions openfisca_core/holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import psutil

from openfisca_core import periods
from openfisca_core.columns import make_column_from_variable
from openfisca_core.commons import empty_clone
from openfisca_core.data_storage import InMemoryStorage, OnDiskStorage
from openfisca_core.errors import PeriodMismatchError
Expand Down Expand Up @@ -267,64 +266,6 @@ def default_array(self):
array.fill(self.variable.default_value)
return array

# Legacy method used by the old OpenFisca Web API to display intermediate results
def to_value_json(self, use_label = False):
column = make_column_from_variable(self.variable)
transform_dated_value_to_json = column.transform_dated_value_to_json

def extra_params_to_json_key(extra_params, period):
return '{' + ', '.join(
['{}: {}'.format(name, value)
for name, value in zip(self.get_extra_param_names(period), extra_params)]
) + '}'

if self.variable.definition_period == ETERNITY:
array = self.get_array(None)
if array is None:
return None
return [
transform_dated_value_to_json(cell, use_label = use_label)
for cell in array.tolist()
]
value_json = {}
for period, array_or_dict in self._memory_storage._arrays.items():
if type(array_or_dict) == dict:
values_dict = {}
for extra_params, array in array_or_dict.items():
extra_params_key = extra_params_to_json_key(extra_params, period)
values_dict[str(extra_params_key)] = [
transform_dated_value_to_json(cell, use_label = use_label)
for cell in array.tolist()
]
value_json[str(period)] = values_dict
else:
value_json[str(period)] = [
transform_dated_value_to_json(cell, use_label = use_label)
for cell in array_or_dict.tolist()
]
if self._disk_storage:
for period, file_or_dict in self._disk_storage._files.items():
if type(file_or_dict) == dict:
values_dict = {}
for extra_params, file in file_or_dict.items():
extra_params_key = extra_params_to_json_key(extra_params, period)
values_dict[str(extra_params_key)] = [
transform_dated_value_to_json(cell, use_label = use_label)
for cell in np.load(file).tolist()
]
value_json[str(period)] = values_dict
else:
value_json[str(period)] = [
transform_dated_value_to_json(cell, use_label = use_label)
for cell in np.load(file_or_dict).tolist()
]
return value_json

# Legacy method called by to_value_json
def get_extra_param_names(self, period):
formula = self.variable.get_formula(period)
return formula.__code__.co_varnames[3:]


def set_input_dispatch_by_period(holder, period, array):
"""
Expand Down
18 changes: 0 additions & 18 deletions tests/core/test_extra_params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals, print_function, division, absolute_import
from nose.tools import assert_equal

from openfisca_core import periods
from openfisca_core.periods import MONTH
Expand Down Expand Up @@ -70,23 +69,6 @@ def test_cache():
assert_near(formula_2_result, [1])


def test_get_extra_param_names():
simulation = get_simulation()
formula_3_holder = simulation.person.get_holder('formula_3')
assert formula_3_holder.get_extra_param_names(reference_period) == ('choice',)


def test_json_conversion():
simulation = get_simulation()
simulation.calculate('formula_1', period = reference_period)
simulation.calculate('formula_2', period = reference_period)
formula_3_holder = simulation.person.get_holder('formula_3')
assert_equal(
formula_3_holder.to_value_json(),
{'2013-01': {'{choice: 1}': [1], '{choice: 0}': [0]}}
)


def test_base_functions():
simulation = get_simulation()
assert simulation.calculate('formula_4', '2013-01', extra_params = [0]) == 0
Expand Down

0 comments on commit 89bfe88

Please sign in to comment.