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

Code before:


@xp_capabilities(skip_backends=[('dask.array', "doesn't know array size")],
                 jax_jit=False)
def sigmaclip(a, low=4., high=4., *, nan_policy='propagate'):
    """Perform iterative sigma-clipping of array elements.

    Starting from the full sample, all elements outside the critical range are
    removed, i.e. all elements of the input array `c` that satisfy either of
    the following conditions::

        c < mean(c) - std(c)*low
        c > mean(c) + std(c)*high

    The iteration continues with the updated sample until no
    elements are outside the (updated) range.

    Parameters
    ----------
    a : array_like
        Data array, will be raveled if not 1-D.
    low : float, optional
        Lower bound factor of sigma clipping. Default is 4.
    high : float, optional
        Upper bound factor of sigma clipping. Default is 4.
    nan_policy : {'propagate', 'raise', 'omit'}
        Defines how to handle input NaNs.

        - ``propagate``: if a NaN is present in the input, the clipped array will be
          empty, and the upper and lower thresholds will be NaN.
        - ``omit``: NaNs will be omitted when performing the calculation.
        - ``raise``: if a NaN is present, a ``ValueError`` will be raised.

    Returns
    -------
    clipped : ndarray
        Input array with clipped elements removed.
    lower : float
        Lower threshold value use for clipping.
    upper : float
        Upper threshold value use for clipping.

    Notes
    -----
    This function iteratively *removes* observations. Once observations are
    removed, they are not re-added in subsequent iterations. Consequently,
    although it is often the case that ``clipped`` is identical to
    ``a[(a >= lower) & (a <= upper)]``, this property is not guaranteed to be
    satisfied; ``clipped`` may have fewer elements.

    Examples

Review comment (suggestion):
```suggestion
    nan_policy : {'propagate', 'omit', 'raise'}
```

Code after:


@xp_capabilities(skip_backends=[('dask.array', "doesn't know array size")],
                 jax_jit=False)
def sigmaclip(a, low=4., high=4., *, nan_policy='propagate'):
    """Perform iterative sigma-clipping of array elements.

    Starting from the full sample, all elements outside the critical range are
    removed, i.e. all elements of the input array `c` that satisfy either of
    the following conditions::

        c < mean(c) - std(c)*low
        c > mean(c) + std(c)*high

    The iteration continues with the updated sample until no
    elements are outside the (updated) range.

    Parameters
    ----------
    a : array_like
        Data array, will be raveled if not 1-D.
    low : float, optional
        Lower bound factor of sigma clipping. Default is 4.
    high : float, optional
        Upper bound factor of sigma clipping. Default is 4.
    nan_policy : {'propagate', 'omit', 'raise'}
        Defines how to handle input NaNs.

        - ``propagate``: if a NaN is present in the input, the clipped array will be
          empty, and the upper and lower thresholds will be NaN.
        - ``omit``: NaNs will be omitted when performing the calculation.
        - ``raise``: if a NaN is present, a ``ValueError`` will be raised.

    Returns
    -------
    clipped : ndarray
        Input array with clipped elements removed.
    lower : float
        Lower threshold value use for clipping.
    upper : float
        Upper threshold value use for clipping.

    Notes
    -----
    This function iteratively *removes* observations. Once observations are
    removed, they are not re-added in subsequent iterations. Consequently,
    although it is often the case that ``clipped`` is identical to
    ``a[(a >= lower) & (a <= upper)]``, this property is not guaranteed to be
    satisfied; ``clipped`` may have fewer elements.

    Examples