Repository: scipy/scipy
File: scipy/signal/_spectral_py.py (Python)

Code before:
        raise ValueError("Parameters x, y, weights must be 1-D arrays of "
                         "equal non-zero length!")
    if not (freqs.ndim == 1 and freqs.size > 0):
        raise ValueError("Parameter freqs must be a 1-D array of non-zero length!")

    # validate weights
    if not (np.all(weights >= 0) and np.sum(weights) > 0):
        raise ValueError("Parameter weights must have only non-negative entries "
                         "which sum to a positive value!")

    # validate normalize parameter
    if isinstance(normalize, bool):
        # if bool, convert to str literal
        normalize = "normalize" if normalize else "power"

    if normalize not in ["power", "normalize", "amplitude"]:
        raise ValueError(
            "Normalize must be: False (or 'power'), True (or 'normalize'), "
            "or 'amplitude'."
        )

    # weight vector must sum to 1
    weights = weights * (1.0 / weights.sum())

    # if requested, perform precenter
    if precenter is not None:
        msg = ("Use of parameter 'precenter' is deprecated as of SciPy 1.17.0 and "
               "will be removed in 1.19.0. Please leave 'precenter' unspecified. "
               "Passing True to 'precenter' "
               "can be exactly substituted by passing 'y = (y - y.mean())' into "
               "the input. Consider setting `floating_mean` to True instead.")
        warnings.warn(msg, DeprecationWarning, stacklevel=2)
        if precenter:
            y = y - y.mean()

    # transform arrays
    # row vector
    freqs = freqs.reshape(1, -1)
    # column vectors
    x = x.reshape(-1, 1)
    y = y.reshape(-1, 1)
    weights = weights.reshape(-1, 1)

    # store frequent intermediates
    weights_y = weights * y
    freqst = freqs * x
    coswt = np.cos(freqst)
    sinwt = np.sin(freqst)

    Y = np.dot(weights.T, y)  # Eq. 7
    CC = np.dot(weights.T, coswt * coswt)  # Eq. 13

Review comment (suggestion):
```suggestion
    if precenter is not _NoValue:
```

Code after:
        raise ValueError("Parameters x, y, weights must be 1-D arrays of "
                         "equal non-zero length!")
    if not (freqs.ndim == 1 and freqs.size > 0):
        raise ValueError("Parameter freqs must be a 1-D array of non-zero length!")

    # validate weights
    if not (np.all(weights >= 0) and np.sum(weights) > 0):
        raise ValueError("Parameter weights must have only non-negative entries "
                         "which sum to a positive value!")

    # validate normalize parameter
    if isinstance(normalize, bool):
        # if bool, convert to str literal
        normalize = "normalize" if normalize else "power"

    if normalize not in ["power", "normalize", "amplitude"]:
        raise ValueError(
            "Normalize must be: False (or 'power'), True (or 'normalize'), "
            "or 'amplitude'."
        )

    # weight vector must sum to 1
    weights = weights * (1.0 / weights.sum())

    # if requested, perform precenter
    if precenter is not _NoValue:
        msg = ("Use of parameter 'precenter' is deprecated as of SciPy 1.17.0 and "
               "will be removed in 1.19.0. Please leave 'precenter' unspecified. "
               "Passing True to 'precenter' "
               "can be exactly substituted by passing 'y = (y - y.mean())' into "
               "the input. Consider setting `floating_mean` to True instead.")
        warnings.warn(msg, DeprecationWarning, stacklevel=2)
        if precenter:
            y = y - y.mean()

    # transform arrays
    # row vector
    freqs = freqs.reshape(1, -1)
    # column vectors
    x = x.reshape(-1, 1)
    y = y.reshape(-1, 1)
    weights = weights.reshape(-1, 1)

    # store frequent intermediates
    weights_y = weights * y
    freqst = freqs * x
    coswt = np.cos(freqst)
    sinwt = np.sin(freqst)

    Y = np.dot(weights.T, y)  # Eq. 7
    CC = np.dot(weights.T, coswt * coswt)  # Eq. 13