-
Notifications
You must be signed in to change notification settings - Fork 133
Stable sort for school escorting #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
americalexander
wants to merge
4
commits into
ActivitySim:main
Choose a base branch
from
RSGInc:stable_sort
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as chaperones just above. |
||||||
| .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"] = ((bundles["chauf_type_num"] + 1) // 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( | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I suggest we use bundle_id to make this independent of row order in pe_tours. |
||||||
| ) | ||||||
|
|
||||||
| # finding what the next start time for that person for scheduling | ||||||
| pe_tours["next_pure_escort_start"] = ( | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in ActivitySim/meeting-notes#114, using person_id as explicit sort key makes this independent of the row order of chaperones.