def _prepare_categoricals(self, data):
is_cat = [is_categorical_dtype(data[col]) for col in data]<EOL>self._is_col_cat = is_cat<EOL>self._value_labels = []<EOL>if not any(is_cat):<EOL><INDENT>return data<EOL><DEDENT>get_base_missing_value = StataMissingValue.get_base_missing_value<EOL>data_formatted = []<EOL>for col, col_is_cat in zip(data, is_cat):<EOL><INDENT>if col_is_cat:<EOL><INDENT>self._value_labels.append(StataValueLabel(data[col]))<EOL>dtype = data[col].cat.codes.dtype<EOL>if dtype == np.int64:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>values = data[col].cat.codes.values.copy()<EOL>if values.max() >= get_base_missing_value(dtype):<EOL><INDENT>if dtype == np.int8:<EOL><INDENT>dtype = np.int16<EOL><DEDENT>elif dtype == np.int16:<EOL><INDENT>dtype = np.int32<EOL><DEDENT>else:<EOL><INDENT>dtype = np.float64<EOL><DEDENT>values = np.array(values, dtype=dtype)<EOL><DEDENT>values[values == -<NUM_LIT:1>] = get_base_missing_value(dtype)<EOL>data_formatted.append((col, values))<EOL><DEDENT>else:<EOL><INDENT>data_formatted.append((col, data[col]))<EOL><DEDENT><DEDENT>return DataFrame.from_dict(OrderedDict(data_formatted))<EOL>
Check for categorical columns, retain categorical information for
        Stata file and convert categorical data to int