B
    Y0dfC              	   @  s  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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dBdd	dd
dddZdCdd	dddddZdDdd	dddddZdEdd	dddddd d!d"ZdFddd%d&d'd(Zdd)d*d+d,ZdGdddd-d.d/ZdHd1dd2dddd3d4d5Zd6d6d7d8d9d:ZdId;dd<d=d>d?Z G d@dA dAeeef Z!dS )Jz
Printing tools.
    )annotationsN)	AnyCallableDictIterableMappingSequenceSizedTypeVarUnion)
get_option)is_sequence_KT_VTintz	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|}xPt|D ]D\}}	||	|| dd}
|
d	||  g|t|	   ||
 qlW t| }x|D ]}|d
	| qW 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   L/var/www/html/venv/lib/python3.7/site-packages/pandas/io/formats/printing.py
<listcomp>1   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   r   adjoin   s     
r3   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   )ljust)r   r   )r6   r   r   r   D   s    zjustify.<locals>.<listcomp>centerc               s   g | ]}|  qS r   )r8   )r   r   )r6   r   r   r   F   s    c               s   g | ]}|  qS r   )rjust)r   r   )r6   r   r   r   H   s    Nr   )r5   r6   r    r   )r6   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   r/   )r;   kwdsr<   sr   r   r   y   s   z_pprint_seq.<locals>.<listcomp>z, z, ...r>   ,)body)
isinstancesethasattrr%   r   iterrangeminr+   tupleformat)r:   r;   r<   rA   fmtnitemsrrD   r   )r;   rA   r<   rB   r   _pprint_seqc   s    	



rP   r   c       
   	   K  s   d}g }d}|dkrt | }n|p0tdp0t | }x`t|  d| D ]H\}}	||jt||d fd|i|t|	|d fd|i|d qHW |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<   Nr>   )keyvalz, z, ...)Zthings)r%   r   listitemsr'   rL   r?   r+   )
r:   r;   r<   rA   rM   pairsZpfmtrN   kvr   r   r   _pprint_dict   s    
$rX   Fr   z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   zEscapeChars | Noner   )rZ   r[   r   c               sj   dddd}t |tr8 r&|| n|}t| }n|p>d}t| }x|D ]}|||| }qNW |S )Nz\tz\nz\r)	r#   r   )rE   dictupdaterS   keysr   replace)rZ   r[   	translateresultc)r\   r   r   as_escaped_string   s    

z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)r]   r<   )r[   r]   r<   ')rG   r   rE   r`   r   rX   r   rP   )rZ   r;   r[   r\   r]   r<   rg   re   r   )r\   r   r?      s$     

r?   utf-8rc   bytes)encodingerrorsr   c             C  s   t | }|||S )N)r?   encode)objectrl   rm   valuer   r   r   pprint_thing_encoded   s    rq   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_methodr`   _return_typer   r   r   r   TableSchemaFormatter  s   r{   TF)	sysmodulesrt   ru   display_formatter
formattersIPython.core.formattersrv   enabled)rs   ru   ipr   mimetyperv   r{   r   r   r   enable_data_resource_formatter   s     

r   )rZ   r<   r   c             C  s   t | dd|dS )N)r^   r_   r#   T)r[   r]   r<   )r?   )rZ   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 }x<ttd	t|d	 D ]"t|d&}t||k rP qW fd'd|D }fd(d|D }d)}|}x:tt|D ]*| | d }||||||\}}qW |rj|| | d* 7 }|}x>tt|d	 D ]*| | d }||||||\}}q|W ||||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!   r>      z
 z,
 rC   zdisplay.max_seq_itemsr   r   ztuple[str, str])rB   linerp   display_widthnext_line_prefixr   c               s@     |   |  |kr0| | 7 } |}||7 }| |fS )N)r%   rstrip)rB   r   rp   r   r   )adjr   r   _extend_lineb  s
     z+format_object_summary.<locals>._extend_linez	list[str])valuesr   c               s"   | rt  fdd| D S dS d S )Nc             3  s   | ]}  |V  qd S )N)r%   )r   r   )r   r   r   	<genexpr>n  s    z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   )r   )r   )r   r   r   best_lenl  s    z'format_object_summary.<locals>.best_lenz, z[][]r   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 | ]} |qS r   r   )r   r   )r   r   r   r     s    c               s   g | ]}|  qS r   )r9   )r   r   )
max_lengthr   r   r     s    c               s   g | ]}|  qS r   )r9   )r   r   )r   r   r   r     s    )r<   c               s   g | ]}t | d qS ))r<   )rP   )r   r   )	max_itemsr   r   r     s    c               s   g | ]}t | d qS ))r<   )rP   )r   r   )r   r   r   r     s    r"   z...)Zpandas.io.formats.consoler   Zpandas.io.formats.formatr   r   typerw   r%   rJ   _justifyr+   r   reversedrI   rP   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_spacerp   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               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   | ]\}}| |V  qd S )N)r9   )r   r   r6   r   r   r   r     s    z&_justify.<locals>.<listcomp>.<genexpr>)rK   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 )N)r9   )r   r   r6   r   r   r   r     s    z&_justify.<locals>.<listcomp>.<genexpr>)rK   r*   )r   r:   )r   r   r   r     s    )r%   r*   )r   r   combinedZ	inner_seqlengthr   )r   r   r     s    
r   r	   zlist[tuple[str, str | int]])r   include_dtyper   c             C  s   g }t | dr*|r*|dd| j df t| dddk	rP|dt| jf n.t| dddk	r~t| jr~|dt| jf tdpt	| }t	| |kr|dt	| f |S )a8  
    Return a list of tuples of the (attr, formatted_value)
    for common attrs, including dtype, name, length

    Parameters
    ----------
    obj : object
        Must be sized.
    include_dtype : bool
        If False, dtype won't be in the returned list

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

    dtyperi   r   Nnameszdisplay.max_seq_itemsr   )
rG   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ddddZdS )
PrettyDictz.Dict extension to support abbreviated __repr__r   )r   c             C  s   t | S )N)r?   )selfr   r   r   __repr__%  s    zPrettyDict.__repr__N)rw   rx   ry   __doc__r   r   r   r   r   r   "  s   r   )r4   )r   N)r   N)r   NFFN)rj   rc   )N)TNTF)T)"r   
__future__r   r|   typingr   r   r   r   r   r   r	   r
   r   Zpandas._configr   Zpandas.core.dtypes.inferencer   r   ZEscapeCharsr   r   r3   r&   rP   rX   r?   rq   r   r   r   r   r   r   r   r   r   r   <module>   s8   ,#%#     D!    +.%