a
    *ñ»jF  ã                	   @  s¸  d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZ ddlmZ ddl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ddddœdd„ZdGdddddœdd„ZdHdddddœdd„ZdIdddddœdd„ZdJd dd!d"d"ddd#œd$d%„ZdKddd(d)œd*d+„Zd"d,d-œd.d/„ZdLd ddd0œd1d2„Z dMd4d"d5d"d"dd6œd7d8„Z!d9d9d:d;œd<d=„Z"G d>d?„ d?e#eef ƒZ$G d@dA„ dAƒZ%G dBdC„ dCe%ƒZ&dAdDœdEdF„Z'dS )Nz
Printing tools.
é    )Úannotations)ÚIterableÚMappingÚSequenceN)ÚAnyÚCallableÚTypeVarÚUnion)Úeast_asian_width)Ú
get_option)Úis_sequence)Úget_console_sizeÚ_KTÚ_VTÚintú	list[str]Ústr)ÚspaceÚlistsÚreturnc                   sÆ   |  dt¡‰|  dt¡}g }‡ ‡fdd„|dd… D ƒ}| ttt|d ƒƒ¡ ttt|ƒƒ}t|ƒD ]B\}}|||| dd�}	d	||  g|t|ƒ  |	 }	| |	¡ qft|Ž }
d
 dd„ |
D ƒ¡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   ú@E:\soccer\ml_env\Lib\site-packages\pandas/io/formats/printing.pyÚ
<listcomp>3   ó    zadjoin.<locals>.<listcomp>NéÿÿÿÿÚleft)Úmodeú Ú
c                 s  s   | ]}d   |¡V  qdS )Ú N)Újoin)r   Úlinesr   r   r   Ú	<genexpr><   r!   zadjoin.<locals>.<genexpr>)	ÚpopÚlenÚ_adj_justifyÚappendr   r   Ú	enumerateÚzipr(   )r   r   Úkwargsr   ZnewListsÚlengthsZmaxLenÚiÚlstÚnlZtoJoinr   r   r   Úadjoin   s    r6   ÚrightúIterable[str]©Ú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 | ]}|  ˆ ¡‘qS r   ©Úljustr   ©r;   r   r   r    D   r!   z _adj_justify.<locals>.<listcomp>Úcenterc                   s   g | ]}|  ˆ ¡‘qS r   ©r?   r   r>   r   r   r    F   r!   c                   s   g | ]}|  ˆ ¡‘qS r   ©Úrjustr   r>   r   r   r    H   r!   Nr   )r:   r;   r$   r   r>   r   r-   ?   s
    r-   r   z
int | None)ÚseqÚ	_nest_lvlÚmax_seq_itemsr   c                   sÀ   t | tƒrd}nt| dƒrdnd}ˆdu r4t| ƒ}nˆpFtdƒpFt| ƒ}t| ƒ‰‡ ‡‡‡fdd„tt|t| ƒƒƒD ƒ}d	 |¡}|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})FrE   c                   s*   g | ]"}t tˆƒˆ d  fdˆiˆ¤Ž‘qS )é   rE   )Úpprint_thingÚnext)r   r3   ©rD   ÚkwdsrE   Úsr   r   r    x   s   ÿz_pprint_seq.<locals>.<listcomp>ú, ú, ...rG   ú,)Úbody)Ú
isinstanceÚsetÚhasattrr,   r   ÚiterÚrangeÚminr(   ÚtupleÚformat)rC   rD   rE   rK   ÚfmtÚnitemsÚrrP   r   rJ   r   Ú_pprint_seqc   s     	

þ

r\   r   c           
   	   K  sÈ   d}g }d}|du rt | ƒ}n|p0tdƒp0t | ƒ}t|  ¡ ƒd|… D ]H\}}	| |jt||d fd|i|¤Žt|	|d fd|i|¤Žd�¡ qF|t | ƒk r²|jd |¡d	 d
