Repository: scipy/scipy
File: scipy/stats/_morestats.py (Python)

Code before:
            raise ValueError(message)

    except (FloatingPointError, ValueError) as e:
        message = ("An error occurred while fitting the Weibull distribution "
                   "to the data, so `anderson` cannot continue. " + suggestion)
        raise ValueError(message) from e

    m, u = res.x
    s = get_scale(m, u)
    return m, u, s


AndersonResult = _make_tuple_bunch('AndersonResult',
                                   ['statistic', 'critical_values',
                                    'significance_level'], ['fit_result'])


_anderson_warning_message = (
"""As of SciPy 1.17, users must choose a p-value calculation method by providing the
`method` parameter. `method='interpolate'` interpolates the p-value from pre-calculated
tables; `method` may also be an instance of `MonteCarloMethod` to approximate the
p-value via Monte Carlo simulation. When `method` is specified, the result object will
include a `pvalue` attribute and not attributes `critical_value`, `significance_level`,
or `fit_result`. Beginning in 1.19.0, these other attributes will no longer be
available, and a p-value will always be computed according to one of the available
`method` options.""".replace('\n', ''))


@xp_capabilities(np_only=True)
def anderson(x, dist='norm', *, method=None):
    """Anderson-Darling test for data coming from a particular distribution.

    The Anderson-Darling test tests the null hypothesis that a sample is
    drawn from a population that follows a particular distribution.
    For the Anderson-Darling test, the critical values depend on
    which distribution is being tested against.  This function works
    for normal, exponential, logistic, weibull_min, or Gumbel (Extreme Value
    Type I) distributions.

    Parameters
    ----------
    x : array_like
        Array of sample data.
    dist : {'norm', 'expon', 'logistic', 'gumbel', 'gumbel_l', 'gumbel_r', 'extreme1', 'weibull_min'}, optional
        The type of distribution to test against.  The default is 'norm'.
        The names 'extreme1', 'gumbel_l' and 'gumbel' are synonyms for the
        same distribution.
    method : str or instance of `MonteCarloMethod`
        Defines the method used to compute the p-value.
        If `method` is ``"interpolated"``, the p-value is interpolated from
        pre-calculated tables.

Review comment (suggestion):
```suggestion
`method` options.""".replace('\n', ' '))
```

Code after:
            raise ValueError(message)

    except (FloatingPointError, ValueError) as e:
        message = ("An error occurred while fitting the Weibull distribution "
                   "to the data, so `anderson` cannot continue. " + suggestion)
        raise ValueError(message) from e

    m, u = res.x
    s = get_scale(m, u)
    return m, u, s


AndersonResult = _make_tuple_bunch('AndersonResult',
                                   ['statistic', 'critical_values',
                                    'significance_level'], ['fit_result'])


_anderson_warning_message = (
"""As of SciPy 1.17, users must choose a p-value calculation method by providing the
`method` parameter. `method='interpolate'` interpolates the p-value from pre-calculated
tables; `method` may also be an instance of `MonteCarloMethod` to approximate the
p-value via Monte Carlo simulation. When `method` is specified, the result object will
include a `pvalue` attribute and not attributes `critical_value`, `significance_level`,
or `fit_result`. Beginning in 1.19.0, these other attributes will no longer be
available, and a p-value will always be computed according to one of the available
`method` options.""".replace('\n', ' '))


@xp_capabilities(np_only=True)
def anderson(x, dist='norm', *, method=None):
    """Anderson-Darling test for data coming from a particular distribution.

    The Anderson-Darling test tests the null hypothesis that a sample is
    drawn from a population that follows a particular distribution.
    For the Anderson-Darling test, the critical values depend on
    which distribution is being tested against.  This function works
    for normal, exponential, logistic, weibull_min, or Gumbel (Extreme Value
    Type I) distributions.

    Parameters
    ----------
    x : array_like
        Array of sample data.
    dist : {'norm', 'expon', 'logistic', 'gumbel', 'gumbel_l', 'gumbel_r', 'extreme1', 'weibull_min'}, optional
        The type of distribution to test against.  The default is 'norm'.
        The names 'extreme1', 'gumbel_l' and 'gumbel' are synonyms for the
        same distribution.
    method : str or instance of `MonteCarloMethod`
        Defines the method used to compute the p-value.
        If `method` is ``"interpolated"``, the p-value is interpolated from
        pre-calculated tables.