Ejemplo n.º 1
0
    def delete(self,
               pos: Indices2D,
               axis: Optional[int] = 0,
               inline: bool = False) -> StructuredArray:
        narr = self if inline else self.copy()
        if isstring(pos):
            del narr._arrs[pos]
            return narr

        sids, aids = self._parseids(pos, axis=axis, mapslice=False)
        slic = isinstance(sids, slice) and sids == slice(None)
        alic = isinstance(aids,
                          slice) and aids == slice(None) and (missing(axis)
                                                              or axis == 0)

        if slic and alic:
            narr._arrs = OrderedDict()
            narr._length = None
        elif slic and not alic:
            if listable(aids) and len(aids) == 1 and aids[0] < 0:
                aids = aids[
                    0]  # fix the issue that currently negative indices are ignored by np.delete
            for k, v in narr._arrs.items():
                narr._arrs[k] = np.delete(v, aids)
            narr._length = len(narr._arrs[l(narr._arrs.keys())[0]])
        elif not slic and alic:
            if isinstance(sids, slice) or sids.dtype.kind not in ('S', 'U'):
                sids = narr.names[sids]
            for k in sids:
                del narr._arrs[k]
        else:
            raise IndexError('unable to delete portion of the array')

        return narr
Ejemplo n.º 2
0
def load(fname: Union[str, Path], *, mode: str = 'r',
         skips: Optional[int] = None, comment: Optional[str] = None, strip: bool = False, **kwargs: Any) -> List[List[str]]:
    checkInputFile(fname)
    with open(fname, mode) as f:
        if available(skips) and skips > 0:
            for _ in range(skips): next(f)
        tb = csv.reader(f, **kwargs)
        if strip: tb = drop(tb, lambda x: len(x) == 0 or (len(x) == 1 and x[0].strip() == ''))
        if available(comment): tb = drop(tb, lambda x: x[0].startswith(comment))
        tb = l(tb)
    return tb
Ejemplo n.º 3
0
 def tolist(self) -> List:
     return l(self._names.tolist())
Ejemplo n.º 4
0
 def fields(self) -> List[Tuple[str, np.ndarray]]:
     return l(self._arrs.items())
Ejemplo n.º 5
0
 def arrays(self) -> List[np.ndarray]:
     return l(self._arrs.values())
Ejemplo n.º 6
0
 def names(self) -> np.ndarray:
     return np.array(l(self._arrs.keys()))