(scores, quantile_points)
return rs
left edge and right edge of last interval are closed
left edge and right edge of last interval are closed
left edge and right edge of last interval are closed
def quantile_binning_and_count(scores, quantile_points):

        """
        left edge and right edge of last interval are closed
        """

        assert len(quantile_points) >= 2

        left_bounds = copy.deepcopy(quantile_points[:-1])
        right_bounds = copy.deepcopy(quantile_points[1:])

        last_interval_left = left_bounds.pop()
        last_interval_right = right_bounds.pop()

        bin_result_1, bin_result_2 = None, None

        if len(left_bounds) != 0 and len(right_bounds) != 0:
            bin_result_1 = pd.cut(scores, pd.IntervalIndex.from_arrays(left_bounds, right_bounds, closed='left'))

        bin_result_2 = pd.cut(scores, pd.IntervalIndex.from_arrays([last_interval_left], [last_interval_right],
                                                                   closed='both'))

        count1 = None if bin_result_1 is None else bin_result_1.value_counts().reset_index()
        count2 = bin_result_2.value_counts().reset_index()

        # if predict scores are the same, count1 will be None, only one interval exists
        final_interval = list(count1['index']) + list(count2['index']) if count1 is not None else list(count2['index'])
        final_count = list(count1[0]) + list(count2[0]) if count1 is not None else list(count2[0])
        rs = {'interval': final_interval, 'count': final_count}

        return rs
def quantile_binning_and_count ( scores , quantile_points ) : assert len ( quantile_points ) >= 2 left_bounds = copy . deepcopy ( quantile_points [ : - 1 ] ) right_bounds = copy . deepcopy ( quantile_points [ 1 : ] ) last_interval_left = left_bounds . pop ( ) last_interval_right = right_bounds . pop ( ) bin_result_1 , bin_result_2 = None , None if len ( left_bounds ) != 0 and len ( right_bounds ) != 0 : bin_result_1 = pd . cut ( scores , pd . IntervalIndex . from_arrays ( left_bounds , right_bounds , closed = 'left' ) ) bin_result_2 = pd . cut ( scores , pd . IntervalIndex . from_arrays ( [ last_interval_left ] , [ last_interval_right ] , closed = 'both' ) ) count1 = None if bin_result_1 is None else bin_result_1 . value_counts ( ) . reset_index ( ) count2 = bin_result_2 . value_counts ( ) . reset_index ( ) # if predict scores are the same, count1 will be None, only one interval exists final_interval = list ( count1 [ 'index' ] ) + list ( count2 [ 'index' ] ) if count1 is not None else list ( count2 [ 'index' ] ) final_count = list ( count1 [ 0 ] ) + list ( count2 [ 0 ] ) if count1 is not None else list ( count2 [ 0 ] ) rs = { 'interval' : final_interval , 'count' : final_count } return rs