Uh oh!
There was an error while loading. Please reload this page.
PNUM hard-coded and Vehicle table creation bug fix - #953
Conversation
Required to maintain backwards compatibility in tour indexes in SANDAG models
There was a problem hiding this comment.
Pull Request Overview
This PR adds fallback mechanisms for handling missing PNUM and auto_ownership columns to improve robustness in key model functions.
- vehicles.py: Falls back to
proto_householdswhenauto_ownershipis missing. - joint_tour_participation.py: Dynamically generates
PNUMfor candidates if absent. - joint_tour_frequency_composition.py: Selects point person via grouping when
PNUMis unavailable.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| activitysim/abm/tables/vehicles.py | Adds fallback for missing auto_ownership column |
| activitysim/abm/models/joint_tour_participation.py | Generates PNUM when absent for candidate numbering |
| activitysim/abm/models/joint_tour_frequency_composition.py | Introduces fallback for selecting point person if PNUM missing |
Comments suppressed due to low confidence (3)
activitysim/abm/tables/vehicles.py:32
- Add a unit test that supplies a DataFrame without
auto_ownershipto verify the fallback toproto_householdsand ensure the vehicles table still generates correctly.
if "auto_ownership" not in households.columns:
activitysim/abm/models/joint_tour_participation.py:63
- Introduce tests for the branch where
PNUMis missing to confirm that the generated numbering aligns with expected participant IDs.
if "PNUM" not in candidates.columns:
activitysim/abm/models/joint_tour_frequency_composition.py:149
- Add a test covering the fallback branch when
PNUMis absent to ensure the grouping logic selects the correct first person consistently.
if "PNUM" in persons.columns:
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dhensle
commented
Jul 22, 2025
@jpn-- I have addressed the Copilot reviews -- didn't accept them, but they are getting more sophisticated haha.. |
Fixes for #951 and #952
This pull request addresses robustness and fallback mechanisms in the
activitysimcodebase by ensuring proper handling of missing columns (PNUMandauto_ownership) in key functions. The changes improve the stability and reliability of the model by adding conditional checks and alternative logic.Enhancements to column handling:
joint_tour_frequency_composition.py: Added a fallback mechanism to handle cases where thePNUMcolumn is missing. IfPNUMis unavailable, the first person in each household is selected using stable ordering and grouping byhousehold_id.joint_tour_participation.py: Introduced logic to create aPNUMcolumn dynamically for candidates if it is missing, ensuring that participant IDs can still be assigned correctly.vehicles.py: Added a check for the presence of theauto_ownershipcolumn in thehouseholdsDataFrame. If missing, the function retrieves theproto_householdstable as a fallback to ensure compatibility during disaggregate accessibility calculations.