def filter_outliers()

in src/mozanalysis/utils.py [0:0]


def filter_outliers(branch_data, threshold_quantile):
    """Return branch_data with outliers capped.

    N.B. `branch_data` is for an individual branch: if you do it for
    the entire experiment population in whole, then you may bias the
    results.

    Args:
        branch_data: Data for one branch as a 1D ndarray or similar.
        threshold_quantile (float): Sets outliers above this
            quantile equal to the value of this quantile.

    Returns:
        branch_data with values capped at or below the threshold
        quantile.
    """
    if threshold_quantile > 1 or threshold_quantile < 0.5:
        raise ValueError("'threshold_quantile' should be close to, and <= 1")

    min_threshold = np.min(branch_data, axis=0)
    max_threshold = np.quantile(branch_data, threshold_quantile, axis=0)

    return np.clip(branch_data, min_threshold, max_threshold)