U
    +if                     @  sl   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
 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)IterableN)DataFrameFormatter)pprint_thingc                   @  s   e Zd ZdZ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)fmt
line_widthc                 C  s    || _ |j| _|j| _|| _d S N)r   adjframer	   )selfr   r	    r   K/home/mars/bis/venv/lib/python3.8/site-packages/pandas/io/formats/string.py__init__   s    zStringFormatter.__init__str)returnc                 C  s&   |   }| jjr"d|| jjg}|S )N )_get_string_representationr   Zshould_show_dimensionsjoinZ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  sL   | j jjr| jS |  }| jd kr2| jjd| S | jrB| 	|S | 
|S )N   )r   )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   3   s    ,z StringFormatter._empty_info_lineboolc                 C  s   t | jjd k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_horizontalis_truncated_vertically_insert_dot_separator_vertical)r   r   Z	str_indexindex_lengthr   r   r   r   ?   s    z&StringFormatter._insert_dot_separatorsintc                 C  s   | j jr| j jd S | j jS )Nr   )r   r&   Z
tr_col_numr'   r   r   r   _adjusted_tr_col_numK   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,   O   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.   U   s&    z.StringFormatter._insert_dot_separator_verticalzIterable[list[str]])strcols_inputr   c                   sZ   j }d}t|} jjrH|d}|t fdd|D  | 8 } fdd|D }|d k	sftt	||}t
|} jjr jjd k	st jjd }	n
t
 j}	g }
d}t|D ]\}}||| } jjr|d| |dkr2|t
|kr"||d k r"|dgdg|	d    n|dg|	  |
 jj|f|  |}qd	|
S )
Nr   r   c                   s   g | ]} j |qS r   r   r*   .0xr'   r   r   
<listcomp>z   s     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   }   s     z>StringFormatter._join_multiline.<locals>.<listcomp>.<listcomp>)r*   nparraymax)r?   r:   r'   r   r   rA   |   s   z \z   z

)r	   listr   r&   poprB   rC   rD   AssertionError_binifyr*   r-   Zmax_rows_fittedr   r8   r2   appendr   r   r   )r   r<   Zlwidthadjoin_widthr   idxZ
col_widthsZcol_binsZnbinsZnrowsZstr_lststartiendrowr   r'   r   r!   s   s:    
$



zStringFormatter._join_multilinec                   s  ddl m  | jjd| d} |j  }t \}}|| }|d }  fdd|D }t|}	d}
|dkr|	dkr|
d7 }
t	|	d }|j
| }|| }||d 8 }||}t|}	qp|	| jj
 }t|d}|| j_| j  |  }| jjd	| S )
Nr   Seriesr   
c                   s   g | ]} | t qS r   )applyr*   rD   )r?   ZelerQ   r   r   rA      s     zBStringFormatter._fit_strcols_to_terminal_width.<locals>.<listcomp>   )r   )r   )ZpandasrR   r   r   splitr   r*   rD   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_lenrX   r   rQ   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   rU   )r*   r8   rJ   )
rd   r	   rK   ZbinsZ
curr_widthZi_last_columnrN   wZ
w_adjoinedwrapr   r   r   rI      s    
rI   )rb   
__future__r   shutilr   typingr   numpyrB   Zpandas.io.formats.formatr   Zpandas.io.formats.printingr   r   rI   r   r   r   r   <module>   s    0