def _interval_index()

in src/smclarify/bias/report.py [0:0]


def _interval_index(data: pd.Series, thresholds: Optional[List[Any]]) -> pd.IntervalIndex:
    """
    Creates a Interval Index from list of threshold values. See pd.IntervalIndex.from_breaks
    Ex. [0,1,2] -> [(0, 1], (1,2]]
    :param data: input data series
    :param thresholds: list of int or float values defining the threshold splits
    :return: pd.IntervalIndex
    """
    if not thresholds:
        raise ValueError("Threshold values must be provided for continuous features")
    max_value, min_value = data.max(), data.min()
    threshold_intervals = thresholds.copy()
    # add  max value if not exists in threshold limits
    if abs(max_value) not in thresholds:
        threshold_intervals.append(max_value)
    sorted_threshold_intervals = sorted(threshold_intervals)
    return pd.IntervalIndex.from_breaks(sorted_threshold_intervals)