�S |jd |¡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}FrE   NrG   )ÚkeyÚvalrM   rN   )Zthings)r,   r   ÚlistÚitemsr.   rX   rH   r(   )
rC   rD   rE   rK   rY   ÚpairsZpfmtrZ   ÚkÚvr   r   r   Ú_pprint_dict†   s     
þÿrd   Fr   úEscapeChars | NoneÚbool)ÚthingrD   Úescape_charsÚdefault_escapesÚquote_stringsrE   r   c                   s¨   |fddddœ‡ fdd„}t | dƒr,t| ƒS t| tƒrT|tdƒk rTt| |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
    r   re   r   )rg   rh   r   c                   sf   ddddœ}t |tƒr8ˆ r&| |¡ n|}t| ¡ ƒ}n|p>d}t| ƒ}|D ]}| ||| ¡}qL|S )Nz\tz\nz\r)ú	r&   úr   )rQ   ÚdictÚupdater_   Úkeysr   Úreplace)rg   rh   Ú	translateÚresultÚc©ri   r   r   Úas_escaped_stringÄ   s    
z'pprint_thing.<locals>.as_escaped_stringÚ__next__zdisplay.pprint_nest_depthT)rj   rE   ©rh   rj   rE   ú')rS   r   rQ   rm   r   rd   r   r\   )rg   rD   rh   ri   rj   rE   ru   rr   r   rt   r   rH   ¥   s,     ÿ
ÿÿûrH   úutf-8rp   Úbytes)ÚencodingÚerrorsr   c                 C  s   t | ƒ}| ||¡S ©N)rH   Úencode)Úobjectr{   r|   Úvaluer   r   r   Úpprint_thing_encodedî   s    r�   ÚNone)Úenabler   c                   sœ   dt jvrd S ddlm} |ƒ }|d u r,d S |jj}d}| r†||vrzddlm} ddlm	‰  G ‡ fdd„d|ƒ}|ƒ ||< d	|| _
n||v r˜d
|| _
d S )NÚIPythonr   )Úget_ipythonz!application/vnd.dataresource+json)ÚBaseFormatter©Ú
ObjectNamec                      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_methodrm   Ú_return_typer   r‡   r   r   ÚTableSchemaFormatter	  s   r�   TF)ÚsysÚmodulesr„   r…   Údisplay_formatterÚ
formattersÚIPython.core.formattersr†   Z	traitletsrˆ   Úenabled)rƒ   r…   Úipr‘   Úmimetyper†   r�   r   r‡   r   Úenable_data_resource_formatterõ   s"    

r–   )rg   rE   r   c                 C  s   t | dd|d�S )N)rk   rl   r&   Trw   ©rH   )rg   rE   r   r   r   Údefault_pprint  s    ür˜   Tr   z
str | None)Ú	formatterÚ
is_justifyÚnameÚindent_for_nameÚline_break_each_valuer   c                   sô  t ƒ \}}|du rtdƒpd}|du r0t| ƒj}|rbt|ƒ}dd|d  › �}	dd|d  › �}
nd}	d}
t| ƒ}|rˆd	dt|ƒ  }nd
}tdƒp–|}||k}tƒ ‰ dddddddœ‡ fdd„}dddœ‡ fdd„}d}|dkrðd|› �}�n |dk�r |�s ˆ| d ƒ}d|› d|› �}�nÐ|dk�rb|�sbˆ| d ƒ}ˆ| d ƒ}d|› d|› d|› �}�nŽ|dk�rŒg }‡fdd„| dd… D ƒ}nf||k�rÜt|d dƒ}‡fdd„| d|… D ƒ}‡fd d„| | d… D ƒ}ng }‡fd!d„| D ƒ}|�rr|�rt||ƒ\}}nd|�s<td |¡ƒ|k �r<td |¡ƒ|k �srt	||ƒ||ƒƒ‰‡fd"d„|D ƒ}‡fd#d„|D ƒ}|�rö|t|
ƒ }|d }d‰t
tdt|ƒd ƒƒD ]*}t||d$�}t|ƒ|k �r¦|‰ �qÒ�q¦‡fd%d„|D ƒ}‡fd&d„|D ƒ}d'}|
}|D ]&}|| d }||||||
ƒ\}}�q|�rH|| ¡ |
 d( 7 }|
}|dd… D ]&}|| d }||||||
ƒ\}}�qT||||d |d |
ƒ\}}||7 }d| 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 : bool
        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 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.

    Returns
    -------
    summary string
    Nzdisplay.widthéP   r&   r%   rG   é   z
 z,
 rO   zdisplay.max_seq_itemsr   r   ztuple[str, str])rL   Úliner€   Údisplay_widthÚnext_line_prefixr   c                   s@   ˆ   | ¡ ¡ˆ   | ¡ ¡ |kr0| | ¡ 7 } |}||7 }| |fS r}   )r,   Úrstrip)rL   r    r€   r¡   r¢   ©Úadjr   r   Ú_extend_line]  s
     z+format_object_summary.<locals>._extend_liner   )Úvaluesr   c                   s"   | rt ‡ fdd„| D ƒƒS dS d S )Nc                 3  s   | ]}ˆ   |¡V  qd S r}   ©r,   r   r¤   r   r   r*   h  r!   z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   ©r   )r§   r¤   r   r   Úbest_lenf  s    z'format_object_summary.<locals>.best_lenrM   r   z[]ú[ú]r"   c                   s   g | ]}ˆ |ƒ‘qS r   r   r   ©r™   r   r   r    {  r!   z)format_object_summary.<locals>.<listcomp>é
   c                   s   g | ]}ˆ |ƒ‘qS r   r   r   r­   r   r   r    ~  r!   c                   s   g | ]}ˆ |ƒ‘qS r   r   r   r­   r   r   r      r!   c                   s   g | ]}ˆ |ƒ‘qS r   r   r   r­   r   r   r    ‚  r!   c                   s   g | ]}|  ˆ ¡‘qS r   rA   r   ©Ú
