@@ -219,7 +219,7 @@ def allocated_vehicle_body(rd: RunData, config: Config) -> pl.DataFrame:
219219 "tour_count_auto_sufficient" : pl .Float64 ,
220220 "tour_count_all_households" : pl .Float64 ,
221221 },
222- required_columns = {"tours" : ("tour_mode" , "tour_purpose" , "finalweight" )},
222+ required_columns = {"tours" : ("tour_mode" , "tour_purpose" , "finalweight" , "AUTOSUFF" )},
223223)
224224def tour_mode (rd : RunData , config : Config ) -> pl .DataFrame :
225225 """Tour mode by auto sufficiency level and total, by tour purpose/category.
@@ -229,7 +229,8 @@ def tour_mode(rd: RunData, config: Config) -> pl.DataFrame:
229229 tour_count_zero_auto, tour_count_auto_deficient,
230230 tour_count_auto_sufficient, tour_count_all_households.
231231 """
232- if "tour_mode" not in rd .tours .columns :
232+ required = {"tour_mode" , "tour_purpose" , "finalweight" , "AUTOSUFF" }
233+ if not required .issubset (set (rd .tours .columns )):
233234 return empty_summary_frame (tour_mode )
234235
235236 indiv = (
@@ -280,11 +281,7 @@ def tour_mode(rd: RunData, config: Config) -> pl.DataFrame:
280281 wgt_col = "wgt" if "wgt" in df .columns else "finalweight"
281282
282283 for as_val in range (3 ):
283- as_filter = (
284- (pl .col ("AUTOSUFF" ) == as_val )
285- if "AUTOSUFF" in df .columns
286- else pl .lit (True )
287- )
284+ as_filter = pl .col ("AUTOSUFF" ) == as_val
288285
289286 sub = df .filter (purpose_filter & as_filter )
290287 counts = sub .group_by ("tour_mode" ).agg (pl .col (wgt_col ).sum ().alias ("n" ))
0 commit comments