Shared func to call any / all Cython GroupBy implementations.
438655
def _bool_agg(self, val_test, skipna):
        

        def objs_to_bool(vals: np.ndarray) -> Tuple[np.ndarray, Type]:
            if is_object_dtype(vals):
                vals = np.array([bool(x) for x in vals])
            else:
                vals = vals.astype(np.bool)

            return vals.view(np.uint8), np.bool

        def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray:
            return result.astype(inference, copy=False)

        return self._get_cythonized_result('group_any_all', self.grouper,
                                           aggregate=True,
                                           cython_dtype=np.uint8,
                                           needs_values=True,
                                           needs_mask=True,
                                           pre_processing=objs_to_bool,
                                           post_processing=result_to_bool,
                                           val_test=val_test, skipna=skipna)
563715
def group_by_types(self):
        """"""
        for t in self.types_of_specie:
            for site in self:
                if site.specie == t:
                    yield site
596590
def _general_multithread(func):
    

    def multithread(templates, stream, *args, **kwargs):
        with pool_boy(ThreadPool, len(stream), **kwargs) as pool:
            return _pool_normxcorr(templates, stream, pool=pool, func=func)

    return multithread
407559
function _groupBy(collection, getter) {
        var result = {};
        var prop;

        forEach( collection, function( elm ) {
          prop = getter(elm);

          if(!result[prop]) {
            result[prop] = [];
          }
          result[prop].push(elm);
        });
        return result;
      }
1048217
def is_cython_or_generator(fn):
    """"""
    if hasattr(fn, "__func__"):
        fn = fn.__func__  # Class method, static method
    if inspect.isgeneratorfunction(fn):
        return True
    name = type(fn).__name__
    return (
        name == "generator"
        or name == "method_descriptor"
        or name == "cython_function_or_method"
        or name == "builtin_function_or_method"
    )
1092332
def groupby(xs, key_fn):
    
    result = defaultdict(list)
    for x in xs:
        key = key_fn(x)
        result[key].append(x)
    return result
411572
def filter(self, func):
        # type: (Callable[[BaseCollection], bool]) -> _CollectionGroupBy
        
        results = OrderedDict()  # type: OrderedDict
        for name, group in self:
            if func(group):
                results[name] = group

        return self.__class__(results)
426287
def cupy_wrapper(func):
    

    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        args = list(args)
        for n, a in enumerate(args):
            if isinstance(a, np.ndarray):
                args[n] = cp.asarray(a)
        for k, v in kwargs.items():
            if isinstance(v, np.ndarray):
                kwargs[k] = cp.asarray(v)
        rtn = func(*args, **kwargs)
        if isinstance(rtn, (list, tuple)):
            for n, a in enumerate(rtn):
                if isinstance(a, cp.core.core.ndarray):
                    rtn[n] = cp.asnumpy(a)
        else:
            if isinstance(rtn, cp.core.core.ndarray):
                rtn = cp.asnumpy(rtn)
        return rtn
    return wrapped
1123104
def grouped_impl(wrap, size, sequence):
    
    iterator = iter(sequence)
    try:
        while True:
            batch = islice(iterator, size)
            yield list(chain((wrap(next(batch)),), batch))
    except StopIteration:
        return
111930
def add_func(self, func, *arg, **kwargs):
        

        return self.groupby(level=1, sort=False).apply(func, *arg, **kwargs)
1056884
def recurse(*cls):
    
    def wrap(f):
        def wrapped_f(tlist):
            for sgroup in tlist.get_sublists():
                if not isinstance(sgroup, cls):
                    wrapped_f(sgroup)
            f(tlist)

        return wrapped_f

    return wrap
519328
def _group(self, obj, val, behavior):
        
        ns = self.Namespace()
        ns.result = {}
        iterator = self._lookupIterator(val)

        def e(value, index, *args):
            key = iterator(value, index)
            behavior(ns.result, key, value)

        _.each(obj, e)

        if len(ns.result) == 1:
            try:
                return ns.result[0]
            except KeyError:
                return list(ns.result.values())[0]
        return ns.result
1347632
def groupby(expr, by, *bys):
    

    if not isinstance(by, list):
        by = [by, ]
    if len(bys) > 0:
        by = by + list(bys)
    return GroupBy(_input=expr, _by=by)
1218418
def grouper(iterable: Iterable, size: int) -> Iterable:
    
    it = iter(iterable)
    while True:
        chunk = list(itertools.islice(it, size))
        if not chunk:
            return
        yield chunk
1080623
def var(self, ddof=1, *args, **kwargs):
        
        nv.validate_groupby_func('var', args, kwargs)
        if ddof == 1:
            try:
                return self._cython_agg_general('var', **kwargs)
            except Exception:
                f = lambda x: x.var(ddof=ddof, **kwargs)
                with _group_selection_context(self):
                    return self._python_agg_general(f)
        else:
            f = lambda x: x.var(ddof=ddof, **kwargs)
            with _group_selection_context(self):
                return self._python_agg_general(f)
1281315
def groupby_dict(dictionary, key):
    ''' 
    '''
    return dict((k, list(g)) for k, g in itertools.groupby(sorted(dictionary.keys(), key=lambda name: dictionary[name][key]), key=lambda name: dictionary[name][key]))
522243
def all(self, func):
        
        return all([func(k, v) for k, v in self.items()])