# Path: DSTK/FeatureBinning/_utils.py
# def _filter_special_values(values, filter_values):
#     feats = np.array(values)
#     filters = np.array(filter_values)
# 
#     special_vals_idx_dct = dict()
#     for val in filters:
#         if np.isnan(val):
#             idx = np.where(np.isnan(feats))[0]
#         else:
#             idx = np.where(feats == val)[0]
# 
#         special_vals_idx_dct.update({str(val): idx})
# 
#     all_special_idx = list()
#     for vals in special_vals_idx_dct.values():
#         all_special_idx += vals.tolist()
# 
#     all_special_idx = np.asarray(all_special_idx)
#     all_idx = np.arange(0, len(feats), 1, dtype=int)
#     all_non_special_idx = [idx for idx in all_idx if idx not in all_special_idx]
#     special_vals_idx_dct.update({'regular': all_non_special_idx})
# 
#     return special_vals_idx_dct
# 
# def _naive_bayes_bins(target, prior, num_classes=2):
#     if len(target) > 1:
#         cnts = np.bincount(target, minlength=num_classes)
#         return list(cnts / cnts.sum())
#     else:
#         return [1 - prior, prior]


import numpy as np
from DSTK.FeatureBinning._utils import _filter_special_values, _naive_bayes_bins



def test_special_values_filter():
    vals = np.asarray([-1.0, 3.1, 11.3, 0.5, np.NaN, -1.0, 3.1])
    special_vals = np.asarray([-1.0, np.NaN])

    idx_dct = _filter_special_values(vals, special_vals)

    np.testing.assert_equal(idx_dct[str(np.NaN)], [4])
    np.testing.assert_equal(idx_dct[str(-1.0)], [0, 5])
    np.testing.assert_equal(idx_dct['regular'], [1, 2, 3, 6])


def test_special_values_filter_2():
    vals = np.asarray([-1.0, 3.1, 11.3, 0.5, np.NaN, -1.0, 3.1])
    special_vals = np.asarray([np.NaN])


# Path: DSTK/FeatureBinning/_utils.py
# def _filter_special_values(values, filter_values):
#     feats = np.array(values)
#     filters = np.array(filter_values)
# 
#     special_vals_idx_dct = dict()
#     for val in filters:
#         if np.isnan(val):
#             idx = np.where(np.isnan(feats))[0]
#         else:
#             idx = np.where(feats == val)[0]
# 
#         special_vals_idx_dct.update({str(val): idx})
# 
#     all_special_idx = list()
#     for vals in special_vals_idx_dct.values():
#         all_special_idx += vals.tolist()
# 
#     all_special_idx = np.asarray(all_special_idx)
#     all_idx = np.arange(0, len(feats), 1, dtype=int)
#     all_non_special_idx = [idx for idx in all_idx if idx not in all_special_idx]
#     special_vals_idx_dct.update({'regular': all_non_special_idx})
# 
#     return special_vals_idx_dct
# 
# def _naive_bayes_bins(target, prior, num_classes=2):
#     if len(target) > 1:
#         cnts = np.bincount(target, minlength=num_classes)
#         return list(cnts / cnts.sum())
#     else:
#         return [1 - prior, prior]


# Path: DSTK/tests/test_feature_binner/test_utils.py
import numpy as np
from DSTK.FeatureBinning._utils import _filter_special_values, _naive_bayes_bins




def test_special_values_filter():
    vals = np.asarray([-1.0, 3.1, 11.3, 0.5, np.NaN, -1.0, 3.1])
    special_vals = np.asarray([-1.0, np.NaN])

    idx_dct = _filter_special_values(vals, special_vals)

    np.testing.assert_equal(idx_dct[str(np.NaN)], [4])
    np.testing.assert_equal(idx_dct[str(-1.0)], [0, 5])
    np.testing.assert_equal(idx_dct['regular'], [1, 2, 3, 6])


def test_special_values_filter_2():
    vals = np.asarray([-1.0, 3.1, 11.3, 0.5, np.NaN, -1.0, 3.1])
    special_vals = np.asarray([np.NaN])


    idx_dct = _filter_special_values(vals, special_vals)