@@ -228,6 +228,36 @@ def attach_legacy_benefit_proxies_from_frs_person(
228228 )
229229
230230
231+ def derive_is_parent_from_frs_microdata (
232+ person_ids ,
233+ person_benunit_ids ,
234+ adult_person_ids ,
235+ benunit_ids ,
236+ dependent_children ,
237+ ) -> np .ndarray :
238+ """Identify FRS adults in benefit units with dependent children.
239+
240+ FRS benefit units contain either one adult or a couple plus any dependent
241+ children. Using the raw adult table and benefit-unit dependent-child count
242+ avoids ranking adults across the whole household when multiple benefit
243+ units share a household.
244+ """
245+
246+ dependent_children_by_benunit = pd .Series (
247+ np .asarray (dependent_children , dtype = float ),
248+ index = np .asarray (benunit_ids ),
249+ )
250+ has_dependent_children = (
251+ pd .Series (np .asarray (person_benunit_ids ))
252+ .map (dependent_children_by_benunit )
253+ .fillna (0 )
254+ .to_numpy ()
255+ > 0
256+ )
257+ is_adult_record = np .isin (np .asarray (person_ids ), np .asarray (adult_person_ids ))
258+ return is_adult_record & has_dependent_children
259+
260+
231261def _as_non_negative_array (values ) -> np .ndarray :
232262 values = np .asarray (values , dtype = float )
233263 return np .maximum (np .nan_to_num (values , nan = 0.0 ), 0.0 )
@@ -443,6 +473,23 @@ def create_frs(
443473 pe_person ["hours_worked" ] = np .maximum (person .tothours , 0 ) * 52
444474 pe_person ["is_household_head" ] = person .hrpid == 1
445475 pe_person ["is_benunit_head" ] = person .uperson == 1
476+ dependent_children = (
477+ benunit .depchldb
478+ if "depchldb" in benunit
479+ else frs ["child" ]
480+ .groupby ("benunit_id" )
481+ .size ()
482+ .reindex (benunit .benunit_id )
483+ .fillna (0 )
484+ .to_numpy ()
485+ )
486+ pe_person ["is_parent" ] = derive_is_parent_from_frs_microdata (
487+ person_ids = pe_person .person_id ,
488+ person_benunit_ids = pe_person .person_benunit_id ,
489+ adult_person_ids = frs ["adult" ].person_id ,
490+ benunit_ids = pe_benunit .benunit_id ,
491+ dependent_children = dependent_children ,
492+ )
446493 MARITAL = [
447494 "MARRIED" ,
448495 "SINGLE" ,
0 commit comments