diff --git a/openfisca_core/simulations/simulation_builder.py b/openfisca_core/simulations/simulation_builder.py index 71c37a352..29ec5d153 100644 --- a/openfisca_core/simulations/simulation_builder.py +++ b/openfisca_core/simulations/simulation_builder.py @@ -294,12 +294,12 @@ def add_default_group_entity(self, persons_ids, entity): persons_count = len(persons_ids) self.entity_ids[entity.plural] = persons_ids self.entity_counts[entity.plural] = persons_count - self.memberships[entity.plural] = numpy.arange( + self.memberships[entity.plural] = list(numpy.arange( 0, persons_count, dtype=numpy.int32 - ) - self.roles[entity.plural] = numpy.repeat( + )) + self.roles[entity.plural] = list(numpy.repeat( entity.flattened_roles[0], persons_count - ) + )) def add_group_entity(self, persons_plural, persons_ids, entity, instances_json): """ diff --git a/tests/core/test_axes.py b/tests/core/test_axes.py index eb0f58caa..e734e0476 100644 --- a/tests/core/test_axes.py +++ b/tests/core/test_axes.py @@ -350,3 +350,27 @@ def test_simulation_with_axes(tax_benefit_system): [0, 0, 0, 0, 0, 0] ) assert simulation.get_array("rent", "2018-11") == pytest.approx([0, 0, 3000, 0]) + +# Test for missing group entities with build_from_entities() + +def test_simulation_with_axes_missing_entities(tax_benefit_system): + input_yaml = """ + persons: + Alicia: {salary: {2018-11: 0}} + Javier: {} + Tom: {} + axes: + - + - count: 2 + name: rent + min: 0 + max: 3000 + period: 2018-11 + """ + data = test_runner.yaml.safe_load(input_yaml) + simulation = SimulationBuilder().build_from_entities(tax_benefit_system, data) + assert simulation.get_array("salary", "2018-11") == pytest.approx( + [0, 0, 0, 0, 0, 0] + ) + # Since a household is synthesized for each person, we have six: + assert simulation.get_array("rent", "2018-11") == pytest.approx([0, 0, 0, 3000, 0, 0])