24
24
25
25
def add_null_results (state , trace_label , tours ):
26
26
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
+ )
28
36
state .add_table ("tours" , tours )
29
37
30
38
@@ -117,6 +125,11 @@ def atwork_subtour_frequency(
117
125
118
126
# convert indexes to alternative names
119
127
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 )
120
133
121
134
if estimator :
122
135
estimator .write_choices (choices )
@@ -137,6 +150,12 @@ def atwork_subtour_frequency(
137
150
138
151
subtours = process_atwork_subtours (state , work_tours , alternatives )
139
152
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
+
140
159
tours = state .extend_table ("tours" , subtours )
141
160
142
161
state .tracing .register_traceable_table ("tours" , subtours )
0 commit comments