1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
U
¬ý°dŸã@stdZddlmZddlmZddlmZmZddlZ    ddl
m Z erPddl m Z Gdd    „d    ƒZd
d d
d œd d„ZdS)z;
Module for formatting output data in console (to string).
é)Ú annotations)Úget_terminal_size)Ú TYPE_CHECKINGÚIterableN)Ú pprint_thing)ÚDataFrameFormatterc@sØeZdZdZd(ddddœdd„Zd    d
œd d „Zd d
œdd„Zd    d
œdd„Zed    d
œdd„ƒZ    edd
œdd„ƒZ
d d dœdd„Z edd
œdd„ƒZ d dd dœdd„Z d dd dœd d!„Zd"d    d#œd$d%„Zd d    dœd&d'„ZdS))ÚStringFormatterz3Formatter for string representation of a dataframe.Nrz
int | NoneÚNone)ÚfmtÚ
line_widthÚreturncCs ||_|j|_|j|_||_dS©N)r
ÚadjÚframer )Úselfr
r ©rúOd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/io/formats/string.pyÚ__init__szStringFormatter.__init__Ústr)r cCs&| ¡}|jjr"d ||jjg¡}|S)NÚ)Ú_get_string_representationr
Zshould_show_dimensionsÚjoinZdimensions_info)rÚtextrrrÚ    to_stringszStringFormatter.to_stringzlist[list[str]]cCs |j ¡}|jjr| |¡}|Sr )r
Z get_strcolsZ is_truncatedÚ_insert_dot_separators©rÚstrcolsrrrÚ _get_strcols#s
 
zStringFormatter._get_strcolscCsL|jjjr|jS| ¡}|jdkr2|jjd|žŽS|jrB|     |¡S| 
|¡S)Né)r) r
rÚemptyÚ_empty_info_linerr rÚadjoinÚ_need_to_wrap_aroundÚ_join_multilineÚ_fit_strcols_to_terminal_widthrrrrr)s
 
 
z*StringFormatter._get_string_representationcCs.dt|jƒj›dt|jjƒ›dt|jjƒ›S)NzEmpty z
 
Columns: z
Index: )ÚtyperÚ__name__rÚcolumnsÚindex©rrrrr 8s,ÿz StringFormatter._empty_info_lineÚboolcCst|jjdkp|jjdkƒS)Nr)r*r
Zmax_colsr)rrrr"@sz$StringFormatter._need_to_wrap_around)rr cCsD|j |jj¡}t|ƒ}|jjr,| ||¡}|jjr@| ||¡}|Sr )r
Z_get_formatted_indexÚtr_frameÚlenÚis_truncated_horizontallyÚ _insert_dot_separator_horizontalÚis_truncated_verticallyÚ_insert_dot_separator_vertical)rrZ    str_indexÚ index_lengthrrrrDs  z&StringFormatter._insert_dot_separatorsÚintcCs|jjr|jjdS|jjS)Nr)r
r(Z
tr_col_numr)rrrÚ_adjusted_tr_col_numPsz$StringFormatter._adjusted_tr_col_num)rr1r cCs| |jdg|¡|S)Nz ...)Úinsertr3)rrr1rrrr.Tsz0StringFormatter._insert_dot_separator_horizontalc Cs¼|t|jjƒ}|jj}t|ƒD]–\}}|j ||¡}|jjrL||jk}nd}|dks\|rbd}    nd}    |dkr||jjr|d}
n|rŠd}d}
nd}
|jj    |    g||
d    d} | 
||| ¡q |S)
NFéz...z..rÚleftéÚright)Úmode) r,r
r+Z
tr_row_numÚ    enumeraterr-r3r(Zjustifyr4) rrr1Z n_header_rowsZrow_numÚixÚcolZcwidthZ
is_dot_colÚdotsZdot_modeZdot_strrrrr0Zs&  z.StringFormatter._insert_dot_separator_verticalzIterable[list[str]])Ú strcols_inputr csZˆj}d}t|ƒ}ˆjjrH| d¡}|t ‡fdd„|Dƒ¡ ¡|8}‡fdd„|Dƒ}|dk    sft‚t    ||ƒ}t
|ƒ}ˆjj ržˆjj dk    st‚ˆjj d}    n
t
ˆj ƒ}    g}
d} t|ƒD]–\} } || | …}ˆjjrà| d|¡|dkr2| t
|ƒkr"| |dkr"| dgdg|    d¡n| dg|    ¡|
 ˆjj|f|žŽ¡| } q¸d     |
¡S)
Nrrcsg|]}ˆj |¡‘qSr©rr,©Ú.0Úxr)rrÚ
<listcomp>sz3StringFormatter._join_multiline.<locals>.<listcomp>cs8g|]0}t|ƒdkr0t ‡fdd„|Dƒ¡ ¡nd‘qS)rcsg|]}ˆj |¡‘qSrr?r@r)rrrC‚sz>StringFormatter._join_multiline.<locals>.<listcomp>.<listcomp>)r,ÚnpÚarrayÚmax)rAr<r)rrrCsÿz \z  ú z
 
)r Úlistr
r(ÚpoprDrErFÚAssertionErrorÚ_binifyr,r/Zmax_rows_fittedrr:r4Úappendrr!r)rr>ZlwidthÚ adjoin_widthrÚidxZ
col_widthsZcol_binsZnbinsZnrowsZstr_lstÚstartÚiÚendÚrowrr)rr#xs:
$
þ 
 
 
zStringFormatter._join_multilinecsddlm‰|jjd|žŽ d¡}ˆ|ƒj ¡ ¡}tƒ\}}||}|d}ˆ‡fdd„|Dƒƒ}t|ƒ}    d}
|dkrÆ|    dkrÆ|
d7}
t    |    dƒ} |j
| } || } || d8}|  | ¡}t|ƒ}    qp|    |j j
}t|dƒ}||j _ |j  ¡| ¡}|jjd    |žŽS)
Nr©ÚSeriesrÚ
csg|]}ˆ|ƒ t¡ ¡‘qSr)Úapplyr,rF)rAZelerSrrrC©szBStringFormatter._fit_strcols_to_terminal_width.<locals>.<listcomp>é)r)r)ZpandasrTrr!Úsplitrr,rFrÚroundr(Zdropr
Úmax_cols_fittedÚtruncater)rrÚlinesÚmax_lenÚwidthÚ_ZdifZadj_difZcol_lensZn_colsÚcounterZmidZmid_ixZcol_lenrZrrSrr$Ÿs. 
 
 
 
 
 
z.StringFormatter._fit_strcols_to_terminal_width)N)r&Ú
__module__Ú __qualname__Ú__doc__rrrrÚpropertyr r"rr3r.r0r#r$rrrrrs  'rz    list[int]r2)Úcolsr r c
Csd}g}d}t|ƒd}t|ƒD]\\}}||}||7}||krV|d|koR|dk}    n|d|koh|dk}    |    r | |¡|}q | t|ƒ¡|S)NrrrW)r,r:rL)
rer rMZbinsZ
curr_widthZ i_last_columnrPÚwZ
w_adjoinedÚwraprrrrKÃs 
rK)rcÚ
__future__rÚshutilrÚtypingrrÚnumpyrDZpandas.io.formats.printingrZpandas.io.formats.formatrrrKrrrrÚ<module>s    0