diff --git a/activitysim/abm/models/school_escorting.py b/activitysim/abm/models/school_escorting.py index d24d52a41..421097e24 100644 --- a/activitysim/abm/models/school_escorting.py +++ b/activitysim/abm/models/school_escorting.py @@ -85,13 +85,15 @@ def determine_escorting_participants( ) chaperones["chaperone_num"] = ( - chaperones.sort_values("chaperone_weight", ascending=False) + chaperones.sort_values("chaperone_weight", ascending=False, kind="stable") .groupby("household_id") .cumcount() + 1 ) escortees["escortee_num"] = ( - escortees.sort_values("age", ascending=True).groupby("household_id").cumcount() + escortees.sort_values("age", ascending=True, kind="stable") + .groupby("household_id") + .cumcount() + 1 ) @@ -247,7 +249,7 @@ def create_school_escorting_bundles_table(choosers, tours, stage): ) # each chauffeur option has ride share or pure escort - bundles["chauf_num"] = np.ceil(bundles["chauf_type_num"].div(2)).astype(int) + bundles["chauf_num"] = np.ceil(bundles["chauf_type_num"].div(2)).astype("int64") # getting bundle chauffeur id based on the chauffeur num bundles["chauf_id"] = -1 @@ -257,7 +259,7 @@ def create_school_escorting_bundles_table(choosers, tours, stage): choosers["chauf_id" + str(i)], bundles["chauf_id"], ) - bundles["chauf_id"] = bundles["chauf_id"].astype(int) + bundles["chauf_id"] = bundles["chauf_id"].astype("int64") assert ( bundles["chauf_id"] > 0 ).all(), "Invalid chauf_id's for school escort bundles!" @@ -586,6 +588,7 @@ def school_escorting( by=["household_id", "school_escort_direction"], ascending=[True, False], inplace=True, + kind="stable", ) school_escort_tours = school_escort_tours_trips.create_pure_school_escort_tours( diff --git a/activitysim/abm/models/util/school_escort_tours_trips.py b/activitysim/abm/models/util/school_escort_tours_trips.py index 43eed64bb..7c9e997fc 100644 --- a/activitysim/abm/models/util/school_escort_tours_trips.py +++ b/activitysim/abm/models/util/school_escort_tours_trips.py @@ -78,7 +78,7 @@ def join_attributes(df, column_names): series = ( df[col] .fillna(-1) - .astype(int) + .astype("int64") .astype(str) .replace("-1", "", regex=False) ) @@ -331,7 +331,7 @@ def create_chauf_trip_table(bundles): def create_chauf_escort_trips(bundles): chauf_trip_bundles = create_chauf_trip_table(bundles.copy()) - chauf_trip_bundles["tour_id"] = bundles["chauf_tour_id"].astype(int) + chauf_trip_bundles["tour_id"] = bundles["chauf_tour_id"].astype("int64") # departure time is the first school start in the outbound school_escort_direction and the last school end in the inbound school_escort_direction starts = ( @@ -651,7 +651,7 @@ def process_tours_after_escorting_model(state: workflow.State, escort_bundles, t num_escortees = ( escort_bundles.drop_duplicates("chauf_tour_id") .set_index("chauf_tour_id")["num_escortees"] - .astype(int) + .astype("int64") ) tours.loc[num_escortees.index, "num_escortees"] = num_escortees @@ -921,7 +921,9 @@ def create_pure_school_escort_tours(state: workflow.State, bundles): pe_tours["school_escort_direction"] == "inbound", "pure_escort", pd.NA ) - pe_tours = pe_tours.sort_values(by=["household_id", "person_id", "start"]) + pe_tours = pe_tours.sort_values( + by=["household_id", "person_id", "start"], kind="stable" + ) # finding what the next start time for that person for scheduling pe_tours["next_pure_escort_start"] = (