o
    Û­jF  ã                   @  sj  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dTdd„ZdUdVdd„Z	dWdXd d!„Z	dWdYd#d$„Z			%	%	dZd[d-d.„Z	0d\d]d4d5„Zd^d8d9„Zd_d`d:d;„Z 	<		<	%dadbdDdE„Z!dcdJdK„Z"G dLdM„ dMe#eef ƒZ$G dNdO„ dOƒZ%G dPdQ„ dQe%ƒZ&dddRdS„Z'dS )ez
Printing tools.
é    )Úannotations)ÚIterableÚMappingÚSequenceN)ÚAnyÚCallableÚTypeVarÚUnion)Úeast_asian_width)Ú
get_option)Úis_sequence)Úget_console_sizeÚ_KTÚ_VTÚspaceÚintÚlistsú	list[str]ÚreturnÚstrc                   sÆ   |  dt¡‰|  dt¡}g }‡ ‡fdd„|dd… D ƒ}| ttt|d ƒƒ¡ ttt|ƒƒ}t|ƒD ]!\}}|||| dd�}	d	||  g|t|ƒ  |	 }	| |	¡ q3t|Ž }
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   úW/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/io/formats/printing.pyÚ
<listcomp>3   s    zadjoin.<locals>.<listcomp>NéÿÿÿÿÚleft)Úmodeú Ú
c                 s  s   � | ]}d   |¡V  qdS )Ú N)Újoin)r   Úlinesr   r   r   Ú	<genexpr><   ó   € zadjoin.<locals>.<genexpr>)	ÚpopÚlenÚ_adj_justifyÚappendr   r   Ú	enumerateÚzipr'   )r   r   Úkwargsr   ÚnewListsÚlengthsÚmaxLenÚiÚlstÚnlÚtoJoinr   r   r   Úadjoin   s   r9   ÚrightÚtextsúIterable[str]Úmax_lenr#   c                   sF   |dkr‡ fdd„| D ƒS |dkr‡ fdd„| D ƒS ‡ fdd„| D ƒS )zB
    Perform ljust, center, rjust against string or list-like
    r"   c                   ó   g | ]}|  ˆ ¡‘qS r   ©Úljustr   ©r=   r   r   r    D   ó    z _adj_justify.<locals>.<listcomp>Úcenterc                   r>   r   ©rC   r   rA   r   r   r    F   rB   c                   r>   r   ©Úrjustr   rA   r   r   r    H   rB   r   )r;   r=   r#   r   rA   r   r-   ?   ó
   r-   Úseqr   Ú	_nest_lvlÚmax_seq_itemsú
int | Nonec                   sÀ   t | tƒrd}n	t| dƒrdnd}ˆdu rt| ƒ}n
ˆp#tdƒp#t| ƒ}t| ƒ‰‡ ‡‡‡fdd„tt|t| ƒƒƒD ƒ}d	 |¡}|t| ƒk rK|d
7 }nt | t	ƒrZt| ƒdkrZ|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})FrJ   c                   s*   g | ]}t tˆƒˆ d  fdˆiˆ¤Ž‘qS )é   rJ   )Úpprint_thingÚnext)r   r5   ©rI   ÚkwdsrJ   Úsr   r   r    x   s    ÿÿz_pprint_seq.<locals>.<listcomp>ú, ú, ...rM   ú,)Úbody)Ú
isinstanceÚsetÚhasattrr,   r   ÚiterÚrangeÚminr'   ÚtupleÚformat)rH   rI   rJ   rQ   ÚfmtÚnitemsÚrrV   r   rP   r   Ú_pprint_seqc   s    
	
þ

rb   r   c           
   	   K  sÄ   d}g }d}|du rt | ƒ}n
|ptdƒpt | ƒ}t|  ¡ ƒd|… D ]$\}}	| |jt||d fd|i|¤Žt|	|d fd|i|¤Žd�¡ q#|t | ƒk rY|jd |¡d	 d
�S |jd |¡d
�S )zy
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.
    z{{{things}}}z{key}: {val}FrJ   NrM   )ÚkeyÚvalrS   rT   )Úthings)r,   r   ÚlistÚitemsr.   r^   rN   r'   )
