def acovf(x, unbiased=False, demean=True, fft=False, missing='none'):
    "\n    Autocovariance for 1D\n\n    Parameters\n    ----------\n    x : array\n        Time series data. Must be 1d.\n    unbiased : bool\n        If True, then denominators is n-k, otherwise n\n    demean : bool\n        If True, then subtract the mean x from each element of x\n    fft : bool\n        If True, use FFT convolution.  This method should be preferred\n        for long time series.\n    missing : str\n        A string in ['none', 'raise', 'conservative', 'drop'] specifying how the NaNs\n        are to be treated.\n\n    Returns\n    -------\n    acovf : array\n        autocovariance function\n\n    References\n    -----------\n    .. [*] Parzen, E., 1963. On spectral analysis with missing observations\n           and amplitude modulation. Sankhya: The Indian Journal of\n           Statistics, Series A, pp.383-392.\n    "
    x = np.squeeze(np.asarray(x))
    if (x.ndim > 1):
        raise ValueError(('x must be 1d. Got %d dims.' % x.ndim))
    missing = missing.lower()
    if (missing not in ['none', 'raise', 'conservative', 'drop']):
        raise ValueError(('missing option %s not understood' % missing))
    if (missing == 'none'):
        deal_with_masked = False
    else:
        deal_with_masked = has_missing(x)
    if deal_with_masked:
        if (missing == 'raise'):
            raise MissingDataError('NaNs were encountered in the data')
        notmask_bool = (~ np.isnan(x))
        if (missing == 'conservative'):
            x[(~ notmask_bool)] = 0
        else:
            x = x[notmask_bool]
        notmask_int = notmask_bool.astype(int)
    if (demean and deal_with_masked):
        xo = (x - (x.sum() / notmask_int.sum()))
        if (missing == 'conservative'):
            xo[(~ notmask_bool)] = 0
    elif demean:
        xo = (x - x.mean())
    else:
        xo = x
    n = len(x)
    if (unbiased and deal_with_masked and (missing == 'conservative')):
        d = np.correlate(notmask_int, notmask_int, 'full')
    elif unbiased:
        xi = np.arange(1, (n + 1))
        d = np.hstack((xi, xi[:(- 1)][::(- 1)]))
    elif deal_with_masked:
        d = (notmask_int.sum() * np.ones(((2 * n) - 1)))
    else:
        d = (n * np.ones(((2 * n) - 1)))
    if fft:
        nobs = len(xo)
        n = _next_regular(((2 * nobs) + 1))
        Frf = np.fft.fft(xo, n=n)
        acov = (np.fft.ifft((Frf * np.conjugate(Frf)))[:nobs] / d[(nobs - 1):])
        acov = acov.real
    else:
        acov = (np.correlate(xo, xo, 'full') / d)[(n - 1):]
    if (deal_with_masked and (missing == 'conservative')):
        x[(~ notmask_bool)] = np.nan
    return acov
Autocovariance for 1D

Parameters
----------
x : array
    Time series data. Must be 1d.
unbiased : bool
    If True, then denominators is n-k, otherwise n
demean : bool
    If True, then subtract the mean x from each element of x
fft : bool
    If True, use FFT convolution.  This method should be preferred
    for long time series.
missing : str
    A string in ['none', 'raise', 'conservative', 'drop'] specifying how the NaNs
    are to be treated.

Returns
-------
acovf : array
    autocovariance function

References
-----------
.. [*] Parzen, E., 1963. On spectral analysis with missing observations
       and amplitude modulation. Sankhya: The Indian Journal of
       Statistics, Series A, pp.383-392.
def acovf(x, unbiased=False, demean=True, fft=False, missing='none'):
    "\n    Autocovariance for 1D\n\n    Parameters\n    ----------\n    x : array\n        Time series data. Must be 1d.\n    unbiased : bool\n        If True, then denominators is n-k, otherwise n\n    demean : bool\n        If True, then subtract the mean x from each element of x\n    fft : bool\n        If True, use FFT convolution.  This method should be preferred\n        for long time series.\n    missing : str\n        A string in ['none', 'raise', 'conservative', 'drop'] specifying how the NaNs\n        are to be treated.\n\n    Returns\n    -------\n    acovf : array\n        autocovariance function\n\n    References\n    -----------\n    .. [*] Parzen, E., 1963. On spectral analysis with missing observations\n           and amplitude modulation. Sankhya: The Indian Journal of\n           Statistics, Series A, pp.383-392.\n    "
    x = np.squeeze(np.asarray(x))
    if (x.ndim > 1):
        raise ValueError(('x must be 1d. Got %d dims.' % x.ndim))
    missing = missing.lower()
    if (missing not in ['none', 'raise', 'conservative', 'drop']):
        raise ValueError(('missing option %s not understood' % missing))
    if (missing == 'none'):
        deal_with_masked = False
    else:
        deal_with_masked = has_missing(x)
    if deal_with_masked:
        if (missing == 'raise'):
            raise MissingDataError('NaNs were encountered in the data')
        notmask_bool = (~ np.isnan(x))
        if (missing == 'conservative'):
            x[(~ notmask_bool)] = 0
        else:
            x = x[notmask_bool]
        notmask_int = notmask_bool.astype(int)
    if (demean and deal_with_masked):
        xo = (x - (x.sum() / notmask_int.sum()))
        if (missing == 'conservative'):
            xo[(~ notmask_bool)] = 0
    elif demean:
        xo = (x - x.mean())
    else:
        xo = x
    n = len(x)
    if (unbiased and deal_with_masked and (missing == 'conservative')):
        d = np.correlate(notmask_int, notmask_int, 'full')
    elif unbiased:
        xi = np.arange(1, (n + 1))
        d = np.hstack((xi, xi[:(- 1)][::(- 1)]))
    elif deal_with_masked:
        d = (notmask_int.sum() * np.ones(((2 * n) - 1)))
    else:
        d = (n * np.ones(((2 * n) - 1)))
    if fft:
        nobs = len(xo)
        n = _next_regular(((2 * nobs) + 1))
        Frf = np.fft.fft(xo, n=n)
        acov = (np.fft.ifft((Frf * np.conjugate(Frf)))[:nobs] / d[(nobs - 1):])
        acov = acov.real
    else:
        acov = (np.correlate(xo, xo, 'full') / d)[(n - 1):]
    if (deal_with_masked and (missing == 'conservative')):
        x[(~ notmask_bool)] = np.nan
    return acov