Write categories of a categorical/nominal attribute

def _write_attribute_categorical(series, fp):
    """Write categories of a categorical/nominal attribute"""
    if is_categorical_dtype(series.dtype):
        categories = series.cat.categories
        string_values = _check_str_array(categories)
    else:
        categories = series.dropna().unique()
        string_values = sorted(_check_str_array(categories), key=lambda x: x.strip('"'))

    values = ",".join(string_values)
    fp.write("{")
    fp.write(values)
    fp.write("}")