How to use the deepdish.io.ls.Node function in deepdish

To help you get started, we’ve selected a few deepdish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
elif hasattr(level._v_attrs, 'strtype'):
            strtype = level._v_attrs.strtype
            itemsize = level._v_attrs.itemsize
            if strtype == b'unicode':
                shape = level.shape[:-1] + (level.shape[-1] // itemsize // 4,)
            elif strtype == b'ascii':
                shape = level.shape

            node = NumpyArrayNode(shape, strtype.decode('ascii'))

        return node
    elif isinstance(level, tables.link.SoftLink):
        node = SoftLinkNode(level.target)
        return node
    else:
        return Node()
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
def print(self, level=0, parent='/', colorize=True, max_level=None,
              file=sys.stdout):
        if level == 0 and not self.header.get('dd_io_unpack'):
            print_row('', self.info(colorize=colorize,
                                    final_level=(0 == max_level)),
                      level=level, parent=parent, unpack=False,
                      colorize=colorize, file=file)
        DictNode.print(self, level, parent, colorize, max_level, file)

    def __repr__(self):
        s = ['{}={}'.format(k, repr(v)) for k, v in self.children.items()]
        return 'SimpleNamespaceNode({})'.format(', '.join(s))


class PandasDataFrameNode(Node):
    def __init__(self, shape):
        self.shape = shape

    def info(self, colorize=True, final_level=False):
        d = {}
        if self.shape is not None:
            d['extra'] = repr(self.shape)

        return type_string('DataFrame',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
        return 'PandasDataFrameNode({})'.format(self.shape)
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
def info(self, colorize=True, final_level=False):
        d = {}
        if self.size is not None:
            d['extra'] = repr((self.size,))
        if self.dtype is not None:
            d['dtype'] = str(self.dtype)

        return type_string('Series',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
        return 'SeriesNode()'


class ListNode(Node):
    def __init__(self, typename='list'):
        self.children = []
        self.typename = typename

    def append(self, v):
        self.children.append(v)

    def __repr__(self):
        s = [repr(v) for v in self.children]
        return 'ListNode({})'.format(', '.join(s))

    def print(self, level=0, parent='/', colorize=True,
              max_level=None, file=sys.stdout, settings={}):

        if level < max_level:
            for i, v in enumerate(self.children):
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
self.shape = shape

    def info(self, colorize=True, final_level=False):
        d = {}
        if self.shape is not None:
            d['extra'] = repr(self.shape)

        return type_string('DataFrame',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
        return 'PandasDataFrameNode({})'.format(self.shape)


class PandasPanelNode(Node):
    def __init__(self, shape):
        self.shape = shape

    def info(self, colorize=True, final_level=False):
        d = {}
        if self.shape is not None:
            d['extra'] = repr(self.shape)

        return type_string('Panel',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
        return 'PandasPanelNode({})'.format(self.shape)
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
colorize=colorize)


class ObjectNode(Node):
    def __init__(self):
        pass

    def __repr__(self):
        return 'ObjectNode'

    def info(self, colorize=True, final_level=False):
        return type_string('pickled', dtype='object', type_color='yellow',
                           colorize=colorize)


class SoftLinkNode(Node):
    def __init__(self, target):
        self.target = target

    def info(self, colorize=True, final_level=False):
        return type_string('link -> {}'.format(self.target),
                           dtype='SoftLink',
                           type_color='cyan',
                           colorize=colorize)

    def __repr__(self):
        return ('SoftLinkNode(target={})'
                .format(self.target))


def _tree_level(level, raw=False, settings={}):
    if isinstance(level, tables.Group):
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
self.shape = shape

    def info(self, colorize=True, final_level=False):
        d = {}
        if self.shape is not None:
            d['extra'] = repr(self.shape)

        return type_string('Panel',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
        return 'PandasPanelNode({})'.format(self.shape)


class PandasSeriesNode(Node):
    def __init__(self, size, dtype):
        self.size = size
        self.dtype = dtype

    def info(self, colorize=True, final_level=False):
        d = {}
        if self.size is not None:
            d['extra'] = repr((self.size,))
        if self.dtype is not None:
            d['dtype'] = str(self.dtype)

        return type_string('Series',
                           type_color='red',
                           colorize=colorize, **d)

    def __repr__(self):
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
self.shape = shape
        self.dtype = dtype

    def info(self, colorize=True, final_level=False):
        return type_string('sparse {}'.format(self.sparse_format),
                           extra=repr(self.shape),
                           dtype=str(self.dtype),
                           type_color='red',
                           colorize=colorize)

    def __repr__(self):
        return ('NumpyArrayNode(shape={}, dtype={})'
                .format(self.shape, self.dtype))


class ValueNode(Node):
    def __init__(self, value):
        self.value = value

    def __repr__(self):
        return 'ValueNode(type={})'.format(type(self.value))

    def info(self, colorize=True, final_level=False):
        if isinstance(self.value, six.text_type):
            if len(self.value) > 25:
                s = repr(self.value[:22] + '...')
            else:
                s = repr(self.value)

            return type_string(s, dtype='unicode',
                               type_color='green',
                               extra='({})'.format(len(self.value)),
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
return type_string(s, dtype='ascii',
                               type_color='green',
                               extra='({})'.format(len(self.value)),
                               colorize=colorize)
        elif self.value is None:
            return type_string('None', dtype='python',
                               type_color='blue',
                               colorize=colorize)
        else:
            return type_string(repr(self.value)[:20],
                               dtype=str(np.dtype(type(self.value))),
                               type_color='blue',
                               colorize=colorize)


class ObjectNode(Node):
    def __init__(self):
        pass

    def __repr__(self):
        return 'ObjectNode'

    def info(self, colorize=True, final_level=False):
        return type_string('pickled', dtype='object', type_color='yellow',
                           colorize=colorize)


class SoftLinkNode(Node):
    def __init__(self, target):
        self.target = target

    def info(self, colorize=True, final_level=False):
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
if len(raw_s) < 25:
                s += ' ' * (25 - len(raw_s))
            s += paint(' {:14.2g}'.format(self.statistics.get('mean')),
                       'white', colorize=colorize)
            s += paint(u' \u00b1 ', 'darkgray', colorize=colorize)
            s += paint('{:.2g}'.format(self.statistics.get('std')),
                       'reset', colorize=colorize)

        return s

    def __repr__(self):
        return ('NumpyArrayNode(shape={}, dtype={})'
                .format(self.shape, self.dtype))


class SparseMatrixNode(Node):
    def __init__(self, fmt, shape, dtype):
        self.sparse_format = fmt
        self.shape = shape
        self.dtype = dtype

    def info(self, colorize=True, final_level=False):
        return type_string('sparse {}'.format(self.sparse_format),
                           extra=repr(self.shape),
                           dtype=str(self.dtype),
                           type_color='red',
                           colorize=colorize)

    def __repr__(self):
        return ('NumpyArrayNode(shape={}, dtype={})'
                .format(self.shape, self.dtype))
github uchicago-cs / deepdish / deepdish / io / ls.py View on Github external
value))


class Node(object):
    def __repr__(self):
        return 'Node'

    def print(self, level=0, parent='/', colorize=True, max_level=None,
              file=sys.stdout, settings={}):
        pass

    def info(self, colorize=True, final_level=False):
        return paint('Node', 'red', colorize=colorize)


class FileNotFoundNode(Node):
    def __init__(self, filename):
        self.filename = filename

    def __repr__(self):
        return 'FileNotFoundNode'

    def print(self, level=0, parent='/', colorize=True, max_level=None,
              file=sys.stdout, settings={}):
        print(paint('File not found', 'red', colorize=colorize),
              file=file)

    def info(self, colorize=True, final_level=False):
        return paint('FileNotFoundNode', 'red', colorize=colorize)


class InvalidFileNode(Node):