Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions policyengine_uk/variables/household/demographic/is_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ def formula(person, period, parameters):

# Find two oldest members
benunit_ages = benunit.members("age", period)
first_highest = benunit.max(benunit_ages)
second_highest = benunit.max(
where(benunit_ages < first_highest, benunit_ages, -np.inf)
)
adult_index = person("adult_index", period)

# Get family types enum
family_types = family_type.possible_values

# For lone parents (FamilyType.LONE_PARENT), only the eldest is parent
is_lone_parent = (family_type == family_types.LONE_PARENT) & (
age == first_highest
adult_index == 1
)

# For couples with children (FamilyType.COUPLE_WITH_CHILDREN), two eldest are parents
is_couple_parent = (
family_type == family_types.COUPLE_WITH_CHILDREN
) & ((age == first_highest) | (age == second_highest))
) & ((adult_index == 1) | (adult_index == 2))

return is_lone_parent | is_couple_parent