a
    Of3                     @  s|   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rXddlmZ ddlmZ G d	d
 d
Zddd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dddZd	d
ddZdd
ddZd	d
ddZed	d
ddZ	edd
ddZ
dddddZedd
ddZddddddZddddd d!Zd"d	d#d$d%Zdd	dd&d'ZdS ))StringFormatterz3Formatter for string representation of a dataframe.Nr   z
int | NoneNone)fmt
line_widthreturnc                 C  s    || _ |j| _|j| _|| _d S N)r
   adjframer   )selfr
   r    r   Q/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/io/formats/string.py__init__   s    zStringFormatter.__init__str)r   c                 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_stringz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 r6| jjdg|R  S | jrF| 	|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!   ?   s    z$StringFormatter._need_to_wrap_around)r   r   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   s    z$StringFormatter._adjusted_tr_col_num)r   r/   r   c                 C  s   | | jdg|  |S )Nz ...)insertr1   )r   r   r/   r   r   r   r-   S   s    z0StringFormatter._insert_dot_separator_horizontalc                 C  s   |t | jj }| jj}t|D ]\}}| j || }| jjrL|| jk}nd}|dks\|rbd}	nd}	|dkr|| jjr|d}
n|rd}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,   r1   r'   justifyr2   )r   r   r/   Zn_header_rowsZrow_numZixcolZcwidthZ
is_dot_coldotsZdot_modeZdot_strr   r   r   r.   Y   s&    z.StringFormatter._insert_dot_separator_verticalzIterable[list[str]])strcols_inputr   c                   s4   j }d}t|} jjrH|d}|t fdd|D  | 8 } fdd|D }|d usfJ t||}t	|}g }	d}
t
|D ]\}}||
| } jjr|d| |dkr
t	|d }|t	|kr||d k r|dgdg|d    n|d	g|  |	 jj|g|R   |}
qd
|	S )Nr   r   c                   s   g | ]} j |qS r   r   r+   .0xr(   r   r   
<listcomp>~       z3StringFormatter._join_multiline.<locals>.<listcomp>c                   s8   g | ]0}t |d kr0t fdd|D  nd qS )r   c                   s   g | ]} j |qS r   r=   r>   r(   r   r   rA      rB   z>StringFormatter._join_multiline.<locals>.<listcomp>.<listcomp>)r+   nparraymax)r?   r:   r(   r   r   rA      s   z \z   z

)r   listr
   r'   poprC   rD   rE   _binifyr+   r8   r2   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r|	dkr|
d7 }
t	|	d }|j
| }|| }||d 8 }||}t|}	qt|	| jj
 }t|d}|| j_| j  |  }| jjdg|R  S )Nr   Seriesr   
c                   s   g | ]} |j   qS r   )r   r+   rE   )r?   ZelerS   r   r   rA      rB   zBStringFormatter._fit_strcols_to_terminal_width.<locals>.<listcomp>   )ZpandasrT   r   r    splitr   r+   rE   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_lenrY   r   rS   r   r#      s.    





z.StringFormatter._fit_strcols_to_terminal_width)N)r%   
__module____qualname____doc__r   r   r   r   propertyr   r!   r   r1   r-   r.   r"   r#   r   r   r   r   r      s    "r   z	list[int]r0   )colsr   r   c           
      C  s   d}g }d}t | d }t| D ]\\}}|| }||7 }||krV|d |koR|dk}	n|d |koh|dk}	|	r || |}q |t |  |S )Nr   r   rV   )r+   r8   rK   )
re   r   rM   ZbinsZ
curr_widthZi_last_columnrP   wZ
w_adjoinedwrapr   r   r   rJ      s    
rJ   )rc   
__future__r   shutilr   typingr   numpyrC   Zpandas.io.formats.printingr   collections.abcr   Zpandas.io.formats.formatr   r   rJ   r   r   r   r   <module>   s    +