Get unique index value for each bar
332176
def _get_values(self):
        
        (gi, _), (ci, _), (si, _) = self._get_dims(self.hmap.last)
        ndims = self.hmap.last.ndims
        dims = self.hmap.last.kdims
        dimensions = []
        values = {}
        for vidx, vtype in zip([gi, ci, si], self._dimensions):
            if vidx < ndims:
                dim = dims[vidx]
                dimensions.append(dim)
                vals = self.hmap.dimension_values(dim.name)
            else:
                dimensions.append(None)
                vals = [None]
            values[vtype] = list(unique_iterator(vals))
        return values, dimensions
336606
def any_unique(keys, axis=semantics.axis_default):
    """"""
    index = as_index(keys, axis)
    return np.any(index.count == 1)
1218106
def unique(self, values):
        """"""
        _, count = self.count()
        if not np.array_equiv(count, 1):
            raise ValueError("Not every entry in the table is assigned a unique value")
        return self.sum(values)
762627
@SuppressWarnings("unchecked")
    private static Object getIndexedValue(Object obj, Property property, int index, ObjectWrapper options) {
        if (property == null) {
            throw new IllegalArgumentException("Cannot get the indexed value from 'null' property.");
        }

        Object propertyValue = property.get(obj);

        if (propertyValue == null) {
            throw new NullPointerException("Invalid 'null' value found for indexed '" + property + "' in "
                                                   + obj.getClass().getName() + ".");

        }

        if (propertyValue instanceof List) {
            List list = (List) propertyValue;
            int size = list.size();

            if (size < index) {
                if (options.isOutOfBoundsSafety) {
                    return null;
                } else {
                    throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                                + obj.getClass().getSimpleName() + " object has only '" + size + "' elements," +
                                                                " but index '" + index + "' requested.");
                }
            }

            return list.get(index);
        } else if (propertyValue.getClass().isArray()) {
            int lenght = Array.getLength(propertyValue);

            if (lenght < index && options.isOutOfBoundsSafety) {
                return null;
            }

            try {
                return Array.get(propertyValue, index);
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                            + obj.getClass().getSimpleName() + " object has only '" + lenght + "' elements," +
                                                            " but index '" + index + "' requested.");

            }
        } else if (propertyValue instanceof Iterable) {
            Iterable iterable = (Iterable) propertyValue;

            int k = 0;
            for (Object object : iterable) {
                if (k == index) {
                    return object;
                }

                k++;// Hopefully not an infinite iteration
            }

            // Nothing found
            if (options.isOutOfBoundsSafety) {
                return null;
            } else {
                throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                            + obj.getClass().getSimpleName() + " object has less than '" + index + "'" +
                                                            " elements.");
            }
        } else {
            throw new IllegalArgumentException("Cannot get an indexed value from the not indexed " + property
                                                       + ". Only List, array and Iterable types are supported, but " + property.getType().getSimpleName()
                                                       + " found.");
        }
    }
1283657
function unique (array) {
    var ret = [];

    array.forEach(function (val) {
        if (ret.indexOf(val) === -1) {
            ret.push(val);
        }
    });

    return ret;
}
370891
def unique_array(arr):
    
    if not len(arr):
        return np.asarray(arr)
    elif pd:
        if isinstance(arr, np.ndarray) and arr.dtype.kind not in 'MO':
            # Avoid expensive unpacking if not potentially datetime
            return pd.unique(arr)

        values = []
        for v in arr:
            if (isinstance(v, datetime_types) and
                not isinstance(v, cftime_types)):
                v = pd.Timestamp(v).to_datetime64()
            values.append(v)
        return pd.unique(values)
    else:
        arr = np.asarray(arr)
        _, uniq_inds = np.unique(arr, return_index=True)
        return arr[np.sort(uniq_inds)]
509355
def _make_index(df, cols=META_IDX):
    """"""
    return pd.MultiIndex.from_tuples(
        pd.unique(list(zip(*[df[col] for col in cols]))), names=tuple(cols))
