From 2a99bed359ee8307c301da4eb14375644bfb95b3 Mon Sep 17 00:00:00 2001 From: David Hensle Date: Mon, 5 Feb 2024 16:56:05 -0800 Subject: [PATCH] correct veh type alts for choices --- activitysim/abm/models/vehicle_type_choice.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index e6ebf5b20..95d4087aa 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -233,6 +233,7 @@ def construct_model_alternatives(model_settings, alts_cats_dict, vehicle_type_da alts_wide.set_index(["body_type", "age", "fuel_type"]).index ) ].reset_index() + alts_long.index = alts_wide.index alts_wide.drop(columns="_merge", inplace=True) # converting age to integer to allow interactions in utilities @@ -427,14 +428,12 @@ def iterate_vehicle_type_choice( choices.rename(columns={"choice": "vehicle_type"}, inplace=True) if alts_cats_dict: - alts = ( - alts_long[alts_long.columns] - .apply(lambda row: "_".join(row.values.astype(str)), axis=1) - .values - ) + alts = alts_long[alts_long.columns].apply( + lambda row: "_".join(row.values.astype(str)), axis=1 + ).to_dict() else: - alts = model_spec.columns - choices["vehicle_type"] = choices["vehicle_type"].map(dict(enumerate(alts))) + alts = enumerate(dict(model_spec.columns)) + choices["vehicle_type"] = choices["vehicle_type"].map(alts) # STEP II: append probabilistic vehicle type attributes if probs_spec_file is not None: