o
    թZh3                     @  st   d Z ddlmZ ddlmZ ddlmZ ddlZddl	m
Z
 er,ddlmZ ddlmZ G d	d
 d
ZdddZdS )z;
Module for formatting output data in console (to string).
    )annotations)get_terminal_size)TYPE_CHECKINGN)pprint_thing)Iterable)DataFrameFormatterc                   @  s   e Zd ZdZd)d*d	d
Zd+ddZd,ddZd+ddZed+ddZ	ed-ddZ
d.ddZed/ddZd0dd Zd0d!d"Zd1d%d&Zd2d'd(ZdS )3StringFormatterz3Formatter for string representation of a dataframe.Nfmtr   
line_width
int | NonereturnNonec                 C  s    || _ |j| _|j| _|| _d S N)r	   adjframer
   )selfr	   r
    r   O/var/www/html/lang_env/lib/python3.10/site-packages/pandas/io/formats/string.py__init__   s   
zStringFormatter.__init__strc                 C  s$   |   }| jjr| | jj }|S r   )_get_string_representationr	   Zshould_show_dimensionsZdimensions_info)r   textr   r   r   	to_string   s   zStringFormatter.to_stringlist[list[str]]c                 C  s    | j  }| j jr| |}|S r   )r	   Zget_strcolsZis_truncated_insert_dot_separatorsr   strcolsr   r   r   _get_strcols"   s   

zStringFormatter._get_strcolsc                 C  sP   | j jjr| jS |  }| jd u r| jjdg|R  S | jr#| 	|S | 
|S N   )r	   r   empty_empty_info_liner   r
   r   adjoin_need_to_wrap_around_join_multiline_fit_strcols_to_terminal_widthr   r   r   r   r   (   s   



z*StringFormatter._get_string_representationc                 C  s.   dt | jj dt| jj dt| jj S )NzEmpty z

Columns: z
Index: )typer   __name__r   columnsindexr   r   r   r   r!   7   s   

z StringFormatter._empty_info_lineboolc                 C  s   t | jjd u p| jjdkS )Nr   )r+   r	   Zmax_colsr*   r   r   r   r#   ?      z$StringFormatter._need_to_wrap_aroundr   c                 C  sD   | j | j j}t|}| j jr| ||}| j jr | ||}|S r   )r	   Z_get_formatted_indextr_framelenis_truncated_horizontally _insert_dot_separator_horizontalZis_truncated_vertically_insert_dot_separator_vertical)r   r   Z	str_indexindex_lengthr   r   r   r   C   s   z&StringFormatter._insert_dot_separatorsintc                 C  s   | j jr
| j jd S | j jS r   )r	   r)   Z
tr_col_numr*   r   r   r   _adjusted_tr_col_numO   r,   z$StringFormatter._adjusted_tr_col_numr2   c                 C  s   | | jdg|  |S )Nz ...)insertr4   )r   r   r2   r   r   r   r0   S   s   z0StringFormatter._insert_dot_separator_horizontalc                 C  s   |t | jj }| jj}t|D ]K\}}| j || }| jjr&|| jk}nd}|dks.|r1d}	nd}	|dkr>| jjr>d}
n	|rEd}d}
nd}
| jj	|	g||
d	d }|
|| | q|S )
NF   z...z..r   left   right)mode)r.   r	   r-   Z
tr_row_num	enumerater   r/   r4   r)   justifyr5   )r   r   r2   Zn_header_rowsZrow_numZixcolZcwidthZ
is_dot_coldotsZdot_modeZdot_strr   r   r   r1   Y   s&   z.StringFormatter._insert_dot_separator_verticalstrcols_inputIterable[list[str]]c                   s2   j }d}t|} jjr$|d}|t fdd|D  | 8 } fdd|D }|d us3J t||}t	|}g }	d}
t
|D ]O\}}||
| } jjrX|d| |dkrt	|d }|t	|kr|||d k r||dgdg|d    n|d	g|  |	 jj|g|R   |}
qDd
|	S )Nr   r   c                      g | ]} j |qS r   r   r.   .0xr*   r   r   
<listcomp>~       z3StringFormatter._join_multiline.<locals>.<listcomp>c                   s8   g | ]}t |d krt fdd|D  nd qS )r   c                   rA   r   rB   rC   r*   r   r   rF      rG   z>StringFormatter._join_multiline.<locals>.<listcomp>.<listcomp>)r.   nparraymax)rD   r=   r*   r   r   rF      s    *z \z   z

)r
   listr	   r)   poprH   rI   rJ   _binifyr.   r;   r5   appendr   r"   join)r   r?   Zlwidthadjoin_widthr   idxZ
col_widthsZcol_binsZnbinsZstr_lststartiendrowZnrowsr   r*   r   r$   w   s4   
$


zStringFormatter._join_multilinec                   s  ddl m  | jjdg|R  d} |j  }t \}}|| }|d }  fdd|D }t|}	d}
|dkrl|	dkrl|
d7 }
t	|	d }|j
| }|| }||d 8 }||}t|}	|dkrl|	dksB|	| jj
 }t|d}|| j_| j  |  }| jjdg|R  S )Nr   Seriesr   
c                   s   g | ]} |j   qS r   )r   r.   rJ   )rD   ZelerX   r   r   rF      s    zBStringFormatter._fit_strcols_to_terminal_width.<locals>.<listcomp>   )ZpandasrY   r   r"   splitr   r.   rJ   r   roundr)   Zdropr	   max_cols_fittedtruncater   )r   r   linesmax_lenwidth_ZdifZadj_difZcol_lensZn_colscountermidZmid_ixZcol_lenr^   r   rX   r   r%      s0   




z.StringFormatter._fit_strcols_to_terminal_widthr   )r	   r   r
   r   r   r   )r   r   )r   r   )r   r+   )r   r   r   r   )r   r3   )r   r   r2   r3   r   r   )r?   r@   r   r   )r   r   r   r   )r'   
__module____qualname____doc__r   r   r   r   propertyr!   r#   r   r4   r0   r1   r$   r%   r   r   r   r   r      s"    






"r   cols	list[int]r
   r3   r   c           
      C  s   d}g }d}t | d }t| D ].\}}|| }||7 }||kr+|d |ko)|dk}	n
|d |ko4|dk}	|	r>|| |}q|t |  |S )Nr   r   r[   )r.   r;   rP   )
rj   r
   rR   ZbinsZ
curr_widthZi_last_columnrU   wZ
w_adjoinedwrapr   r   r   rO      s    
rO   )rj   rk   r
   r3   r   rk   )rh   
__future__r   shutilr   typingr   numpyrH   Zpandas.io.formats.printingr   collections.abcr   Zpandas.io.formats.formatr   r   rO   r   r   r   r   <module>   s     +