Compute the most frequent value in a 1d array extended with
       [extra_value] * n_repeat, where extra_value is assumed to be not part
       of the array.
431820
def _most_frequent(array, extra_value, n_repeat):
    """"""
    # Compute the most frequent value in array only
    if array.size > 0:
        with warnings.catch_warnings():
            # stats.mode raises a warning when input array contains objects due
            # to incapacity to detect NaNs. Irrelevant here since input array
            # has already been NaN-masked.
            warnings.simplefilter("ignore", RuntimeWarning)
            mode = stats.mode(array)

        most_frequent_value = mode[0][0]
        most_frequent_count = mode[1][0]
    else:
        most_frequent_value = 0
        most_frequent_count = 0

    # Compare to array + [extra_value] * n_repeat
    if most_frequent_count == 0 and n_repeat == 0:
        return np.nan
    elif most_frequent_count < n_repeat:
        return extra_value
    elif most_frequent_count > n_repeat:
        return most_frequent_value
    elif most_frequent_count == n_repeat:
        # Ties the breaks. Copy the behaviour of scipy.stats.mode
        if most_frequent_value < extra_value:
            return most_frequent_value
        else:
            return extra_value
451420
def repeat(self, count):
        
        x = HSeq()
        for i in range(count):
            x = x.concatenate(self)
        return x
306794
def mode_number(self, rows: List[Row], column: NumberColumn) -> Number:
        
        most_frequent_list = self._get_most_frequent_values(rows, column)
        if not most_frequent_list:
            return 0.0  # type: ignore
        most_frequent_value = most_frequent_list[0]
        if not isinstance(most_frequent_value, Number):
            raise ExecutionError(f"Invalid valus for mode_number: {most_frequent_value}")
        return most_frequent_value
681946
def counts(data):
    
    if data is None:
        raise TypeError('None is not iterable')
    table = collections.Counter(data).most_common()
    if not table:
        return table
        # Extract the values with the highest frequency.
    maxfreq = table[0][1]
    for i in range(1, len(table)):
        if table[i][1] != maxfreq:
            table = table[:i]
            break
    return table
302265
def repeat(self, repeats, *args, **kwargs):
        
        nv.validate_repeat(args, kwargs)
        values = self._data.repeat(repeats)
        return type(self)(values.view('i8'), dtype=self.dtype)
1244702
def index_nearest(value, array):
    

    a = (array-value)**2
    return index(a.min(), a)
420451
def has_duplicate(x):
    
    if not isinstance(x, (np.ndarray, pd.Series)):
        x = np.asarray(x)
    return x.size != np.unique(x).size
330961
private void ones(int n) {
        if (n > value.length)
            value = new int[n];
        Arrays.fill(value, -1);
        offset = 0;
        intLen = n;
    }
1009983
def _append_value(self, v_values, next_value, v_idx=None, n_vals=1):
        """"""
        for _ in range(n_vals):
            if v_idx:
                try:
                    v_i = next(v_idx)
                except StopIteration:
                    # Repeating commas are null-statements and can be ignored
                    # Otherwise, we warn the user that this is a bad namelist
                    if next_value is not None:
                        warnings.warn('f90nml: warning: Value {0} is not assigned to '
                              'any variable and has been removed.'
                              ''.format(next_value))

                    # There are more values than indices, so we stop here
                    break

                v_s = [self.default_start_index if idx is None else idx
                       for idx in v_idx.first]

                if not self.row_major:
                    v_i = v_i[::-1]
                    v_s = v_s[::-1]

                # Multidimensional arrays
                if not self.sparse_arrays:
                    pad_array(v_values, list(zip(v_i, v_s)))

                # We iterate inside the v_values and inspect successively
                # deeper lists within the list tree.  If the requested index is
                # missing, we re-size that particular entry.
                # (NOTE: This is unnecessary when sparse_arrays is disabled.)

                v_subval = v_values
                for (i_v, i_s) in zip(v_i[:-1], v_s[:-1]):
                    try:
                        v_subval = v_subval[i_v - i_s]
                    except IndexError:
                        size = len(v_subval)
                        v_subval.extend([] for _ in range(size, i_v - i_s + 1))
                        v_subval = v_subval[i_v - i_s]

                # On the deepest level, we explicitly assign the value
                i_v, i_s = v_i[-1], v_s[-1]
                try:
                    v_subval[i_v - i_s] = next_value
                except IndexError:
                    size = len(v_subval)
                    v_subval.extend(None for _ in range(size, i_v - i_s + 1))
                    v_subval[i_v - i_s] = next_value
            else:
                v_values.append(next_value)
