Skip to content

Stable sort for school escorting#1085

Open
americalexander wants to merge 3 commits into
ActivitySim:mainfrom
RSGInc:stable_sort
Open

Stable sort for school escorting#1085
americalexander wants to merge 3 commits into
ActivitySim:mainfrom
RSGInc:stable_sort

Conversation

@americalexander

@americalexander americalexander commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Address multiple locations where the school escorting model does not sort in a stable manner. Also use 64-bit integers for tour and person IDs.

Changes

Stable Sorting

Added kind=""stable"" to sort_values calls throughout the school escorting model to ensure deterministic, reproducible results regardless of the initial row ordering of input data. Without stable sorting, ties in the sort key can be broken arbitrarily, leading to non-reproducible outputs across runs or platforms.

Affected locations:

  • determine_escorting_participants: stable sort of chaperones by chaperone_weight (descending) when assigning chaperone_num, and stable sort of escortees by age (ascending) when assigning escortee_num
  • school_escorting: stable sort of school escort tours by household_id and school_escort_direction before further processing
  • create_pure_school_escort_tours: stable sort of pure escort tours by household_id, person_id, and start time

64-bit Integer Types

Replaced .astype(int) with .astype(""int64"") for tour IDs, person IDs, and related integer columns. Using the platform-native int type can produce 32-bit integers on Windows, which risks integer overflow for large ID values and inconsistent behavior across operating systems.

Affected locations:

  • chauf_num and chauf_id in create_school_escorting_bundles_table
  • Column values in join_attributes
  • tour_id in create_chauf_escort_trips
  • num_escortees in process_tours_after_escorting_model

@americalexander americalexander marked this pull request as ready for review June 24, 2026 21:28
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.

1 participant