3
®yb¸B  ã            	   @   sì  d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ eeeef ee f ZedƒZedƒZeee edœd	d
„Zd0ee eeee dœdd„Zd1e
ee	e edœdd„Zd2eee	e edœdd„Zd3eee	e eee	e edœdd„Zd4eeedœdd„Zeddœdd„Zd5ee	e ed œd!d"„Z d6eee	e eeed$œd%d&„Z!ee
e  ee
e  eeeed'f  eeed'f  f d(œd)d*„Z"d7e
eeeeeeef f  d+œd,d-„Z#G d.d/„ d/eeef ƒZ$dS )8z
Printing tools.
é    N)ÚAnyÚCallableÚDictÚIterableÚListÚMappingÚOptionalÚSequenceÚTupleÚTypeVarÚUnion)Ú
get_option)Úis_sequenceÚ_KTÚ_VT)ÚspaceÚlistsÚreturnc                sä   |j dtƒ‰|j dtƒ}g }g }‡ ‡fdd„|dd… D ƒ}|jttt|d ƒƒƒ ttt|ƒƒ}xPt|ƒD ]D\}}	||	|| dd�}
|
jd	||  g|t|	ƒ  ƒ |j|
ƒ qlW t|Ž }x|D ]}|jd
j	|ƒƒ qÂW dj	|ƒS )a»  
    Glues together two sets of strings using the amount of space requested.
    The idea is to prettify.

    ----------
    space : int
        number of spaces for padding
    lists : str
        list of str which being joined
    strlen : callable
        function used to calculate the length of each str. Needed for unicode
        handling.
    justfunc : callable
        function used to justify str. Needed for unicode handling.
    ÚstrlenÚjustfuncc                s   g | ]}t tˆ|ƒƒˆ  ‘qS © )ÚmaxÚmap)Ú.0Úx)r   r   r   ú>/tmp/pip-install-4cy230dp/pandas/pandas/io/formats/printing.pyú
<listcomp>2   s    zadjoin.<locals>.<listcomp>Né   Úleft)Úmodeú Ú Ú
éÿÿÿÿr#   )
ÚpopÚlenÚjustifyÚappendr   r   Ú	enumerateÚextendÚzipÚjoin)r   r   Úkwargsr   Z	out_linesZnewListsÚlengthsÚmaxLenÚiÚlstÚnlZtoJoinÚlinesr   )r   r   r   Úadjoin   s     
r3   Úright)ÚtextsÚmax_lenr   r   c                sJ   |dkr‡ fdd„| D ƒS |dkr4‡ fdd„| D ƒS ‡ fdd„| D ƒS dS )zB
    Perform ljust, center, rjust against string or list-like
    r   c                s   g | ]}|j ˆ ƒ‘qS r   )Úljust)r   r   )r6   r   r   r   E   s    zjustify.<locals>.<listcomp>Úcenterc                s   g | ]}|j ˆ ƒ‘qS r   )r8   )r   r   )r6   r   r   r   G   s    c                s   g | ]}|j ˆ ƒ‘qS r   )Úrjust)r   r   )r6   r   r   r   I   s    Nr   )r5   r6   r   r   )r6   r   r&   @   s
    r&   )ÚseqÚ	_nest_lvlÚmax_seq_itemsr   c                sÀ   t | tƒrd}nt| dƒrdnd}ˆdkr4t| ƒ}nˆpFtdƒpFt| ƒ}t| ƒ‰‡ ‡‡‡fdd„tt|t| ƒƒƒD ƒ}d	j|ƒ}|t| ƒk r–|d
7 }nt | t	ƒr´t| ƒdkr´|d7 }|j
|d�S )z¶
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.

    bounds length of printed sequence, depending on options
    z
{{{body}}}Ú__setitem__z[{body}]z({body})Fr<   c                s*   g | ]"}t tˆƒˆ d  fdˆiˆ—Ž‘qS )r   r<   )Úpprint_thingÚnext)r   r/   )r;   Úkwdsr<   Úsr   r   r   z   s   z_pprint_seq.<locals>.<listcomp>z, z, ...r   ú,)Úbody)Ú
isinstanceÚsetÚhasattrr%   r   ÚiterÚrangeÚminr+   ÚtupleÚformat)r:   r;   r<   r@   ÚfmtÚnitemsÚrrC   r   )r;   r@   r<   rA   r   Ú_pprint_seqd   s    	



