def curvature(x):
    """Curvature of a timeseries

    This test is commonly known as gradient for historical reasons, but that
    is a bad name choice since it is not the actual gradient, like:
    d/dx + d/dy + d/dz,
    but as defined by GTSPP, EuroGOOS and others, which is actually the
    curvature of the timeseries..

    Note
    ----
    - Pandas.Series operates with indexes, so it should be done different. In
      that case, call for _curvature_pandas.
    """
    if isinstance(x, ma.MaskedArray):
        x[x.mask] = np.nan
        x = x.data

    if PANDAS_AVAILABLE and isinstance(x, pd.Series):
        return _curvature_pandas(x)

    x = np.atleast_1d(x)
    y = np.nan * x
    y[1:-1] = x[1:-1] - (x[:-2] + x[2:]) / 2.0
    return y