openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
170 stars 75 forks source link

Encapsulated entities do not preserve Enums within formulas #1085

Open nikhilwoodruff opened 2 years ago

nikhilwoodruff commented 2 years ago

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

Inside a formula, with defined encapsulated entities, decode an Enum variable:

str_enum = family.household("enum_variable", period).decode_to_str()

Here is what I expected to happen:

The string decodes in an array to be returned, just like what happens when I run:

simulation.calculate("family_enum_variable_returning_households_enum", period).decode_to_str()

Here is what actually happened:

AttributeError: 'numpy.ndarray' object has no attribute 'decode_to_str'

Here is data (or links to it) that can help you reproduce this issue:

Happy to add this as a test case to test_projectors and find a fix.

Context

I identify more as a:

Thanks!

nikhilwoodruff commented 2 years ago

On further inspection, I think the root cause of this is that GroupPopulation.value_nth_person does not preserve Enum status, returning only integer arrays.