Expand group names.

    Args:
        grp (string): group names to expand

    Returns:
        list of groups

    Examples:

        * grp[1-3] will be expanded to [grp1, grp2, grp3]
        * grp1 will be expanded to [grp1]
422783
def expand_groups(grp):
    
    p = re.compile(r"(?P<name>.+)\[(?P<start>\d+)-(?P<end>\d+)\]")
    m = p.match(grp)
    if m is not None:
        s = int(m.group('start'))
        e = int(m.group('end'))
        n = m.group('name')
        return list(map(lambda x: n + str(x), range(s, e + 1)))
    else:
        return [grp]
119110
def _add_constraints(self, relation):
        
        names = []
        expression = relation.expression
        for value_set in expression.value_sets():
            name = next(self._constr_names)
            self._p.addConstr(
                self._grb_expr_from_value_set(value_set),
                self.CONSTR_SENSE_MAP[relation.sense],
                -float(expression.offset), name)
            names.append(name)

        self._p.update()

        return names
436844
def create_group(self, group_name, path='/'):
        
        params = {'GroupName' : group_name,
                  'Path' : path}
        return self.get_response('CreateGroup', params)
1327894
def pars_in_groups(self):
        
        pargp = self.par_groups
        allpars = dict()
        for cpg in pargp:
            allpars[cpg] = [i for i in self.parameter_data.loc[self.parameter_data.pargp == cpg, 'parnme']]
        return allpars
153077
def groups(self):
        

        # this is mainly for compat
        # GH 3881
        result = {key: value for key, value in zip(self.binlabels, self.bins)
                  if key is not NaT}
        return result
778671
def grp_by_src(self):
        
        smodels = []
        grp_id = 0
        for sm in self.source_models:
            src_groups = []
            smodel = sm.__class__(sm.names, sm.weight, sm.path, src_groups,
                                  sm.num_gsim_paths, sm.ordinal, sm.samples)
            for sg in sm.src_groups:
                for src in sg.sources:
                    src.src_group_id = grp_id
                    src_groups.append(
                        sourceconverter.SourceGroup(
                            sg.trt, [src], name=src.source_id, id=grp_id))
                    grp_id += 1
            smodels.append(smodel)
        return self.__class__(self.gsim_lt, self.source_model_lt, smodels,
                              self.optimize_same_id)
1120587
def add_grpSp(self):
        
        shape_id = self._next_shape_id
        name = 'Group %d' % (shape_id-1,)
        grpSp = CT_GroupShape.new_grpSp(shape_id, name)
        self.insert_element_before(grpSp, 'p:extLst')
        return grpSp
200240
def get_grp_ids(self, sm_id):
        
        return [sg.id for sg in self.source_models[sm_id].src_groups]
1033567
def _expand_list(names):
  

  if names is None:
    names = []
  elif isinstance(names, basestring):
    names = [names]

  results = []  # The expanded list.
  items = {}  # Cached contents of buckets; used for matching.
  for name in names:
    bucket, key = datalab.storage._bucket.parse_name(name)
    results_len = len(results)  # If we fail to add any we add name and let caller deal with it.
    if bucket:
      if not key:
        # Just a bucket; add it.
        results.append('gs://%s' % bucket)
      elif datalab.storage.Item(bucket, key).exists():
        results.append('gs://%s/%s' % (bucket, key))
      else:
        # Expand possible key values.
        if bucket not in items and key[:1] == '*':
          # We need the full list; cache a copy for efficiency.
          items[bucket] = [item.metadata.name
                           for item in list(datalab.storage.Bucket(bucket).items())]
        # If we have a cached copy use it
        if bucket in items:
          candidates = items[bucket]
        # else we have no cached copy but can use prefix matching which is more efficient than
        # getting the full contents.
        else:
          # Get the non-wildchar prefix.
          match = re.search('\?|\*|\[', key)
          prefix = key
          if match:
            prefix = key[0:match.start()]

          candidates = [item.metadata.name
                        for item in datalab.storage.Bucket(bucket).items(prefix=prefix)]

        for item in candidates:
          if fnmatch.fnmatch(item, key):
            results.append('gs://%s/%s' % (bucket, item))

    # If we added no matches, add the original name and let caller deal with it.
    if len(results) == results_len:
      results.append(name)

  return results
1126105
def _expand_qname(self, qname):
        """"""
        if type(qname) is not rt.URIRef:
            raise TypeError("Cannot expand qname of type {}, must be URIRef"
                            .format(type(qname)))
        for ns in self.graph.namespaces():
            if ns[0] == qname.split(':')[0]:
                return rt.URIRef("%s%s" % (ns[1], qname.split(':')[-1]))
        return qname
57362
def get_group_by_name(self, group_name: str) -> typing.Optional['Group']:
        
        VALID_STR.validate(group_name, 'get_group_by_name')
        for group in self.groups:

            if group.group_name == group_name:
                return group
        return None
451584
def get_partition_trees(self, p):
        
        trees = []
        for grp in p.get_membership():
            try:
                result = self.get_group_result(grp)
                trees.append(result['ml_tree'])
            except ValueError:
                trees.append(None)
                logger.error('No tree found for group {}'.format(grp))
        return trees
760419
def gid_to_group(gid):
    '''
    
    '''
    try:
        gid = int(gid)
    except ValueError:
        # This is not an integer, maybe it's already the group name?
        gid = group_to_gid(gid)

    if gid == '':
        # Don't even bother to feed it to grp
        return ''

    try:
        return grp.getgrgid(gid).gr_name
    except (KeyError, NameError):
        # If group is not present, fall back to the gid.
        return gid
574983
def add_group(self, L):
        
        if len(L) == 1:
            self.add(L[0])
        elif len(L) >= 2:
            x = PQ_node(P_shape)
            x.add_all(L)
            self.add(x)
886487
def build_groups(self):
        
        # check if there are any groupings
        if len(self.groups):
            groups = []

            # get the group sql for each grouping
            for group in self.groups:
                groups.append(group.get_name())
            return 'GROUP BY {0} '.format(', '.join(groups))
        return ''
887819
def group(self, *args, **kwargs):
        
        return super().group(
            *args, cls=kwargs.pop('cls', Group) or Group, **kwargs)
1217996
def grouper(num, iterable, fillvalue=None):
    ""
    # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
    args = [iter(iterable)] * num
    return zip_longest(fillvalue=fillvalue, *args)