Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions extropy/population/sampler/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ def _sample_dependent_as_agent(
agent["household_id"] = household_id
agent["household_role"] = f"dependent_{dependent.relationship}"
agent["relationship_to_primary"] = dependent.relationship
dep_name = str(getattr(dependent, "name", "")).strip()
if dep_name:
agent["first_name"] = dep_name
if parent.get("last_name"):
agent["last_name"] = parent["last_name"]

# Copy household-scoped attributes from parent
for attr in spec.attributes:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_agent_focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,28 @@ def test_different_focus_values(self):
for focus in ["surgeons", "retired couples", "families", None]:
spec = _make_household_spec(size=100, agent_focus=focus)
assert spec.meta.agent_focus == focus


class TestPromotedDependentNames:
def test_promoted_dependents_preserve_household_names(self):
spec = _make_household_spec(size=240, agent_focus="families")
result = sample_population(spec, count=240, seed=42)

promoted = [
a
for a in result.agents
if a.get("household_role", "").startswith("dependent_")
]
assert promoted, "Expected promoted dependents in families mode"

households = {h["id"]: h for h in getattr(result, "_households", [])}
for dep in promoted:
first_name = dep.get("first_name")
assert first_name, "Promoted dependents must have first_name"

hh = households.get(dep["household_id"])
assert hh is not None
dependent_names = {d.get("name") for d in hh.get("dependent_data", [])}
assert first_name in dependent_names, (
"Promoted dependent names should stay aligned with generated dependent records"
)
Loading