rO   c       
      K   sÌ   d}g }d}|dkrt | ƒ}n|p0tdƒp0t | ƒ}x`t| jƒ ƒd|… D ]H\}}	|j|jt||d fd|i|—Žt|	|d fd|i|—Žd�ƒ qHW |t | ƒk r¶|jdj|ƒd	 d
�S |jdj|ƒd
�S dS )zy
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.
    z{{{things}}}z{key}: {val}Fr<   Nr   )ÚkeyÚvalz, z, ...)Zthings)r%   r   ÚlistÚitemsr'   rK   r>   r+   )
r:   r;   r<   r@   rL   ÚpairsZpfmtrM   ÚkÚvr   r   r   Ú_pprint_dict‡   s    
$rW   F)Úthingr;   Úescape_charsÚdefault_escapesÚquote_stringsr<   r   c                s¬   |ft tt tdœ‡ fdd„}t| dƒr0t| ƒS t| tƒrX|tdƒk rXt| |d|d�}nPt	| ƒr€|tdƒk r€t
| ||||d�}n(t| tƒr |r d	|| ƒ› d	�}n|| ƒ}|S )
a  
    This function is the sanctioned way of converting objects
    to a string representation and properly handles nested sequences.

    Parameters
    ----------
    thing : anything to be formatted
    _nest_lvl : internal use only. pprint_thing() is mutually-recursive
        with pprint_sequence, this argument is used to keep track of the
        current nesting level, and limit it.
    escape_chars : list or dict, optional
        Characters to escape. If a dict is passed the values are the
        replacements
    default_escapes : bool, default False
        Whether the input escape characters replaces or adds to the defaults
    max_seq_items : int or None, default None
        Pass through to other pretty printers to limit sequence printing

    Returns
    -------
    str
    )rX   rY   r   c                sl   ddddœ}t |tƒr8ˆ r&|j|ƒ n|}t|jƒ ƒ}n
|p@tƒ }t| ƒ}x|D ]}|j||| ƒ}qPW |S )Nz\tz\nz\r)ú	r"   ú)rD   ÚdictÚupdaterR   ÚkeysrJ   ÚstrÚreplace)rX   rY   Ú	translateÚresultÚc)rZ   r   r   Úas_escaped_stringÅ   s    


z'pprint_thing.<locals>.as_escaped_stringÚ__next__zdisplay.pprint_nest_depthT)r[   r<   )rY   r[   r<   ú')r   r   ÚEscapeCharsra   rF   rD   r^   r   rW   r   rO   )rX   r;   rY   rZ   r[   r<   rf   rd   r   )rZ   r   r>   ¦   s&     

r>   úutf-8rb   )ÚencodingÚerrorsr   c             C   s   t | ƒ}|j||ƒS )N)r>   Úencode)Úobjectrk   rl   Úvaluer   r   r   Úpprint_thing_encodedï   s    rp   )Úenabler   c             C   sŒ   dt jkrd S ddlm} |ƒ }|d kr,d S |jj}d}| rv||krjddlm} G dd„ d|ƒ}|ƒ ||< d|| _n||krˆd	|| _d S )
NÚIPythonr   )Úget_ipythonz!application/vnd.dataresource+json)ÚBaseFormatterc               @   s   e Zd ZdZefZdS )z=_enable_data_resource_formatter.<locals>.TableSchemaFormatterZ_repr_data_resource_N)Ú__name__Ú
__module__Ú__qualname__Zprint_methodr^   Z_return_typer   r   r   r   ÚTableSchemaFormatter	  s   rx   TF)	ÚsysÚmodulesrr   rs   Zdisplay_formatterÚ
formattersZIPython.core.formattersrt   Zenabled)rq   rs   Úipr{   Úmimetypert   rx   r   r   r   Ú_enable_data_resource_formatterö   s     

r~   )rX   r<   r   c             C   s   t | dd|d�S )Nr\   r]   r"   T)rY   r[   r<   )r\   r]   r"   )r>   )rX   r<   r   r   r   Údefault_pprint  s
    r   T)Ú	formatterÚ
is_justifyÚnameÚindent_for_nameÚline_break_each_valuer   c                s
  ddl m} ddlm} |ƒ \}}	|dkr6tdƒp4d}|dkrHt| ƒj}|rzt|ƒ}
dd|
d	  › �}dd|
d
  › �}nd}d}t| ƒ}|r ddt|ƒ  }nd}tdƒp®|}||k}|ƒ ‰ tttt	tt
ttf dœ‡ fdd„}tt t	dœ‡ fdd„}d}|dk�rd|› �}�nð|d	k�rH| �rHˆ| d ƒ}d|› d|› �}�n¾|d
k�rŒ| �rŒˆ| d ƒ}ˆ| d% ƒ}d|› d|› d|› �}�nz||k�rÜt|d
 dƒ}‡fdd„| d|… D ƒ}‡fdd„| | d… D ƒ}ng }‡fdd„| D ƒ}|�rt|�rt||ƒ\}}nf|�s>tdj|ƒƒ|k �o8tdj|ƒƒ|k  �rtt||ƒ||ƒƒ‰‡fdd„|D ƒ}‡fdd„|D ƒ}|�rð|t|ƒ }|d }x<ttd	t|ƒd	 ƒƒD ]"‰t|ˆd �}t|ƒ|k �r¦P �q¦W ‡fd!d„|D ƒ}‡fd"d„|D ƒ}d#}|}x:tt|ƒƒD ]*‰|ˆ | d }||||||ƒ\}}�qW |�rR||jƒ | d$ 7 }|}x>tt|ƒd	 ƒD ]*‰|ˆ | d }||||||ƒ\}}�qdW ||||d& |d
 |ƒ\}}||7 }d|jdƒ }||7 }t|ƒ|k�sà|�rê||7 }n|d7 }d|t|ƒd…  }|S )'a  
    Return the formatted obj as a unicode string

    Parameters
    ----------
    obj : object
        must be iterable and support __getitem__
    formatter : callable
        string formatter for an element
    is_justify : boolean
        should justify the display
    name : name, optional
        defaults to the class name of the obj
    indent_for_name : bool, default True
        Whether subsequent lines should be be indented to
        align with the name.
    line_break_each_value : bool, default False
        If True, inserts a line break for each value of ``obj``.
        If False, only break lines when the a line of values gets wider
        than the display width.

        .. versionadded:: 0.25.0

    Returns
    -------
    summary string
    r   )Úget_console_size)Ú_get_adjustmentNzdisplay.widthéP   r"   r    r   é   z
 z,
 rB   zdisplay.max_seq_items)rA   Úlinero   Údisplay_widthÚnext_line_prefixr   c                s@   ˆ j |jƒ ƒˆ j |jƒ ƒ |kr0| |jƒ 7 } |}||7 }| |fS )N)r%   Úrstrip)rA   r‰   ro   rŠ   r‹   )Úadjr   r   Ú_extend_linec  s
     z+format_object_summary.<locals>._extend_line)Úvaluesr   c                s"   | rt ‡ fdd„| D ƒƒS dS d S )Nc             3   s   | ]}ˆ j |ƒV  qd S )N)r%   )r   r   )r�   r   r   ú	<genexpr>o  s    z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   )r   )r�   )r�   r   r   Úbest_lenm  s    z'format_object_summary.<locals>.best_lenz, z[]ú[ú]é
   c                s   g | ]}ˆ |ƒ‘qS r   r   )r   r   )r€   r   r   r   ‚  s    z)format_object_summary.<locals>.<listcomp>c                s   g | ]}ˆ |ƒ‘qS r   r   )r   r   )r€   r   r   r   ƒ  s    c                s   g | ]}ˆ |ƒ‘qS r   r   )r   r   )r€   r   r   r   †  s    c                s   g | ]}|j ˆ ƒ‘qS r   )r9   )r   r   )Ú
max_lengthr   r   r   •  s    c                s   g | ]}|j ˆ ƒ‘qS r   )r9   )r   r   )r•   r   r   r   –  s    )r<   c                s   g | ]}t |ˆ d �‘qS ))r<   )rO   )r   r   )Ú	max_itemsr   r   r   ¥  s    c                s   g | ]}t |ˆ d �‘qS ))r<   )rO   )r   r   )r–   r   r   r   ¦  s    r!   z...r#   r#   )Zpandas.io.formats.consoler…   Zpandas.io.formats.formatr†   r   Útyperu   r%   ra   Úintr
   r   rI   Ú_justifyr+   r   ÚreversedrH   rO   rŒ   )Úobjr€   r�   r‚   rƒ   r„   r…   r†   rŠ   Ú_Zname_lenZspace1Zspace2ÚnÚsepr<   Zis_truncatedrŽ   r‘   ÚcloseÚsummaryÚfirstÚlastÚheadÚtailZ	max_spacero   Zpprinted_seqr‰   Úwordr   )r�   r€   r–   r•   r   Úformat_object_summary   sš    #





r¦   .)r£   r¤   r   c                sv   | | }dgt |d ƒ ‰ x.|D ]&}dd„ |D ƒ}dd„ tˆ |ƒD ƒ‰ q W ‡ fdd„| D ƒ} ‡ fdd„|D ƒ}| |fS )aà  
    Justify items in head and tail, so they are right-aligned when stacked.

    Parameters
    ----------
    head : list-like of list-likes of strings
    tail : list-like of list-likes of strings

    Returns
    -------
    tuple of list of tuples of strings
        Same as head and tail, but items are right aligned when stacked
        vertically.

    Examples
    --------
    >>> _justify([['a', 'b']], [['abc', 'abcd']])
    ([('  a', '   b')], [('abc', 'abcd')])
    r   c             S   s   g | ]}t |ƒ‘qS r   )r%   )r   Úitemr   r   r   r   è  s    z_justify.<locals>.<listcomp>c             S   s   g | ]\}}t ||ƒ‘qS r   )r   )r   r   Úyr   r   r   r   é  s    c                s$   g | ]}t d d„ t|ˆ ƒD ƒƒ‘qS )c             s   s   | ]\}}|j |ƒV  qd S )N)r9   )r   r   r6   r   r   r   r�   í  s    z&_justify.<locals>.<listcomp>.<genexpr>)rJ   r*   )r   r:   )r•   r   r   r   í  s    c                s$   g | ]}t d d„ t|ˆ ƒD ƒƒ‘qS )c             s   s   | ]\}}|j |ƒV  qd S )N)r9   )r   r   r6   r   r   r   r�   ð  s    z&_justify.<locals>.<listcomp>.<genexpr>)rJ   r*   )r   r:   )r•   r   r   r   ð  s    )r%   r*   )r£   r¤   ZcombinedZ	inner_seqÚlengthr   )r•   r   r™   Ì  s    
r™   )r›   Úinclude_dtyper   c             C   s°   g }t | dƒr*|r*|jdd| j› d�fƒ t| ddƒdk	rP|jdt| jƒfƒ n.t| ddƒdk	r~t| jƒr~|jdt| jƒfƒ tdƒpŒt	| ƒ}t	| ƒ|kr¬|jdt	| ƒfƒ |S )a:  
    Return a list of tuples of the (attr, formatted_value)
    for common attrs, including dtype, name, length

    Parameters
    ----------
    obj : object
        must be iterable
    include_dtype : bool
        If False, dtype won't be in the returned list

    Returns
    -------
    list of 2-tuple

    Údtyperh   r‚   NÚnameszdisplay.max_seq_itemsr©   )
rF   r'   r«   Úgetattrr   r‚   Úanyr¬   r   r%   )r›   rª   Úattrsr<   r   r   r   Úformat_object_attrsù  s    r°   c               @   s   e Zd ZdZedœdd„ZdS )Ú
PrettyDictz.Dict extension to support abbreviated __repr__)r   c             C   s   t | ƒS )N)r>   )Úselfr   r   r   Ú__repr__   s    zPrettyDict.__repr__N)ru   rv   rw   Ú__doc__ra   r³   r   r   r   r   r±     s   r±   )r4   )r   N)r   N)r   NFFN)rj   rb   )N)TNTF)T)%r´   ry   Útypingr   r   r   r   r   r   r   r	   r
   r   r   Zpandas._configr   Zpandas.core.dtypes.inferencer   ra   ri   r   r   r˜   r3   r&   rO   rW   Úboolr>   Úbytesrp   r~   r   r¦   r™   r°   r±   r   r   r   r   Ú<module>   sD   4#%"    C!    '.,""