openfisca / openfisca-core

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

Allow complete group encapsulation #1041

Closed nikhilwoodruff closed 2 years ago

nikhilwoodruff commented 3 years ago

In openfisca-uk, we have entities that are guaranteed to be completely hierachical. For example, a person can be a member of a benefit unit (nuclear family) and a household, but every person in the benefit unit will be in the same household. Variables at the benefit unit level often depend on properties of the household, and right now this is usually done via: (for example, say household_region is at the household level, and benunit_region is at the benefit unit level)

benunit_region = benunit.value_from_first_person(benunit.members.household("household_region", period))

I wonder if this could be simplified to:

benunit_region = benunit.household("household_region", period)

by making the .household function available to group entities (e.g. benefit unit) which specify that their members will have the same household membership.