def describe_categorical_1d(data):
    names = ['count', 'unique']
    objcounts = data.value_counts()
    count_unique = len(objcounts[(objcounts != 0)])
    result = [data.count(), count_unique]
    if (result[1] > 0):
        (top, freq) = (objcounts.index[0], objcounts.iloc[0])
        if is_datetime64_any_dtype(data):
            tz = data.dt.tz
            asint = data.dropna().values.view('i8')
            top = Timestamp(top)
            if ((top.tzinfo is not None) and (tz is not None)):
                top = top.tz_convert(tz)
            else:
                top = top.tz_localize(tz)
            names += ['top', 'freq', 'first', 'last']
            result += [top, freq, Timestamp(asint.min(), tz=tz), Timestamp(asint.max(), tz=tz)]
        else:
            names += ['top', 'freq']
            result += [top, freq]
    return pd.Series(result, index=names, name=data.name)
def describe_categorical_1d(data):
    names = ['count', 'unique']
    objcounts = data.value_counts()
    count_unique = len(objcounts[(objcounts != 0)])
    result = [data.count(), count_unique]
    if (result[1] > 0):
        (top, freq) = (objcounts.index[0], objcounts.iloc[0])
        if is_datetime64_any_dtype(data):
            tz = data.dt.tz
            asint = data.dropna().values.view('i8')
            top = Timestamp(top)
            if ((top.tzinfo is not None) and (tz is not None)):
                top = top.tz_convert(tz)
            else:
                top = top.tz_localize(tz)
            names += ['top', 'freq', 'first', 'last']
            result += [top, freq, Timestamp(asint.min(), tz=tz), Timestamp(asint.max(), tz=tz)]
        else:
            names += ['top', 'freq']
            result += [top, freq]
    return pd.Series(result, index=names, name=data.name)