390799
def unique_justseen(iterable, key=None):
    ""
    # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
    # unique_justseen('ABBCcAD', str.lower) --> A B C A D
    return imap(next, imap(operator.itemgetter(1), groupby(iterable, key)))
1228877
function(datasetIndex, index) {
		var me = this;
		var chart = me.chart;
		var meta = me.getMeta();
		var scale = me._getValueScale();
		var isHorizontal = scale.isHorizontal();
		var datasets = chart.data.datasets;
		var value = +scale.getRightValue(datasets[datasetIndex].data[index]);
		var minBarLength = scale.options.minBarLength;
		var stacked = scale.options.stacked;
		var stack = meta.stack;
		var start = 0;
		var i, imeta, ivalue, base, head, size;

		if (stacked || (stacked === undefined && stack !== undefined)) {
			for (i = 0; i < datasetIndex; ++i) {
				imeta = chart.getDatasetMeta(i);

				if (imeta.bar &&
					imeta.stack === stack &&
					imeta.controller._getValueScaleId() === scale.id &&
					chart.isDatasetVisible(i)) {

					ivalue = +scale.getRightValue(datasets[i].data[index]);
					if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
						start += ivalue;
					}
				}
			}
		}

		base = scale.getPixelForValue(start);
		head = scale.getPixelForValue(start + value);
		size = head - base;

		if (minBarLength !== undefined && Math.abs(size) < minBarLength) {
			size = minBarLength;
			if (value >= 0 && !isHorizontal || value < 0 && isHorizontal) {
				head = base - minBarLength;
			} else {
				head = base + minBarLength;
			}
		}

		return {
			size: size,
			base: base,
			head: head,
			center: head + size / 2
		};
	}
450871
def unique_dimkeys(obj, default_dim='Frame'):
    
    from .ndmapping import NdMapping, item_check
    from .spaces import HoloMap
    key_dims = obj.traverse(lambda x: (tuple(x.kdims),
                                       list(x.data.keys())), (HoloMap,))
    if not key_dims:
        return [Dimension(default_dim)], [(0,)]
    dim_groups, keys = zip(*sorted(key_dims, key=lambda x: -len(x[0])))
    dgroups = [frozenset(d.name for d in dg) for dg in dim_groups]
    subset = all(g1 <= g2 or g1 >= g2 for g1 in dgroups for g2 in dgroups)
    # Find unique keys
    if subset:
        dims = merge_dimensions(dim_groups)
        all_dims = sorted(dims, key=lambda x: dim_groups[0].index(x))
    else:
        # Handle condition when HoloMap/DynamicMap dimensions do not overlap
        hmaps = obj.traverse(lambda x: x, ['HoloMap'])
        if hmaps:
            raise ValueError('When combining HoloMaps into a composite plot '
                             'their dimensions must be subsets of each other.')
        dimensions = merge_dimensions(dim_groups)
        dim_keys = {}
        for dims, keys in key_dims:
            for key in keys:
                for d, k in zip(dims, key):
                    dim_keys[d.name] = k
        if dim_keys:
            keys = [tuple(dim_keys.get(dim.name) for dim in dimensions)]
        else:
            keys = []
        return merge_dimensions(dim_groups), keys

    ndims = len(all_dims)
    unique_keys = []
    for group, keys in zip(dim_groups, keys):
        dim_idxs = [all_dims.index(dim) for dim in group]
        for key in keys:
            padded_key = create_ndkey(ndims, dim_idxs, key)
            matches = [item for item in unique_keys
                       if padded_key == tuple(k if k is None else i
                                              for i, k in zip(item, padded_key))]
            if not matches:
                unique_keys.append(padded_key)

    with item_check(False):
        sorted_keys = NdMapping({key: None for key in unique_keys},
                                kdims=all_dims).data.keys()
    return all_dims, list(sorted_keys)
