How to use the petl.util.header function in petl

To help you get started, we’ve selected a few petl 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 petl-developers / petl / src / petl / transform / setops.py View on Github external
+-------+-------+-------+
        | 9     | 'A'   | False |
        +-------+-------+-------+

    Note that both tables must have the same set of fields, but that the order
    of the fields does not matter. See also the :func:`complement` function.

    See also the discussion of the `buffersize`, `tempdir` and `cache` arguments
    under the :func:`sort` function.

    .. versionadded:: 0.3

    """

    ha = header(a)
    hb = header(b)
    assert set(ha) == set(hb), 'both tables must have the same set of fields'
    # make sure fields are in the same order
    bv = cut(b, *ha)
    return complement(a, bv, buffersize=buffersize, tempdir=tempdir,
                      cache=cache)
github petl-developers / petl / src / petl / transform / joins.py View on Github external
def natural_key(left, right):
    # determine key field or fields
    lflds = header(left)
    rflds = header(right)
    key = [f for f in lflds if f in rflds]
    assert len(key) > 0, 'no fields in common'
    if len(key) == 1:
        key = key[0]  # deal with singletons
    return key
github petl-developers / petl / src / petl / interactive.py View on Github external
def repr_html(tbl, limit=None, index_header=None, representation=text_type,
              caption=None, encoding='utf-8'):

    # add column indices to header?
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [u'%s|%s' % (i, f)
                          for (i, f) in enumerate(petl.util.header(tbl))]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl

    # limit number of rows output?
    # N.B., limit is max number of data rows (not including header)
    if limit is None:
        # use default
        limit = repr_html_limit

    overflow = False
    if limit > 0:
        # try reading one more than the limit, to see if there are more rows
        target = list(islice(target, 0, limit+2))
        if len(target) > limit+1:
            overflow = True
github petl-developers / petl / petl / interactive.py View on Github external
def repr_html(tbl, limit=None, index_header=None, representation=text_type,
              caption=None, encoding='utf-8'):

    # add column indices to header?
    if index_header is None:
        index_header = repr_index_header  # use default
    if index_header:
        indexed_header = [u'%s|%s' % (i, f)
                          for (i, f) in enumerate(petl.util.header(tbl))]
        target = petl.transform.setheader(tbl, indexed_header)
    else:
        target = tbl

    # limit number of rows output?
    # N.B., limit is max number of data rows (not including header)
    if limit is None:
        # use default
        limit = repr_html_limit

    overflow = False
    if limit > 0:
        # try reading one more than the limit, to see if there are more rows
        target = list(islice(target, 0, limit+2))
        if len(target) > limit+1:
            overflow = True
github petl-developers / petl / petl / interactive.py View on Github external
def __repr__(self):
        if repr_index_header:
            indexed_header = ['%s|%s' % (i, f)
                              for (i, f) in enumerate(petl.util.header(self))]
            target = petl.transform.setheader(self, indexed_header)
        else:
            target = self
        if representation is not None:
            return repr(representation(target))
        else:
            return object.__repr__(target)
github petl-developers / petl / src / petl / transform / joins.py View on Github external
def natural_key(left, right):
    # determine key field or fields
    lflds = header(left)
    rflds = header(right)
    key = [f for f in lflds if f in rflds]
    assert len(key) > 0, 'no fields in common'
    if len(key) == 1:
        key = key[0]  # deal with singletons
    return key
github petl-developers / petl / src / petl / transform / joins.py View on Github external
def itercrossjoin(sources, prefix):

    # construct fields
    outflds = list()
    for i, s in enumerate(sources):
        if prefix:
            # use one-based numbering
            outflds.extend([str(i+1) + '_' + str(f) for f in header(s)])
        else:
            outflds.extend(header(s))
    yield tuple(outflds)

    datasrcs = [data(src) for src in sources]
    for prod in itertools.product(*datasrcs):
        outrow = list()
        for row in prod:
            outrow.extend(row)
        yield tuple(outrow)