Skip to content

Conversation

@dhensle
Copy link
Contributor

@dhensle dhensle commented Jun 11, 2025

Fixes for #951 and #952

This pull request addresses robustness and fallback mechanisms in the activitysim codebase by ensuring proper handling of missing columns (PNUM and auto_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 the PNUM column is missing. If PNUM is unavailable, the first person in each household is selected using stable ordering and grouping by household_id.

  • joint_tour_participation.py: Introduced logic to create a PNUM column 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 the auto_ownership column in the households DataFrame. If missing, the function retrieves the proto_households table as a fallback to ensure compatibility during disaggregate accessibility calculations.

dhensle and others added 4 commits June 2, 2025 11:09
@jpn-- jpn-- requested a review from Copilot July 17, 2025 16:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_households when auto_ownership is missing.
  • joint_tour_participation.py: Dynamically generates PNUM for candidates if absent.
  • joint_tour_frequency_composition.py: Selects point person via grouping when PNUM is 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_ownership to verify the fallback to proto_households and 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 PNUM is 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 PNUM is absent to ensure the grouping logic selects the correct first person consistently.
    if "PNUM" in persons.columns:

@dhensle
Copy link
Contributor Author

dhensle commented Jul 22, 2025

@jpn-- I have addressed the Copilot reviews -- didn't accept them, but they are getting more sophisticated haha..

@jpn-- jpn-- merged commit 6a553fc into ActivitySim:main Jul 31, 2025
16 of 17 checks passed
@dhensle dhensle deleted the SimOR_development branch August 1, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants