Skip to content

Commit 6266ce4

Browse files
dhenslejuangacostajpn--
authored
Index names consistently set to "alt" for alternatives files (#1018)
* "alt" now used as index in all alternatives modules * formatting * minor commenting * using stable sorting for unit test * adding to change log * updating school escort bundle Alt to alt * typo * Revert "updating school escort bundle Alt to alt" This reverts commit 625f685. * regenerate pipeline --------- Co-authored-by: juangacosta <juan.acosta@rsginc.com> Co-authored-by: Jeffrey Newman <jeff@driftless.xyz>
1 parent 0811191 commit 6266ce4

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

activitysim/abm/models/joint_tour_frequency_composition.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def joint_tour_frequency_composition(
4444
model_settings_file_name,
4545
)
4646

47-
# FIXME setting index as "alt" causes crash in estimation mode...
4847
alts = simulate.read_model_alts(
49-
state, "joint_tour_frequency_composition_alternatives.csv", set_index=None
48+
state, "joint_tour_frequency_composition_alternatives.csv", set_index="alt"
5049
)
51-
alts.index = alts["alt"].values
5250

5351
# - only interested in households with more than one cdap travel_active person and
5452
# - at least one non-preschooler

activitysim/abm/models/school_escorting.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def create_school_escorting_bundles_table(choosers, tours, stage):
308308
bundles["chauf_id"],
309309
)
310310

311-
bundles["Alt"] = choosers["Alt"]
311+
bundles["alt"] = choosers["alt"]
312312
bundles["Description"] = choosers["Description"]
313313

314314
return bundles
@@ -412,11 +412,7 @@ def school_escorting(
412412

413413
trace_hh_id = state.settings.trace_hh_id
414414

415-
# FIXME setting index as "Alt" causes crash in estimation mode...
416-
# happens in joint_tour_frequency_composition too!
417-
# alts = simulate.read_model_alts(state, model_settings.ALTS, set_index="Alt")
418-
alts = simulate.read_model_alts(state, model_settings.ALTS, set_index=None)
419-
alts.index = alts["Alt"].values
415+
alts = simulate.read_model_alts(state, model_settings.ALTS, set_index="alt")
420416

421417
choosers, participant_columns = determine_escorting_participants(
422418
households_merged, persons, model_settings
@@ -565,10 +561,10 @@ def school_escorting(
565561
)
566562

567563
if stage_num >= 1:
568-
choosers["Alt"] = choices
569-
choosers = choosers.join(alts.set_index("Alt"), how="left", on="Alt")
564+
choosers["alt"] = choices
565+
choosers = choosers.join(alts, how="left", on="alt")
570566
bundles = create_school_escorting_bundles_table(
571-
choosers[choosers["Alt"] > 1], tours, stage
567+
choosers[choosers["alt"] > 1], tours, stage
572568
)
573569
escort_bundles.append(bundles)
574570

activitysim/core/simulate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,22 @@ def read_model_alts(state: workflow.State, file_name, set_index=None):
7979
file_path = state.filesystem.get_config_file_path(file_name)
8080
df = pd.read_csv(file_path, comment="#")
8181
if set_index:
82+
if "Alt" in df.columns:
83+
# Handle deprecated ALTS index
84+
warnings.warn(
85+
"Support for 'Alt' column name in alternatives files will be removed."
86+
" Use 'alt' (lowercase) instead.",
87+
DeprecationWarning,
88+
)
89+
# warning above does not actually output to logger, so also log it
90+
logger.warning(
91+
"Support for 'Alt' column name in alternatives files will be removed."
92+
" Use 'alt' (lowercase) instead."
93+
)
94+
df.rename(columns={"Alt": "alt"}, inplace=True)
95+
8296
df.set_index(set_index, inplace=True)
97+
8398
return df
8499

85100

Binary file not shown.

docs/dev-guide/changes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ branch (i.e., the main branch on GitHub), but not yet released in a stable versi
1313
of ActivitySim. See below under the various version headings for changes in
1414
released versions.
1515

16+
### Alternative file naming consistency
17+
18+
We have enforced a naming scheme for alternative config files to have the index name
19+
be 'alt' instead of 'Alt'. This is to maintain consistency across all config files.
20+
The code will handle this for you, but you will get a deprecation warning if you
21+
are using 'Alt' in your config files. Please update your config files to use 'alt'.
22+
See ActivitySim issue [#846](https://github.com/ActivitySim/activitysim/issues/846)
23+
1624
### CDAP Estimation Mode
1725

1826
A bug has been fixed in the Larch portion of code for the re-estimation of CDAP

0 commit comments

Comments
 (0)