rH   rI   rJ   rQ   r_   ÚpairsÚpfmtr`   ÚkÚvr   r   r   Ú_pprint_dict†   s    
þÿrl   FÚthingr   Úescape_charsúEscapeChars | NoneÚdefault_escapesÚboolÚquote_stringsc                   s¦   |fd‡ fdd„}t | d	ƒrt| ƒS t| tƒr'|td
ƒk r't| |d|d�}|S t| ƒr<|td
ƒk r<t| ||||d�}|S t| tƒrM|rMd|| ƒ› d�}|S || ƒ}|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
    rm   r   rn   ro   r   r   c                   sf   ddddœ}t |tƒrˆ r| |¡ n|}t| ¡ ƒ}n|pd}t| ƒ}|D ]
}| ||| ¡}q&|S )Nz\tz\nz\r)ú	r%   úr   )rW   ÚdictÚupdaterf   Úkeysr   Úreplace)rm   rn   Ú	translateÚresultÚc©rp   r   r   Úas_escaped_stringÄ   s   
z'pprint_thing.<locals>.as_escaped_stringÚ__next__zdisplay.pprint_nest_depthT)rr   rJ   ©rn   rr   rJ   ú'N)rm   r   rn   ro   r   r   )rY   r   rW   ru   r   rl   r   rb   )rm   rI   rn   rp   rr   rJ   r}   rz   r   r|   r   rN   ¥   s2    ÿ
ÿÿóûûþrN   úutf-8rx   ÚencodingÚerrorsÚbytesc                 C  s   t | ƒ}| ||¡S ©N)rN   Úencode)Úobjectr‚   rƒ   Úvaluer   r   r   Úpprint_thing_encodedî   s   r‰   ÚenableÚNonec                   s¢   dt jvrd S ddlm} |ƒ }|d u rd S |jj}d}| rD||vr=ddlm} ddlm	‰  G ‡ fdd„d|ƒ}|ƒ ||< d	|| _
d S ||v rOd
|| _
d S 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>.TableSchemaFormatterÚ_repr_data_resource_N)Ú__name__Ú
__module__Ú__qualname__Úprint_methodru   Ú_return_typer   r�   r   r   ÚTableSchemaFormatter	  s    
r—   TF)ÚsysÚmodulesrŒ   r�   Údisplay_formatterÚ
formattersÚIPython.core.formattersrŽ   Ú	traitletsr�   Úenabled)rŠ   r�   Úipr›   ÚmimetyperŽ   r—   r   r�   r   Úenable_data_resource_formatterõ   s$   

ÿr¡   c                 C  s   t | dd|d�S )N)rs   rt   r%   Tr   ©rN   )rm   rJ   r   r   r   Údefault_pprint  s   ür£   TÚ	formatterr   Ú
is_justifyÚnameú
str | NoneÚindent_for_nameÚline_break_each_valuec                   sÐ  t ƒ \}}|du rtdƒpd}|du rt| ƒj}|r1t|ƒ}dd|d  › �}	dd|d  › �}
nd}	d}
t| ƒ}|rDd	dt|ƒ  }nd
}tdƒpK|}||k}tƒ ‰ d.‡ fdd„}d/‡ fdd„}d}|dkrnd|› �}|S |dkr„|s„ˆ| d ƒ}d|› d|› �}|S |dkr£|s£ˆ| d ƒ}ˆ| d  ƒ}d|› d|› d|› �}|S |dkr·g }‡fd!d"„| d d… D ƒ}n2||krÞt|d d#ƒ}‡fd$d"„| d|… D ƒ}‡fd%d"„| | d… D ƒ}ng }‡fd&d"„| D ƒ}|�r(|röt||ƒ\}}n2|�std |¡ƒ|k �rtd |¡ƒ|k �s(t	||ƒ||ƒƒ‰‡fd'd"„|D ƒ}‡fd(d"„|D ƒ}|�ri|t|
ƒ }|d }d‰t
tdt|ƒd ƒƒD ]}t||d)�}t|ƒ|k �rU|‰ n�qB‡fd*d"„|D ƒ}‡fd+d"„|D ƒ}d,}|
}|D ]}|| d }||||||
ƒ\}}�qo|�r’|| ¡ |
 d- 7 }|
}|dd … D ]}|| d }||||||
ƒ\}}�q˜||||d  |d |
ƒ\}}||7 }d| d¡ }||7 }t|ƒ|k�sÓ|�rØ||	7 }n|d7 }d|t|
ƒd…  }|S )0aÛ  
    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$   rM   é   z
 z,
 rU   zdisplay.max_seq_itemsrR   r   Úlinerˆ   Údisplay_widthr   Únext_line_prefixr   útuple[str, str]c                   s@   ˆ   | ¡ ¡ˆ   | ¡ ¡ |kr| | ¡ 7 } |}||7 }| |fS r…   )r,   Úrstrip)rR   r¬   rˆ   r­   r®   ©Úadjr   r   Ú_extend_line]  s
    z+format_object_summary.<locals>._extend_lineÚvaluesr   c                   s   | rt ‡ fdd„| 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_lenrS   r   z[]ú[ú]r!   c                   ó   g | ]}ˆ |ƒ‘qS r   r   r   ©r¤   r   r   r    {  ó    z)format_object_summary.<locals>.<listcomp>é
   c                   rº   r   r   r   r»   r   r   r    ~  r¼   c                   rº   r   r   r   r»   r   r   r      r¼   c                   rº   r   r   r   r»   r   r   r    ‚  r¼   c                   r>   r   rE   r   ©Ú
max_lengthr   r   r    ‘  rB   c                   r>   r   rE   r   r¾   r   r   r    ’  rB   ©rJ   c                   ó   g | ]}t |ˆ d �‘qS ©rÀ   ©rb   r   ©Ú	max_itemsr   r   r    £  ó    c                   rÁ   rÂ   rÃ   r   rÄ   r   r   r    ¤  rÆ   r&   z...)rR   r   r¬   r   rˆ   r   r­   r   r®   r   r   r¯   )r´   r   r   r   )r   r   Útyper’   r,   Úget_adjustmentr\   Ú_justifyr'   r   Úreversedr[   rb   r°   )Úobjr¤   r¥   r¦   r¨   r©   r­   Ú_Úname_lenÚspace1Úspace2ÚnÚseprJ   Úis_truncatedr³   r·   ÚcloseÚsummaryÚfirstÚlastÚheadÚtailÚ	max_spacerˆ   Ú	num_itemsÚpprinted_seqr¬   Ú
head_valueÚwordÚ	tail_itemr   )r²   r¤   rÅ   r¿   r   Úformat_object_summary  s¦   
!
	
X©U¬Q±þ
rß   r×   úlist[Sequence[str]]rØ   ú3tuple[list[tuple[str, ...]], list[tuple[str, ...]]]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    ç  ó    c                   ó$   g | ]}t d d„ t|ˆ ƒD ƒƒ‘qS )c                 s  ó   � | ]
\}}|  |¡V  qd S r…   rE   ©r   r   r=   r   r   r   r)   ë  ó   € ú&_justify.<locals>.<listcomp>.<genexpr>©r]   r0   ©r   rH   r¾   r   r   r    ê  ó    ÿc                   rå   )c                 s  ræ   r…   rE   rç   r   r   r   r)   î  rè   ré   rê   rë   r¾   r   r   r    í  rì   )r,   r0   )r×   rØ   ÚcombinedÚ	inner_seqÚlengthÚhead_tuplesÚtail_tuplesr   r¾   r   rÉ   Ê  s   
ÿ
ÿrÉ   c                   @  s   e Zd ZdZ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__ö  ó   zPrettyDict.__repr__N)r   r   )r’   r“   r”   Ú__doc__rõ   r   r   r   r   rò   ó  s    rò   c                   @  s6   e Zd Zddd„Zddd	„Zdddd„Z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__Útextr   r   c                 C  s   t |ƒS r…   rµ   ©rô   rú   r   r   r   r,   þ  rö   z_TextAdjustment.lenr:   r;   r   r=   r#   r   c                   sF   |dkr‡ fdd„|D ƒS |dkr‡ fdd„|D ƒS ‡ fdd„|D ƒS )zJ
        Perform ljust, center, rjust against string or list-like
        r"   c                   r>   r   r?   r   rA   r   r   r      rB   z+_TextAdjustment.justify.<locals>.<listcomp>rC   c                   r>   r   rD   r   rA   r   r   r      rB   c                   r>   r   rE   r   rA   r   r   r    
  rB   r   ©rô   r;   r=   r#   r   rA   r   Újustify  rG   z_TextAdjustment.justifyr   c                 O  s    t |g|¢R | j| jdœ|¤ŽS )N)r   r   )r9   r,   rý   )rô   r   r   r1   r   r   r   r9     s    z_TextAdjustment.adjoinN©r   r‹   ©rú   r   r   r   ©r:   )r;   r   r=   r   r#   r   r   r   )r   r   r   r   )r’   r“   r”   rù   r,   rý   r9   r   r   r   r   rø   ú  s
    

rø   c                      s6   e Zd Zd‡ fdd„Zddd	„Z	
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«   rM   )Ú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   r{   ró   r   r   r)   $  s   € 
ÿz/_EastAsianTextAdjustment.len.<locals>.<genexpr>)rW   r   r,   Úsumrû   r   ró   r   r,     s
   
ÿz_EastAsianTextAdjustment.lenr:   r;   r<   r=   r#   r   c                   sT   ‡‡fdd„‰ |dkr‡ fdd„|D ƒS |dkr!‡ fdd„|D ƒS ‡ fdd„|D ƒS )	Nc                   s   ˆ ˆ  | ¡ t | ƒ S r…   rµ   )Út)r=   rô   r   r   Ú_get_pad,  s   z2_EastAsianTextAdjustment.justify.<locals>._get_padr"   c                   ó   g | ]	}|  ˆ |ƒ¡‘qS r   r?   r   ©r  r   r   r    0  rä   z4_EastAsianTextAdjustment.justify.<locals>.<listcomp>rC   c                   r  r   rD   r   r  r   r   r    2  rä   c                   r  r   rE   r   r  r   r   r    4  rä   r   rü   r   )r  r=   rô   r   rý   (  s   z _EastAsianTextAdjustment.justifyrþ   rÿ   r   ©r;   r<   r=   r   r#   r   r   r   )r’   r“   r”   rù   r,   rý   Ú__classcell__r   r   r
  r   r    s
    
ÿr  c                  C  s   t dƒ} | r	tƒ S tƒ S )Nz display.unicode.east_asian_width)r   r  rø   )Úuse_east_asian_widthr   r   r   rÈ   7  s   rÈ   )r   r   r   r   r   r   r   r  )r   N)rH   r   rI   r   rJ   rK   r   r   )rH   r   rI   r   rJ   rK   r   r   )r   NFFN)rm   r   rI   r   rn   ro   rp   rq   rr   rq   rJ   rK   r   r   )r�   rx   )r‚   r   rƒ   r   r   r„   )rŠ   rq   r   r‹   r…   )rm   r   rJ   rK   r   r   )TNTF)r¤   r   r¥   rq   r¦   r§   r¨   rq   r©   rq   r   r   )r×   rà   rØ   rà   r   rá   )r   rø   )(r÷   Ú
__future__r   Úcollections.abcr   r   r   r˜   Útypingr   r   r   r	   Úunicodedatar
   Úpandas._configr   Úpandas.core.dtypes.inferencer   Úpandas.io.formats.consoler   r   ÚEscapeCharsr   r   r9   r-   rb   rl   rN   r‰   r¡   r£   rß   rÉ   ru   rò   rø   r  rÈ   r   r   r   r   Ú<module>   sN    
 %ÿ$ÿ!úJÿ
!ú 
,)'