max_lengthr   r   r    ‘  r!   c                   s   g | ]}|  ˆ ¡‘qS r   rA   r   r¯   r   r   r    ’  r!   ©rE   c                   s   g | ]}t |ˆ d �‘qS ©r±   ©r\   r   ©Ú	max_itemsr   r   r    £  r!   c                   s   g | ]}t |ˆ d �‘qS r²   r³   r   r´   r   r   r    ¤  r!   r'   z...)r   r   Útyper‰   r,   Úget_adjustmentrV   Ú_justifyr(   r   ÚreversedrU   r\   r£   )Úobjr™   rš   r›   rœ   r�   r¡   Ú_Zname_lenZspace1Zspace2ÚnÚseprE   Zis_truncatedr¦   rª   ÚcloseÚsummaryÚfirstÚlastÚheadÚtailZ	max_spacer€   Ú	num_itemsZpprinted_seqr    Z
head_valueÚwordZ	tail_itemr   )r¥   r™   rµ   r°   r   Úformat_object_summary  s¢    !

	

ÿþ

rÆ   zlist[Sequence[str]]z3tuple[list[tuple[str, ...]], list[tuple[str, ...]]])rÂ   rÃ   r   c                   sr   | | }dgt |d ƒ ‰ |D ]&}dd„ |D ƒ}dd„ tˆ |ƒD ƒ‰ q‡ 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    æ  r!   z_justify.<locals>.<listcomp>c                 S  s   g | ]\}}t ||ƒ‘qS r   r©   )r   r   Úyr   r   r   r    ç  r!   c                   s$   g | ]}t d d„ t|ˆ ƒD ƒƒ‘qS )c                 s  s   | ]\}}|  |¡V  qd S r}   rA   ©r   r   r;   r   r   r   r*   ë  r!   ú&_justify.<locals>.<listcomp>.<genexpr>©rW   r0   ©r   rC   r¯   r   r   r    ê  s   c                   s$   g | ]}t d d„ t|ˆ ƒD ƒƒ‘qS )c                 s  s   | ]\}}|  |¡V  qd S r}   rA   rÉ   r   r   r   r*   î  r!   rÊ   rË   rÌ   r¯   r   r   r    í  s   )r,   r0   )rÂ   rÃ   ÚcombinedZ	inner_seqÚlengthZhead_tuplesZtail_tuplesr   r¯   r   r¸   Ê  s    
ÿ
ÿr¸   c                   @  s   e Zd ZdZddœdd„ZdS )Ú
PrettyDictz.Dict extension to support abbreviated __repr__r   ©r   c                 C  s   t | ƒS r}   r—   ©Úselfr   r   r   Ú__repr__ö  s    zPrettyDict.__repr__N)r‰   rŠ   r‹   Ú__doc__rÓ   r   r   r   r   rÏ   ó  s   rÏ   c                   @  sP   e Zd Zddœdd„Zdddœdd	„Zddddddœdd„Zdddœdd„ZdS )Ú_TextAdjustmentr‚   rÐ   c                 C  s   t dƒ| _d S )Nzdisplay.encoding)r   r{   rÑ   r   r   r   Ú__init__û  s    z_TextAdjustment.__init__r   r   ©Útextr   c                 C  s   t |ƒS r}   r¨   ©rÒ   rØ   r   r   r   r,   þ  s    z_TextAdjustment.lenr7   r   r   r9   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 )zJ
        Perform ljust, center, rjust against string or list-like
        r#   c                   s   g | ]}|  ˆ ¡‘qS r   r<   r   r>   r   r   r      r!   z+_TextAdjustment.justify.<locals>.<listcomp>r?   c                   s   g | ]}|  ˆ ¡‘qS r   r@   r   r>   r   r   r      r!   c                   s   g | ]}|  ˆ ¡‘qS r   rA   r   r>   r   r   r    
  r!   Nr   ©rÒ   r:   r;   r$   r   r>   r   Újustify  s
    z_TextAdjustment.justify)r   r   c                 O  s    t |g|¢R | j| jdœ|¤ŽS )N)r   r   )r6   r,   rÛ   )rÒ   r   r   r1   r   r   r   r6     s    z_TextAdjustment.adjoinN)r7   )r‰   rŠ   r‹   rÖ   r,   rÛ   r6   r   r   r   r   rÕ   ú  s   rÕ   c                      sH   e Zd Zddœ‡ fdd„Zdddœdd	„Zddddddœdd„Z‡  ZS )Ú_EastAsianTextAdjustmentr‚   rÐ   c                   s6   t ƒ  ¡  tdƒrd| _nd| _ddddddœ| _d S )Nz!display.unicode.ambiguous_as_widerŸ   rG   )ZNaÚNÚWÚFÚH)ÚsuperrÖ   r   Úambiguous_widthÚ_EAW_MAPrÑ   ©Ú	__class__r   r   rÖ     s
    
