def _categorical_data_idx()

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


def _categorical_data_idx(col: pd.Series, positive_values: List[Any]) -> pd.Series:
    """
    Converts `col` series to True / False based on the `positive_values`.

    If no True values found, it tries converting elements of the `positive_value`
    to the data type of the series' elements.

    :param col: input data series
    :param positive_values: list of category values to generate boolean index
    :returns: a boolean series where data_values are present in col as True
    """

    def __categorical_data_idx(col: pd.Series, data_values: List[Any]) -> pd.Series:
        # create indexing series with boolean OR of facet values
        index_key_series: pd.Series = col == data_values[0]
        for val in data_values[1:]:
            index_key_series = index_key_series | (col == val)
        return index_key_series

    index_key_series = __categorical_data_idx(col, positive_values)
    if any(index_key_series):
        return index_key_series

    positive_values = common.convert_positive_label_values(col, positive_values)
    return __categorical_data_idx(col, positive_values)