1314629
def _nth(arr, n):
    
    try:
        return arr.iloc[n]
    except (KeyError, IndexError):
        return np.nan
985719
public static function getMostFrequentValues(array $data, $mostFrequentQuantity = NULL, $allocationPeriod = NULL)
    {
        $mostFrequentValues = [];

        $allocatedData = self::allocateInfo($data, $allocationPeriod);

        usort($allocatedData, function ($a, $b) {

            if ($a->getValueQuantity() === $b->getValueQuantity()) {
                if ($a->getValue() === $b->getValueQuantity()) {
                    return 0;
                }
                return ($a->getValue() < $b->getValue()) ? -1 : 1;
            } else {
                return ($a->getValueQuantity() > $b->getValueQuantity()) ? -1 : 1;
            }
        });

        if (!$mostFrequentQuantity) {
            $mostFrequentQuantity = self::MOST_FREQUENT_QUANTITY;
        }

        for ($i = 0; $i < $mostFrequentQuantity; $i++) {

            $frequentValue = new SortData();
            $frequentValue->setValue($allocatedData[$i]->getValue());
            $frequentValue->setValueQuantity($allocatedData[$i]->getValueQuantity());

            $valueExamples = ($allocatedData[$i]->getValueExamples() !== "")
                ? substr($allocatedData[$i]->getValueExamples(), 0, -2)
                : $allocatedData[$i]->getValueExamples();

            $frequentValue->setValueExamples($valueExamples);

            if ($mostFrequentQuantity === 1) {
                $mostFrequentValues = $frequentValue;
            } else {
                $mostFrequentValues[] = $frequentValue;
            }
        }

        return $mostFrequentValues;
    }
223876
def state_max_repeat(self, value):
        """"""
        min_, max_, value = value
        value = [val for val in Traverser(value, self.groups)]
        if not min_ and max_:
            for val in value:
                if isinstance(val, required):
                    min_ = 1
                    break

        for val in value * min_:
            yield val
538095
def has_duplicate_min(x):
    
    if not isinstance(x, (np.ndarray, pd.Series)):
        x = np.asarray(x)
    return np.sum(x == np.min(x)) >= 2
1026226
def get_not_unique_values(array):
    '''
    '''
    s = np.sort(array, axis=None)
    s = s[s[1:] == s[:-1]]
    return np.unique(s)
575373
def _array(group_idx, a, size, fill_value, dtype=None):
    """"""
    if fill_value is not None and not (np.isscalar(fill_value) or
                                       len(fill_value) == 0):
        raise ValueError("fill_value must be None, a scalar or an empty "
                         "sequence")
    order_group_idx = np.argsort(group_idx, kind='mergesort')
    counts = np.bincount(group_idx, minlength=size)
    ret = np.split(a[order_group_idx], np.cumsum(counts)[:-1])
    ret = np.asanyarray(ret)
    if fill_value is None or np.isscalar(fill_value):
        _fill_untouched(group_idx, ret, fill_value)
    return ret
584765
def p_repeat(self, p):
        ''
        p[0] = Repeat(p[3], p[2], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
985938
def has_duplicate_max(x):
    
    if not isinstance(x, (np.ndarray, pd.Series)):
        x = np.asarray(x)
    return np.sum(x == np.max(x)) >= 2