z!_EastAsianTextAdjustment.__init__r   r   r×   c                   s(   t |tƒst|ƒS t‡ fdd„|D ƒƒS )zN
        Calculate display width considering unicode East Asian Width
        c                 3  s"   | ]}ˆ j  t|ƒˆ j¡V  qd S r}   )rã   Úgetr
   râ   )r   rs   rÑ   r   r   r*   $  s   z/_EastAsianTextAdjustment.len.<locals>.<genexpr>)rQ   r   r,   ÚsumrÙ   r   rÑ   r   r,     s
    
ÿz_EastAsianTextAdjustment.lenr7   r8   r   r9   c                   sX   ‡‡fdd„‰ |dkr(‡ fdd„|D ƒS |dkrB‡ fdd„|D ƒS ‡ fdd„|D ƒS d S )	Nc                   s   ˆ ˆ  | ¡ t | ƒ S r}   r¨   )Út)r;   rÒ   r   r   Ú_get_pad,  s    z2_EastAsianTextAdjustment.justify.<locals>._get_padr#   c                   s   g | ]}|  ˆ |ƒ¡‘qS r   r<   r   ©ré   r   r   r    0  r!   z4_EastAsianTextAdjustment.justify.<locals>.<listcomp>r?   c                   s   g | ]}|  ˆ |ƒ¡‘qS r   r@   r   rê   r   r   r    2  r!   c                   s   g | ]}|  ˆ |ƒ¡‘qS r   rA   r   rê   r   r   r    4  r!   r   rÚ   r   )ré   r;   rÒ   r   rÛ   (  s    z _EastAsianTextAdjustment.justify)r7   )r‰   rŠ   r‹   rÖ   r,   rÛ   Ú__classcell__r   r   rä   r   rÜ     s    ÿrÜ   rÐ   c                  C  s   t dƒ} | rtƒ S tƒ S d S )Nz display.unicode.east_asian_width)r   rÜ   rÕ   )Zuse_east_asian_widthr   r   r   r·   7  s    r·   )r7   )r   N)r   N)r   NFFN)ry   rp   )N)TNTF)(rÔ   Ú
__future__r   Úcollections.abcr   r   r   rŽ   Útypingr   r   r   r	   Úunicodedatar
   Zpandas._configr   Zpandas.core.dtypes.inferencer   Zpandas.io.formats.consoler   r   ZEscapeCharsr   r   r6   r-   r\   rd   rH   r�   r–   r˜   rÆ   r¸   rm   rÏ   rÕ   rÜ   r·   r   r   r   r   Ú<module>   sL    % ÿ$ ÿ!     úJ ÿ!    ú ,)'