o
    h3                     @  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   l/var/www/html/construction_image-detection-poc/venv/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	   should_show_dimensions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	   get_strcols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	   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	   _get_formatted_indextr_framelenis_truncated_horizontally _insert_dot_separator_horizontalis_truncated_vertically_insert_dot_separator_vertical)r   r    	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-   
tr_col_numr.   r   r   r   _adjusted_tr_col_numO   r1   z$StringFormatter._adjusted_tr_col_numr:   c                 C  s   | | jdg|  |S )Nz ...)insertr=   )r   r    r:   r   r   r   r6   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)r4   r	   r3   
tr_row_num	enumerater   r5   r=   r-   justifyr>   )r   r    r:   n_header_rowsrow_numixcolcwidth
is_dot_coldotsdot_modedot_strr   r   r   r8   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   r4   .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                   rR   r   rS   rT   r.   r   r   rW      rX   z>StringFormatter._join_multiline.<locals>.<listcomp>.<listcomp>)r4   nparraymax)rU   rJ   r.   r   r   rW      s    *z \z   z

)r
   listr	   r-   poprY   rZ   r[   _binifyr4   rE   r>   appendr   r&   join)r   rP   lwidthadjoin_widthr    idx
col_widthscol_binsnbinsstr_lststartiendrow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   r4   r[   )rU   elero   r   r   rW      s    zBStringFormatter._fit_strcols_to_terminal_width.<locals>.<listcomp>   )pandasrp   r   r&   splitr   r4   r[   r   roundr-   dropr	   max_cols_fittedtruncater!   )r   r    linesmax_lenwidth_difadj_difcol_lensn_colscountermidmid_ixcol_lenrx   r   ro   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   r;   )r    r   r:   r;   r   r   )rP   rQ   r   r   )r    r   r   r   )r+   
__module____qualname____doc__r   r   r!   r   propertyr%   r'   r   r=   r6   r8   r(   r)   r   r   r   r   r      s"    






"r   cols	list[int]r
   r;   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   rs   )r4   rE   ra   )
r   r
   rd   bins
curr_widthi_last_columnrk   w
w_adjoinedwrapr   r   r   r`      s    
r`   )r   r   r
   r;   r   r   )r   
__future__r   shutilr   typingr   numpyrY   pandas.io.formats.printingr   collections.abcr   pandas.io.formats.formatr   r   r`   r   r   r   r   <module>   s     +