U
    +ifP>                  	   @  sp  d Z ddlmZ ddlZddl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d	d
ddddZd=dd	dd
dddZd>dd	dddddZd?dd	dddddZd@dd	dddddd d!d"ZdAddd%d&d'd(Zdd)d*d+d,ZdBdddd-d.d/ZdCd1dd2dddd3d4d5Zd6d6d7d8d9d:ZG d;d< d<eeef ZdS )Dz
Printing tools.
    )annotationsN)AnyCallableDictIterableMappingSequenceTypeVarUnion)
get_option)is_sequence_KT_VTint	list[str]str)spacelistsreturnc                   s   | dt| dt}g }g } fdd|dd D }|ttt|d  ttt|}t|D ]D\}}	||	|| dd}
|
d	||  g|t|	   ||
 qjt| }|D ]}|d
	| qd	|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   M/home/mars/bis/venv/lib/python3.8/site-packages/pandas/io/formats/printing.py
<listcomp>0   s     zadjoin.<locals>.<listcomp>Nleft)mode  
)
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   adjoin   s     r5   rightz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   r8   r   r   r   C   s     zjustify.<locals>.<listcomp>centerc                   s   g | ]}|  qS r   )r;   r   r:   r   r   r   E   s     c                   s   g | ]}|  qS r   rjustr   r:   r   r   r   G   s     Nr   )r7   r8   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kr4t| }npFtdpFt| }t|  fddtt|t| D }d	|}|t| k r|d
7 }nt | t	rt| 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@   )pprint_thingnext)r   r1   r?   kwdsr@   sr   r   r   w   s   z_pprint_seq.<locals>.<listcomp>, , ...rB   ,)body)
isinstancesethasattrr'   r   iterrangeminr-   tupleformat)r>   r?   r@   rF   fmtnitemsrrK   r   rE   r   _pprint_seqb   s     	



rW   r   c           
   	   K  s   d}g }d}|dk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}Fr@   NrB   )keyvalrH   rI   )Zthings)r'   r   listitemsr)   rS   rC   r-   )
r>   r?   r@   rF   rT   pairsZpfmtrU   kvr   r   r   _pprint_dict   s     
r_   Fr   EscapeChars | Nonebool)thingr?   escape_charsdefault_escapesquote_stringsr@   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|rd||  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   r`   r   )rb   rc   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   )rL   dictupdaterZ   keysr   replace)rb   rc   	translateresultcrd   r   r   as_escaped_string   s    
z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)re   r@   rc   re   r@   ')rN   r   rL   rh   r   r_   r   rW   )rb   r?   rc   rd   re   r@   rp   rm   r   ro   r   rC      s2     
   rC   utf-8rk   bytes)encodingerrorsr   c                 C  s   t | }|||S N)rC   encode)objectrv   rw   valuer   r   r   pprint_thing_encoded   s    r|   None)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rd	|| _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_methodrh   _return_typer   r   r   r   TableSchemaFormatter  s   r   TF)	sysmodulesr   r   display_formatter
formattersIPython.core.formattersr   enabled)r~   r   ipr   mimetyper   r   r   r   r   enable_data_resource_formatter   s     

r   )rb   r@   r   c                 C  s   t | dd|dS )N)rf   rg   r%   Trr   rC   )rb   r@   r   r   r   default_pprint  s    r   Tr   z
str | None)	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| }|rddt|  }nd}tdp|}||k}|  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r||s|| d }| d }d| d| d| }n|d	krg }fdd| dd D }nf||krt|d
 d }fd!d| d| D }fd"d| | d D }ng }fd#d| D }|r|r(t	||\}}nd|sVtd
||k rVtd
||k st||||fd$d|D }fd%d|D }|r|t| }|d }ttd	t|d	 D ]&t|d&}t||k r qqfd'd|D }fd(d|D }d)}|}tt|D ]*| | d }||||||\}}q|rf|| | d* 7 }|}tt|d	 D ]*| | d }||||||\}}qv||||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.

        .. versionadded:: 0.25.0

    Returns
    -------
    summary string
    r   )get_console_size)get_adjustmentNzdisplay.widthP   r%   r#   rB      z
 z,
 rJ   zdisplay.max_seq_itemsr   r   ztuple[str, str])rG   liner{   display_widthnext_line_prefixr   c                   s@     |   |  |kr0| | 7 } |}||7 }| |fS rx   )r'   rstrip)rG   r   r{   r   r   adjr   r   _extend_linea  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 rx   r'   r   r   r   r   	<genexpr>m  s     z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   r   )r   r   r   r   best_lenk  s    z'format_object_summary.<locals>.best_lenrH   z[][]r    c                   s   g | ]} |qS 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     s     c                   s   g | ]} |qS r   r   r   r   r   r   r     s     c                   s   g | ]} |qS r   r   r   r   r   r   r     s     c                   s   g | ]}|  qS r   r<   r   
max_lengthr   r   r     s     c                   s   g | ]}|  qS r   r<   r   r   r   r   r     s     r@   c                   s   g | ]}t | d qS r   rW   r   	max_itemsr   r   r     s     c                   s   g | ]}t | d qS r   r   r   r   r   r   r     s     r$   z...)Zpandas.io.formats.consoler   Zpandas.io.formats.formatr   r   typer   r'   rQ   _justifyr-   r   reversedrP   rW   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_spacer{   Zpprinted_seqr   wordr   )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     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   | ]\}}| |V  qd S rx   r<   r   r   r8   r   r   r   r     s     &_justify.<locals>.<listcomp>.<genexpr>rR   r,   r   r>   r   r   r   r     s    c                   s$   g | ]}t d d t| D qS )c                 s  s   | ]\}}| |V  qd S rx   r<   r   r   r   r   r     s     r   r   r   r   r   r   r     s    )r'   r,   )r   r   combinedZ	inner_seqlengthr   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 rx   r   )selfr   r   r   __repr__  s    zPrettyDict.__repr__N)r   r   r   __doc__r   r   r   r   r   r     s   r   )r6   )r   N)r   N)r   NFFN)rt   rk   )N)TNTF) r   
__future__r   r   typingr   r   r   r   r   r   r	   r
   Zpandas._configr   Zpandas.core.dtypes.inferencer   r   ZEscapeCharsr   r   r5   r(   rW   r_   rC   r|   r   r   r   r   r   r   r   r   r   <module>   sF   (#%   $   !     J   !     1-