2424
2525def add_null_results (state , trace_label , tours ):
2626 logger .info ("Skipping %s: add_null_results" , trace_label )
27- tours ["atwork_subtour_frequency" ] = np .nan
27+ cat_type = pd .api .types .CategoricalDtype (
28+ ["" ],
29+ ordered = False ,
30+ )
31+ choices = choices .astype (cat_type )
32+ tours ["atwork_subtour_frequency" ] = ""
33+ tours ["atwork_subtour_frequency" ] = tours ["atwork_subtour_frequency" ].astype (
34+ cat_type
35+ )
2836 state .add_table ("tours" , tours )
2937
3038
@@ -117,6 +125,11 @@ def atwork_subtour_frequency(
117125
118126 # convert indexes to alternative names
119127 choices = pd .Series (model_spec .columns [choices .values ], index = choices .index )
128+ cat_type = pd .api .types .CategoricalDtype (
129+ alternatives .index .tolist () + ["" ],
130+ ordered = False ,
131+ )
132+ choices = choices .astype (cat_type )
120133
121134 if estimator :
122135 estimator .write_choices (choices )
@@ -137,6 +150,12 @@ def atwork_subtour_frequency(
137150
138151 subtours = process_atwork_subtours (state , work_tours , alternatives )
139152
153+ # convert purpose to pandas categoricals
154+ purpose_type = pd .api .types .CategoricalDtype (
155+ alternatives .columns .tolist () + ["atwork" ], ordered = False
156+ )
157+ subtours ["tour_type" ] = subtours ["tour_type" ].astype (purpose_type )
158+
140159 tours = state .extend_table ("tours" , subtours )
141160
142161 state .tracing .register_traceable_table ("tours" , subtours )
0 commit comments