human
Complete this python program:
def add_trend(x, trend='c', prepend=False, has_constant='skip'):
assistant
#Here is the Python program you requested.

    """Adds a trend and/or constant to an array.
    Parameters
    X : array-like
    Original array of data.
    trend : str {"c","t","ct","ctt"}
    "c" add constant only
    "t" add trend only
    "ct" add constant and linear trend
    "ctt" add constant and linear and quadratic trend.
    prepend : bool
    If True, prepends the new data to the columns of X.
    has_constant : str {\raise\, \add\, \skip\}
    Controls what happens when trend is \c\ and a constant already
    exists in X. \raise\ will raise an error. \add\ will duplicate a
    constant. \skip\ will return the data without change. \skip\ is the
    default.
    Returns
    y : array, recarray or DataFrame
    The original data with the additional trend columns.  If x is a
    recarray or pandas Series or DataFrame, then the trend column names
    are \const\, \trend\ and \trend_squared\.
    Notes
    Returns columns as ["ctt","ct","c"] whenever applicable. There is currently
    no checking for an existing trend.
    See also
    statsmodels.tools.tools.add_constant
    """
    trend = trend.lower()
    columns = ['const', 'trend', 'trend_squared']
    if (trend == 'c'):
        columns = columns[:1]
        trendorder = 0
    elif ((trend == 'ct') or (trend == 't')):
        columns = columns[:2]
        if (trend == 't'):
            columns = columns[1:2]
        trendorder = 1
    elif (trend == 'ctt'):
        trendorder = 2
    else:
        raise ValueError(('trend    %s    not    understood' % trend))
    is_recarray = _is_recarray(x)
    is_pandas = (_is_using_pandas(x, None) or is_recarray)
    if (is_pandas or is_recarray):
        if is_recarray:
            descr = x.dtype.descr
            x = pd.DataFrame.from_records(x)
        elif isinstance(x, pd.Series):
            x = pd.DataFrame(x)
        else:
            x = x.copy()
    else:
        x = np.asanyarray(x)
    nobs = len(x)
    trendarr = np.vander(np.arange(1, (nobs + 1), dtype=np.float64), (trendorder + 1))
    trendarr = np.fliplr(trendarr)
    if (trend == 't'):
        trendarr = trendarr[:, 1]
    if ('c' in trend):
        if (is_pandas or is_recarray):
            def safe_is_const(s):
                try:
                    return ((np.ptp(s) == 0.0) and np.any((s != 0.0)))
                except:
                    return False
            col_const = x.apply(safe_is_const, 0)
        else:
            col_const = np.logical_and(np.any((np.ptp(np.asanyarray(x), axis=0) == 0), axis=0), np.all((x != 0.0), axis=0))
        if np.any(col_const):
            if (has_constant == 'raise'):
                raise ValueError('x    already    contains    a    constant')
            elif (has_constant == 'skip'):
                columns = columns[1:]
                trendarr = trendarr[:, 1:]
    order = (1 if prepend else (-1))
    if (is_recarray or is_pandas):
        trendarr = pd.DataFrame(trendarr, index=x.index, columns=columns)
        x = [trendarr, x]
        x = pd.concat(x[::order], 1)
    else:
        x = [trendarr, x]
        x = np.column_stack(x[::order])
    if is_recarray:
        x =...