o
    ;Di                      @   sp   d dl mZmZmZ d dlmZmZmZ dd Zee_dd Z	e	e_	dd Z
e
e_
d	d
 ZdddZdd ZdS )    )absolute_importprint_functiondivision)valuesheaderTablec              	   C   s@   t  }t| |D ]}z
|t|j W q ty   Y qw |S )a  
    Return a set containing all Python types found for values in the given
    field. E.g.::

        >>> import petl as etl
        >>> table = [['foo', 'bar', 'baz'],
        ...          ['A', 1, '2'],
        ...          ['B', u'2', '3.4'],
        ...          [u'B', u'3', '7.8', True],
        ...          ['D', u'xyz', 9.0],
        ...          ['E', 42]]
        >>> sorted(etl.typeset(table, 'foo'))
        ['str']
        >>> sorted(etl.typeset(table, 'bar'))
        ['int', 'str']
        >>> sorted(etl.typeset(table, 'baz'))
        ['NoneType', 'float', 'str']

    The `field` argument can be a field name or index (starting from zero).

    )setr   addtype__name__
IndexError)tablefieldsv r   G/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/util/misc.pytypeset   s   r   c                 C   s(   t t| }t t|}|| || fS )a  
    Return the difference between the headers of the two tables as a pair of
    sets. E.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar', 'baz'],
        ...           ['a', 1, .3]]
        >>> table2 = [['baz', 'bar', 'quux'],
        ...           ['a', 1, .3]]
        >>> add, sub = etl.diffheaders(table1, table2)
        >>> add
        {'quux'}
        >>> sub
        {'foo'}

    )r   r   )t1t2t1ht2hr   r   r   diffheaders*   s   r   c                 C   s,   t t| |}t t||}|| || fS )a  
    Return the difference between the values under the given field in the two
    tables, e.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 3]]
        >>> table2 = [['bar', 'foo'],
        ...           [1, 'a'],
        ...           [3, 'c']]
        >>> add, sub = etl.diffvalues(table1, table2, 'foo')
        >>> add
        {'c'}
        >>> sub
        {'b'}

    )r   r   )r   r   ft1vt2vr   r   r   
diffvaluesD   s   r   c                    s    fddS )z
    Return a function to join sequences using `s` as the separator. Intended
    for use with :func:`petl.transform.conversions.convert`.

    c                    s     tt| S N)joinmapstr)lr   r   r   <lambda>g   s    zstrjoin.<locals>.<lambda>r   r"   r   r"   r   strjoin`   s   r$   Nc                    s    fddS )aG  
    Construct a function to return the nth word in a string. E.g.::

        >>> import petl as etl
        >>> s = 'foo bar'
        >>> f = etl.nthword(0)
        >>> f(s)
        'foo'
        >>> g = etl.nthword(1)
        >>> g(s)
        'bar'

    Intended for use with :func:`petl.transform.conversions.convert`.

    c                    s   |    S r   )splitr"   nsepr   r   r#   {   s    znthword.<locals>.<lambda>r   r&   r   r&   r   nthwordj   s   r)   c                     s,   | dd| dd  fdd}|S )z
    Return a function which accepts a row and returns the first non-missing
    value from the specified fields. Intended for use with
    :func:`petl.transform.basics.addfield`.

    missingNdefaultc                    s&   D ]}| | }|ur|  S q S r   r   )rowr   r   r+   fieldsr*   r   r   	_coalesce   s   zcoalesce.<locals>._coalesce)get)r.   kwargsr/   r   r-   r   coalesce~   s   r2   r   )
__future__r   r   r   petl.util.baser   r   r   r   r   r   r$   r)   r2   r   r   r   r   <module>   s     