715348
def _bar(self, target_name, current, total):
        
        bar_len = 30

        if total is None:
            state = 0
            percent = "?% "
        else:
            total = int(total)
            state = int((100 * current) / total) if current < total else 100
            percent = str(state) + "% "

        if self._n_total > 1:
            num = "({}/{}): ".format(self._n_finished + 1, self._n_total)
        else:
            num = ""

        n_sh = int((state * bar_len) / 100)
        n_sp = bar_len - n_sh
        pbar = "[" + "#" * n_sh + " " * n_sp + "] "

        return num + pbar + percent + target_name
1063148
def get_index_by_name(self, name):
        """"""
        for i in range(self.n_blocks):
            if self.get_block_name(i) == name:
                return i
        raise KeyError('Block name ({}) not found'.format(name))
83607
def create_index(column_names, unique=False):
    
    connection = _State.connection()
    _State.reflect_metadata()
    table_name = _State.table.name

    table = _State.table

    index_name = re.sub(r'[^a-zA-Z0-9]', '', table_name) + '_'
    index_name += '_'.join(re.sub(r'[^a-zA-Z0-9]', '', x)
                           for x in column_names)

    if unique:
        index_name += '_unique'

    columns = []
    for column_name in column_names:
        columns.append(table.columns[column_name])

    current_indices = [x.name for x in table.indexes]
    index = sqlalchemy.schema.Index(index_name, *columns, unique=unique)
    if index.name not in current_indices:
        index.create(bind=_State.engine)
127425
function(each){
    var indexVarName = each.key || 'pug_index' + this.eachCount;
    this.eachCount++;

    this.buf.push(''
      + '// iterate ' + each.obj + '\n'
      + ';(function(){\n'
      + '  var $$obj = ' + each.obj + ';\n'
      + '  if (\'number\' == typeof $$obj.length) {');

    if (each.alternate) {
      this.buf.push('    if ($$obj.length) {');
    }

    this.buf.push(''
      + '      for (var ' + indexVarName + ' = 0, $$l = $$obj.length; ' + indexVarName + ' < $$l; ' + indexVarName + '++) {\n'
      + '        var ' + each.val + ' = $$obj[' + indexVarName + '];');

    this.visit(each.block, each);

    this.buf.push('      }');

    if (each.alternate) {
      this.buf.push('    } else {');
      this.visit(each.alternate, each);
      this.buf.push('    }');
    }

    this.buf.push(''
      + '  } else {\n'
      + '    var $$l = 0;\n'
      + '    for (var ' + indexVarName + ' in $$obj) {\n'
      + '      $$l++;\n'
      + '      var ' + each.val + ' = $$obj[' + indexVarName + '];');

    this.visit(each.block, each);

    this.buf.push('    }');
    if (each.alternate) {
      this.buf.push('    if ($$l === 0) {');
      this.visit(each.alternate, each);
      this.buf.push('    }');
    }
    this.buf.push('  }\n}).call(this);\n');
  }
530357
def get_nth_unique_value(self, keypath, n, distance_from, open_interval=True):
        
        unique_values = self.get_ordered_values(keypath, distance_from, open_interval)
        if 0 <= n < len(unique_values):
            #logging.error("%i th unique value is %s" % (n, str(unique_values[n])))
            return unique_values[n]
        else:
            raise Contradiction("n-th Unique value out of range: " + str(n))
607217
def _BuildIndex(self):
        """"""
        self._index = {}
        for i, k in enumerate(self._keys):
            self._index[k] = i
303922
def rand_indices(x, rand_attr):
    
    loop = True
    indices = range(len(x[0]))

    while loop:
        loop = False
        # randomly selected features without replacement
        rand_list = random.sample(indices, rand_attr)
        for i in rand_list:
            if len(np.unique(x[:, i])) == 1:
                loop = True
                indices.remove(i)
                if len(indices) == rand_attr - 1:
                    return -1  # all features in dataset have one distinct value
                break
    return rand_list