예제 #1
0
 def _parseids(self, ids):
     if isinstance(ids, tuple):
         raise IndexError('too many dimensions for array')
     if (listable(ids) and checkany(ids, isstring)) or isstring(ids):
         return self.idsof(ids, safe=False)
     if listable(ids) and checkany(ids, lambda v: isinstance(v, bool)):
         return np.where(ids)[0]
     if ids is None: return slice(None)
     return ids
예제 #2
0
 def _parsevals(value, arrayonly=False):
     if isinstance(value, NamedIndex):
         val = value._names
     elif iterable(value):
         val = np.asarray(ll(value), dtype=object)
         if checkany(val, lambda x: not isstring(x)):
             raise TypeError('index names must be string')
     else:
         if arrayonly: raise TypeError('index names must be an array')
         if not isstring(value):
             raise TypeError('index name must be a string')
         val = value
     return val
예제 #3
0
 def idsof(self,
           names: Union[str, Iterable[str]],
           safe: bool = False) -> Union[None, int, List[Union[None, int]]]:
     if isstring(names):
         ids = self._nidct.get(names, None)
         if not safe and missing(ids):
             raise KeyError(f'unknown index name {names}')
     else:
         ids = [
             self._nidct.get(n, None) if isstring(n) else n for n in names
         ]
         if not safe and checkany(ids, missing):
             raise KeyError('unknown index name(s)')
     return ids
예제 #4
0
    def _parseids(self, idx, axis=None, mapslice=True):
        if missing(axis):
            sids, aids = (idx, slice(None)) if not isinstance(idx, tuple) else \
                         (idx[0], slice(None)) if len(idx) == 1 else idx
        else:
            if isinstance(idx, tuple):
                raise IndexError('too many dimensions for array')
            if axis not in (0, 1): raise IndexError('invalid axis value')
            sids, aids = (idx, slice(None)) if axis == 0 else (slice(None),
                                                               idx)

        def _wrap(ids):
            if ids is None: return slice(None)
            if isinstance(ids, slice): return ids
            if not listable(ids): return [ids]
            return ids

        sids, aids = smap((sids, aids), _wrap)

        if (isinstance(sids, slice) and mapslice) or (
                listable(sids) and checkany(sids, lambda x: not isstring(x))):
            sids = self.names[sids]
        return sids, aids
예제 #5
0
파일: table.py 프로젝트: akialbz/Kagami
 def _mapids(ids, names):
     if isinstance(ids, NamedIndex): ids = np.array(ids)
     if not listable(ids): ids = [ids]
     if not checkany(ids, isstring): return ids
     if missing(names): raise KeyError('table names not set')
     return names.idsof(ids, safe = False)