From 998c96bc3f5de1f63c14b36b3dd2b31cf643ccc4 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Thu, 3 Apr 2025 16:14:07 +0100 Subject: [PATCH] Add fix to is_parent --- .../variables/household/demographic/is_parent.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/policyengine_uk/variables/household/demographic/is_parent.py b/policyengine_uk/variables/household/demographic/is_parent.py index 415bae7aa..540c8202d 100644 --- a/policyengine_uk/variables/household/demographic/is_parent.py +++ b/policyengine_uk/variables/household/demographic/is_parent.py @@ -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