Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux committed Jun 22, 2017
1 parent 9b2b48e commit 5523d61
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions openfisca_core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ def filled_array(self, value, dtype = None):
warnings.simplefilter("ignore")
return np.full(self.count, value, dtype)

def get_holder(self, variable_name, init = True):
def get_holder(self, variable_name):
self.check_variable_defined_for_entity(variable_name)
holder = self._holders.get(variable_name)
if holder:
return holder
if not init:
return None
column = self.simulation.tax_benefit_system.get_column(variable_name)
self._holders[variable_name] = holder = Holder(
entity = self,
Expand Down
2 changes: 1 addition & 1 deletion openfisca_core/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_holder(self, column_name, default = UnboundLocalError):
)
column = self.tax_benefit_system.get_column(column_name, check_existence = True)
entity = self.entities[column.entity.key]
holder = entity.get_holder(column_name, init = False)
holder = entity._holders.get(column_name)
if holder:
return holder
if default is UnboundLocalError:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_calculate__holder_attribute_content():
variable_name = 'disposable_income'
period = "2014-01"
simulation.calculate(variable_name, period) # numpy.ndarray
simulation_holder = simulation.person.get_holder(variable_name, period)
simulation_holder = simulation.person.get_holder(variable_name)

assert issubclass(simulation_holder.formula.__class__, Formula)
assert len(simulation_holder.formula.dated_formulas) > 0 # contains formulas instances
2 changes: 1 addition & 1 deletion tests/core/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_clone__end_attribute__formulas__different_names():
month = '2005-01'
simulation = new_simulation(tax_benefit_system, month)
simulation.calculate('end_attribute__formulas__different_names', month)
simulation_holder = simulation.person.get_holder('end_attribute__formulas__different_names', month)
simulation_holder = simulation.person.get_holder('end_attribute__formulas__different_names')

# clone
variable_as_column = tax_benefit_system.column_by_name['end_attribute__formulas__different_names'] # IntCol
Expand Down

0 comments on commit 5523d61

Please sign in to comment.