Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 135
Patch sharrow sandag#1009
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
Uh oh!
There was an error while loading. Please reload this page.
Patch sharrow sandag #1009
Changes from all commits
7fd19f2591fe1ef6ec70e5002215eb0bd609185b225873be7a84f7710a1b99aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1496,23 +1496,42 @@ def run_trip_destination( | ||
| for primary_purpose, trips_segment in nth_trips.groupby( | ||
| "primary_purpose", observed=True | ||
| ): | ||
| choices, destination_sample = choose_trip_destination( | ||
| state, | ||
| primary_purpose, | ||
| trips_segment, | ||
| alternatives, | ||
| tours_merged, | ||
| model_settings, | ||
| want_logsums, | ||
| want_sample_table, | ||
| size_term_matrix, | ||
| skim_hotel, | ||
| estimator, | ||
| chunk_size, | ||
| trace_label=tracing.extend_trace_label( | ||
| nth_trace_label, primary_purpose | ||
| ), | ||
| ) | ||
| try: | ||
| choices, destination_sample = choose_trip_destination( | ||
| state, | ||
| primary_purpose, | ||
| trips_segment, | ||
| alternatives, | ||
| tours_merged, | ||
| model_settings, | ||
| want_logsums, | ||
| want_sample_table, | ||
| size_term_matrix, | ||
| skim_hotel, | ||
| estimator, | ||
| chunk_size, | ||
| trace_label=tracing.extend_trace_label( | ||
| nth_trace_label, primary_purpose | ||
| ), | ||
| ) | ||
| except KeyError as err: | ||
| if err.args[0] == "purpose_index_num": | ||
| logger.error( | ||
| """ | ||
| When using the trip destination model with sharrow, it is necessary | ||
| to set a value for `purpose_index_num` in the trip destination | ||
| annotate trips preprocessor. This allows for an optimized compiled | ||
| lookup of the size term from the array of size terms. The value of | ||
| `purpose_index_num` should be the integer column position in the size | ||
| matrix, with usual zero-based numpy indexing semantics (i.e. the first | ||
| column is zero). The preprocessor expression most likely needs to be | ||
| "size_terms.get_cols(df.purpose)" unless some unusual transform of | ||
| size terms has been employed. | ||
| """ | ||
jpn-- marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| raise | ||
| choices_list.append(choices) | ||
| if want_sample_table: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -989,7 +989,7 @@ def to_array(x): | ||
| # return utilities | ||
| def set_skim_wrapper_targets(df, skims): | ||
| def set_skim_wrapper_targets(df, skims, allow_partial_success: bool = True): | ||
jpn-- marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| Add the dataframe to the SkimWrapper object so that it can be dereferenced | ||
| using the parameters of the skims object. | ||
| @@ -1007,6 +1007,11 @@ def set_skim_wrapper_targets(df, skims): | ||
| dataframe that comes back from interacting choosers with | ||
| alternatives. See the skims module for more documentation on how | ||
| the skims object is intended to be used. | ||
| allow_partial_success : bool, optional | ||
| If True (default), failures to set skim targets for some skim objects | ||
| (for example due to missing required columns in `df`) will be collected | ||
| and logged as warnings but will not raise an exception. If False, any | ||
| such failure will be raised immediately, preventing partial success. | ||
| """ | ||
| skims = ( | ||
| @@ -1016,13 +1021,31 @@ def set_skim_wrapper_targets(df, skims): | ||
| if isinstance(skims, dict) | ||
| else [skims] | ||
| ) | ||
| problems = [] | ||
| # assume any object in skims can be treated as a skim | ||
| for skim in skims: | ||
| try: | ||
| skim.set_df(df) | ||
| except AttributeError: | ||
| # sometimes when passed as a dict, the skims have a few keys given as | ||
| # settings or constants, which are not actually "skim" objects and have | ||
| # no `set_df` attribute. This is fine and we just let them pass. | ||
| pass | ||
| except AssertionError as e: | ||
| # An assertion error will get triggered if the columns of `df` are | ||
| # missing one of the required keys needed to look up values in the | ||
| # skims. This may not be a problem, if this particular set of skims | ||
| # is not actually used in this model component. So we'll warn about | ||
| # it but usually not raise a showstopping error. | ||
| problems.append(e) | ||
| if not allow_partial_success: | ||
| raise | ||
| if problems: | ||
| # if problems were discovered, log them as warnings | ||
| for problem in problems: | ||
| logger.warning(str(problem)) | ||
| # | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.