
    Mhc                   z   S SK Jr  S SKJr  S SKJr  S SKJr  S SKrS SK	J
r
JrJrJrJrJrJr  S SKJr  S SKrS SKJr  S S	KJr  S S
KJr  S SKJrJrJr  S SKJ r   S SK!J"r"J#r#J$r$J%r%J&r&J'r'  S SK(J)r)  S SK*J+s  J,r-  \
(       a  S SK.J/r/J0r0  \" SSS9r1S SK2J3r4  \\5\4   r6\\6\7\\\6   4   4   r8\9\5\\5\:4   4   r;\<\;   r=\\5\=4   r> " S S\5      r?\<\?   r@\\A\\#4   rB " S S5      rC          S1S jrD   S2   S3S jjrE S4       S5S jjrFS6S jrGS7S jrHS8S9S jjrI        S:S jrJS rKS  rL       S;               S<S! jjrMS=S" jrNS>S# jrO      S?S$ jrP " S% S&5      rQS@S' jrRSAS( jrS S8       SBS) jjrT  SC           SDS* jjrUSES+ jrVSFS, jrWSGS- jrXSGS. jrYSGS/ jrZSGS0 jr[g)H    )annotations)defaultdict)Sequence)partialN)TYPE_CHECKINGAnyCallableDefaultDictOptional	TypedDictUnion)uuid4)
get_option)lib)import_optional_dependency)
is_complexis_float
is_integer)	ABCSeries)	DataFrameIndex
IndexSlice
MultiIndexSeriesisna)is_list_like)AxisLeveljinja2z DataFrame.style requires jinja2.)extraescapec                  *    \ rS rSr% S\S'   S\S'   Srg)CSSDict:   strselectorCSSPropertiesprops N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r*       P/var/www/html/env/lib/python3.13/site-packages/pandas/io/formats/style_render.pyr$   r$   :   s    Mr1   r$   c                  :   \ rS rSrSr\R                  SS5      r\R                  \SS9r	\	R                  S5      r\	R                  S5      r\	R                  S	5      r\	R                  S
5      r\	R                  S5      r       S                  S!S jjr   S"         S#S jjr  S$         S%S jjr        S&S jr  S$         S%S jjrS r    S'           S(S jjrS)S jr      S*S jr      S*S jrS+S jr  S,             S-S jjrS.S jr      S/S jrS0S jr        S1                 S2S jjr         S3                   S4S jjr   S5       S6S jjr!Sr"g)7StylerRendererC   zL
Base class to process rendering a Styler with a specified jinja2 template.
pandaszio/formats/templatesT)loadertrim_blockszhtml.tplzhtml_table.tplzhtml_style.tplz	latex.tplz
string.tplNc	                *  ^ [        U[        5      (       a  UR                  5       n[        U[        5      (       d  [	        S5      eXl        UR                  U l        UR                  U l        [        U[        5      (       a  US:  a  [	        S5      eU=(       d!    [        5       R                  S [        SU5       U l        [        U R                  5      U l        X@l        XPl        X`l        Xpl        SSSSS	S
SSSSSS.U l        / U l        SU l        SU l        S/U R                  R.                  -  U l        S/U R                  R.                  -  U l        / U l        / U l        [9        [:        5      U l        [9        [:        5      U l        [9        [:        5      U l         [9        [B        5      U l"        / U l#        S U l$        Tc  [K        S5      OTm[9        U4S j5      U l&        [9        U4S j5      U l'        [9        U4S j5      U l(        g )Nz&``data`` must be a Series or DataFramer   z1``uuid_len`` must be an integer in range [0, 32].    row_headingcol_heading
index_namecolrowcol_trimrow_trimleveldatablankfoot)r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   Fstyler.format.precisionc                     > [        [        T S9$ N	precisionr   _default_formatterrI   s   r2   <lambda>)StylerRenderer.__init__.<locals>.<lambda>       (:i Pr1   c                     > [        [        T S9$ rH   rK   rI   s   r2   rM   rN      rO   r1   c                     > [        [        T S9$ rH   rK   rI   s   r2   rM   rN      rO   r1   ))
isinstancer   to_framer   	TypeErrorrC   indexcolumnsintr   hexminuuidlenuuid_lentable_stylestable_attributescaptioncell_idscssconcatenatedhide_index_nameshide_column_namesnlevelshide_index_hide_columns_hidden_rowshidden_columnsr   listctx	ctx_indexctx_columnsr&   cell_context_todotooltipsr   _display_funcs_display_funcs_index_display_funcs_columns)	selfrC   rZ   r\   r]   r^   r_   r`   rJ   s	           `r2   __init__StylerRenderer.__init__P   s    dF##==?D$	**DEE#	 JJ
"ll(C((HqLOPP<EGKK(;#b(*;<	DII( 0 ((&""
 35&+',"'4::+=+=!=$)7T\\-A-A#A*,-/:Ed:K@KD@QBMdBS?J3?O9;
)-5>5FJ01I 	
 PQ 	
 PQ 	!
 PQ 	#r1   c                   U R                  5         / n[        U R                  5      n[        U R                  5       GH  u  pU R
                  U	l        U R                  U	l        U R                  S    U 3n
0 U R                  EU
 S3U
 S3U
 S3U
 S3S.EU	l        U	R                  XX4U5      nUR                  U5        U	R                  R                  5        H  u  u  pnXR                  X-   U4'   M     U	R                  R                  5        H  u  u  pnXR                  X-   U4'   M     U[        U	R                  5      -  nGM     U R                  XX4XV5      nU$ )z
Computes and applies styles and then generates the general render dicts.

Also extends the `ctx` and `ctx_index` attributes with those of concatenated
stylers for use within `_translate_latex`
rE   _data_row_heading_row_foot)rC   r;   r?   rE   )_computer[   rU   	enumeraterb   rf   ri   ra   _renderappendrk   itemsrl   
_translate)rt   sparse_indexsparse_columnsmax_rowsmax_colsrD   dxsctx_lenirb   rE   dxrcvds                   r2   r~   StylerRenderer._render   si    	djj/():):;OA'+'7'7L$*.*=*=L'hhv&'s+D (( &"&|4t}& L %%h%B JJrN)--335	-.!+q)* 6)3399;	34Q/0 < s<--..G+  <. OO(e
 r1   c                    U R                  XX4S5      nUR                  U5        U R                  R                  " S0 UDU R                  U R
                  S.D6$ )z
Renders the ``Styler`` including all applied styles to HTML.
Generates a dict with necessary kwargs passed to jinja2 template.
&nbsp;)html_table_tplhtml_style_tplr*   )r~   updatetemplate_htmlrendertemplate_html_tabletemplate_html_stylert   r   r   r   r   kwargsr   s          r2   _render_htmlStylerRenderer._render_html   sZ     LLx8T	!!(( 

3333
 	
r1   c                   U R                  XSS5      nU R                  XSS9  [        U R                  R                  S'   [
        U R                  R                  S'   [        U R                  R                  S'   [        U R                  R                  S'   UR                  U5        U R                  R                  " S0 UD6$ )z!
Render a Styler in latex format
N)clines
parse_wrapparse_table
parse_cellparse_headerr*   )
r~   _translate_latex_parse_latex_table_wrappingtemplate_latexglobals_parse_latex_table_styles_parse_latex_cell_styles_parse_latex_header_spanr   r   )rt   r   r   r   r   r   s         r2   _render_latexStylerRenderer._render_latex   s     LLtTBa/4O##L15N##M24L##L16N##N3	"")).A..r1   c                    U R                  XX45      nUR                  U5        U R                  R                  " S0 UD6$ )z"
Render a Styler in string format
r*   )r~   r   template_stringr   r   s          r2   _render_stringStylerRenderer._render_string   s:     LLxJ	##**/Q//r1   c                    U R                   R                  5         U R                  R                  5         U R                  R                  5         U nU R                   H  u  p#nU" U 5      " U0 UD6nM     U$ )z
Execute the style functions built up in `self._todo`.

Relies on the conventions that all style functions go through
.apply or .map. The append styles to apply as tuples of

(application method, *args, **kwargs)
)rk   clearrl   rm   ro   )rt   r   funcargsr   s        r2   r|   StylerRenderer._compute   sd     	 "&**DT
D+F+A #-r1   c                   Uc  / nXPR                   S'   U R                  [        U R                  =(       d    / 5      U R                  S.n[        S5      nU(       a  UO
[        S5      nU(       a  UO
[        S5      n[        [        U R                  R                  5      [        U R                  R                  5      UUU5      u  p4[        [        5      U l        U R                  X$5      n	UR                  SU	05        [!        U R                  XU R"                  5      n
UR                  SU
05        [        [        5      U l        [        [        5      U l        U R)                  XU5      nUR                  SU05        S	S
SS.nUR+                  5        HR  u  p[-        X5      R+                  5        VVs/ s H  u  nn[        U5      US.PM     nnnUR                  UU05        MT     U HH  nUS   R/                  US   5        US   R/                  US   5        US   R/                  US   5        MJ     U R0                  n[        S5      (       d)  U=(       d    SnSU;   a  UR3                  SS5      nOUS-  nUR                  SU05        U R4                  (       a  U R4                  R7                  X5      nU$ s  snnf )a  
Process Styler data and settings into a dict for template rendering.

Convert data and settings from ``Styler`` attributes such as ``self.data``,
``self.tooltips`` including applying any methods in ``self._todo``.

Parameters
----------
sparse_index : bool
    Whether to sparsify the index or print all hierarchical index elements.
    Upstream defaults are typically to `pandas.options.styler.sparse.index`.
sparse_cols : bool
    Whether to sparsify the columns or print all hierarchical column elements.
    Upstream defaults are typically to `pandas.options.styler.sparse.columns`.
max_rows, max_cols : int, optional
    Specific max rows and cols. max_elements always take precedence in render.
blank : str
    Entry to top-left blank cells.
dxs : list[dict]
    The render dicts of the concatenated Stylers.

Returns
-------
d : dict
    The following structure: {uuid, table_styles, caption, head, body,
    cellstyle, table_attributes}
blank_value)rZ   r]   r_   zstyler.render.max_elementszstyler.render.max_rowszstyler.render.max_columnsheadindex_lengthsbodycellstyle_mapcellstyle_map_indexcellstyle_map_columns)	cellstylecellstyle_indexcellstyle_columns)r)   	selectorsr   r   zstyler.html.mathjax zclass="zclass="tex2jax_ignore z class="tex2jax_ignore"r^   )ra   rZ   format_table_stylesr]   r_   r   _get_trimming_maximumsr[   rC   rU   rV   r   rj   r   _translate_headerr   _get_level_lengthsrh   r   r   _translate_bodyr   getattrextendr^   replacerp   r   )rt   r   sparse_colsr   r   rD   r   r   max_elementsr   idx_lengthsr   ctx_mapskattrr)   r   mapr   
table_attrs                       r2   r   StylerRenderer._translate  s   H ;C"' II/0A0A0GRH||
 "">?'8Z8P-Q'8Z8S-T3		 		!!"
  	" %%k<	&$  )JJ0@0@
 	
/;/0JUK

  	  ))+J	&$  )4!8

  ~~'GA )0(;(A(A(C(C$E9 u+I>(C   HHaX ( BfIRZ(kN!!"[/2 ''$%  **
/00#)rJJ&'//	;ST
77
	$j12==((1A3s   8Kc                "   [        U R                  XU R                  5      nU R                  R                  R	                  5       nU R                  R                  R
                  S:X  a  U Vs/ s H  oU/PM     nn[        [        U6 5      n/ n[        U R                  5       H9  u  pxU(       d  U(       d  M  U R                  Xt4X#5      n	UR                  U	5        M;     U R                  R                  R                  (       a  [        R                  " U R                  R                  R                  6 (       aN  [!        U R"                  5      (       d4  U R$                  (       d#  U R'                  XBU5      n
UR                  U
5        U$ s  snf )a  
Build each <tr> within table <head> as a list

Using the structure:
     +----------------------------+---------------+---------------------------+
     |  index_blanks ...          | column_name_0 |  column_headers (level_0) |
  1) |       ..                   |       ..      |             ..            |
     |  index_blanks ...          | column_name_n |  column_headers (level_n) |
     +----------------------------+---------------+---------------------------+
  2) |  index_names (level_0 to level_n) ...      | column_blanks ...         |
     +----------------------------+---------------+---------------------------+

Parameters
----------
sparsify_cols : bool
    Whether column_headers section will add colspan attributes (>1) to elements.
max_cols : int
    Maximum number of columns to render. If exceeded will contain `...` filler.

Returns
-------
head : list
    The associated HTML elements needed for template rendering.
   )r   rV   ri   rC   tolistre   rj   zipr}   rg   _generate_col_header_rowr   rU   namescomany_not_noneallrf   rc   _generate_index_names_row)rt   sparsify_colsr   col_lengthsclabelsxr   r   hide
header_rowindex_names_rows              r2   r    StylerRenderer._translate_headers  s2   4 )LL-43F3F
 ))##**,99$$)$+,GqsGG,sG}% !3!34GA766hJ KK
# 5 IIOO!!  $))//"7"78(())))"<<;O KK(5 -s   .Fc                J   Uu  pE[        SU R                  S   U R                  S   S5      /U R                  R                  [	        U R
                  5      -
  S-
  -  nU R                  R                  R                  U   n[        SUc#  U R                  S    SU R                  S    U 3O"U R                  S    SU R                  S    U 3Ub  U R                  (       d  UOU R                  S   [        U R
                  5      (       + 5      /n/ n	S	n
[        XT   5       GH  u  p[        XU5      nU(       a  XR                  XK4S	5      -  n
U R                  U
UU	SU R                  S
    SU R                  S    U SU R                  S    35      (       a    GO[        SU R                  S
    SU R                  S    U SU R                  S    U 3UUU R                  XK4   " U5      UR                  XK4S	5      S:  a  SUR                  XK4S	5       S3OSS9nU R                   (       a(  U R                  S    U SU R                  S    U 3US'   U(       a  XK4U R"                  ;   a  U R"                  XK4   (       a  U R                  S    U SU R                  S    U 3US'   U R$                  ['        U R"                  XK4   5         R)                  U R                  S    U SU R                  S    U 35        U	R)                  U5        GM     Xh-   U	-   $ )a  
Generate the row containing column headers:

 +----------------------------+---------------+---------------------------+
 |  index_blanks ...          | column_name_i |  column_headers (level_i) |
 +----------------------------+---------------+---------------------------+

Parameters
----------
iter : tuple
    Looping variables from outer scope
max_cols : int
    Permissible number of columns
col_lengths :
    c

Returns
-------
list of elements
thrD   r   Tr    rB   r=   r   r<   r@   r>   	colspan=""r   display_value
attributes_id)_elementra   rU   re   sumrf   rC   rV   r   rd   r   r}   _is_visibleget_check_trimrs   r`   rm   r   tupler   )rt   iterr   r   r   r   index_blanksnamecolumn_namecolumn_headersvisible_col_countr   valueheader_element_visibleheader_elements                  r2   r   'StylerRenderer._generate_col_header_row  sU   0 
 T488G,dhh}.EtL
ZZ#d&6&6"77!;= yy  &&q) | xx()488G+<*=aSA HH\231TXXg5F4GsK $T-C-C XXm,(())
  "!"!'*-HA%0{%C"%!__aVQ%??!!88M*+1TXXg->,?s!88J'(*  %xx./q'1B0CA3axx's, &"991&A%H #vq1A5   :;1=N  }}*.((7*;)<QCq%@QRSQT'Ut$&Fd...$$QT**.((7*;)<QCq%@QRSQT'Ut$**51A1A!$1G+HIPPxx()!Adhhuo->qcB !!.1U .X )N::r1   c                D   Un[        U R                  R                  R                  5       VVs/ s HX  u  pV[	        SU R
                  S    SU R
                  S    U 3Uc  U R
                  S   OUU R                  U   (       + 5      PMZ     nnn/ nSn	U(       a  U R                  R                  S-
  n
[        XJ   5       H  u  p[[        XZU5      nU(       a  U	S-  n	U R                  U	UUSU R
                  S    SU R
                  S	    U SU R
                  S
    3U R
                  S   5      (       a    Xx-   $ UR                  [	        SU R
                  S    SU R
                  S	    U 3U R
                  S   XPR                  ;  5      5        M     Xx-   $ s  snnf )a  
Generate the row containing index names

 +----------------------------+---------------+---------------------------+
 |  index_names (level_0 to level_n) ...      | column_blanks ...         |
 +----------------------------+---------------+---------------------------+

Parameters
----------
iter : tuple
    Looping variables from outer scope
max_cols : int
    Permissible number of columns

Returns
-------
list of elements
r   r=   r   rB   r   r   r   rD   r>   r@   )r}   rC   rU   r   r   ra   rf   rV   re   r   r   r   ri   )rt   r   r   r   r   r   r   index_namescolumn_blanksr   
last_levelr   r   s                r2   r   (StylerRenderer._generate_index_names_row  s   ,  %TYY__%:%:;
 < 88L)*!DHHW,=+>qcB+/<'T$$Q''	 < 	 
 !!"--1J%g&9:)4QK)P&)%*%##%!xx()488E?*;A3a@T?UVHH]+   ** $$88G,-Qtxx.?sC/!4!44	 ;. **K
s   AFc                   U R                   R                  R                  5       n[        U R                   R                  [        5      (       d  U Vs/ s H  oU/PM     nn/ nSn[        U R                   R                  5       5       Vs/ s H  oS   U R                  ;  d  M  UPM     sn HK  u  pUS-  nU R                  UUUS5      (       a    U$ U R                  XU4X15      nUR                  U5        MM     U$ s  snf s  snf )as  
Build each <tr> within table <body> as a list

Use the following structure:
  +--------------------------------------------+---------------------------+
  |  index_header_0    ...    index_header_n   |  data_by_column   ...     |
  +--------------------------------------------+---------------------------+

Also add elements to the cellstyle_map for more efficient grouped elements in
<style></style> block

Parameters
----------
sparsify_index : bool
    Whether index_headers section will add rowspan attributes (>1) to elements.

Returns
-------
body : list
    The associated HTML elements needed for template rendering.
r   r   r?   )rC   rU   r   rR   r   r}   
itertuplesrh   r   _generate_body_rowr   )rt   r   r   r   rlabelsr   r   visible_row_countzr   row_tupbody_rows               r2   r   StylerRenderer._translate_bodyM  s   , ))//((*$))//:66$+,GqsGG,!" !5!5!78
8!aDHXHX<XA8
JA "!	   	 ..W%xH KK!
  ) -
s   C=	D#Dc           
         X:  aC  US:X  a!  UR                  U R                  U5      5        gUR                  [        XEUSSS95        gg)a_  
Indicates whether to break render loops and append a trimming indicator

Parameters
----------
count : int
    The loop count of previous visible items.
max : int
    The allowable rendered items in the loop.
obj : list
    The current render collection of the rendered items.
element : str
    The type of element to append in the case a trimming indicator is needed.
css : str, optional
    The css to add to the trimming indicator element.
value : str, optional
    The value of the elements display if necessary.

Returns
-------
result : bool
    Whether a trimming element was required and appended.
r?   Tr   r   F)r   _generate_trimmed_rowr   )rt   countmaxobjelementra   r   s          r2   r   StylerRenderer._check_trim{  sM    @ ;%

455c:;  

8G%"MNr1   c                   [        U R                  R                  R                  5       Vs/ s HS  n[	        SU R
                  S    SU R
                  S    U SU R
                  S    3SU R                  U   (       + SS9PMU     nn/ nS	n[        U R                  5       H  u  p&X R                  ;  nU(       a  US
-  nU R                  UUUSU R
                  S    SU R
                  S    SU R
                  S    35      (       a    X4-   $ UR                  [	        SU R
                  S    SU R
                  S    U SU R
                  S    3SUSS95        M     X4-   $ s  snf )z
When a render has too many rows we generate a trimming row containing "..."

Parameters
----------
max_cols : int
    Number of permissible columns

Returns
-------
list of elements
r   r;   r   rB   rA   ...r   r  r   r   tdrC   r@   r>   )rangerC   rU   re   r   ra   rf   r}   rV   ri   r   r   )rt   r   r   index_headersrC   r   r   data_element_visibles           r2   r  $StylerRenderer._generate_trimmed_row  s   0 499??223
 4 xx./q'1B0CA3axx
+,. $$Q''	 4 	 
 !"dll+DA#$,?,?#? #!Q&!!88F#$Adhhz&:%;1TXXj=Q<RS   ## KKxx'($((5/):1#Qtxx
?S>TU(! ,. ##O
s   AE#c                   Uu  pEn/ n[        Xd   5       GH  u  p[        XHU5      =(       a    U R                  U   (       + n
[        SU R                  S    SU R                  S    U SU R                  S    U 3U	U
U R
                  XH4   " U	5      UR                  X4S5      S:  a  SUR                  X4S5       S	3OS
S9nU R                  (       a(  U R                  S    U SU R                  S    U 3US'   U
(       a  XH4U R                  ;   a  U R                  XH4   (       a  U R                  S    U SU R                  S    U 3US'   U R                  [        U R                  XH4   5         R                  U R                  S    U SU R                  S    U 35        UR                  U5        GM     / nSn[        USS 5       GH  u  pXR                  ;  =(       a    X@R                  ;  nU(       a  US-  nU R                  UUUSU R                  S    SU R                  S    U SU R                  S    35      (       a    X|-   $ S
nXH4U R                  ;   a  SU R                  XH4   -   n[        SU R                  S    SU R                  S    U SU R                  S    U U 3U	US
U R                   XH4   " U	5      S9nU R                  (       a(  U R                  S    U SU R                  S    U 3US'   U(       a  XH4U R"                  ;   a  U R"                  XH4   (       a  U R                  S    U SU R                  S    U 3US'   U R$                  [        U R"                  XH4   5         R                  U R                  S    U SU R                  S    U 35        UR                  U5        GM     X|-   $ )a?  
Generate a regular row for the body section of appropriate format.

  +--------------------------------------------+---------------------------+
  |  index_header_0    ...    index_header_n   |  data_by_column   ...     |
  +--------------------------------------------+---------------------------+

Parameters
----------
iter : tuple
    Iterable from outer scope: row number, row data tuple, row index labels.
max_cols : int
    Number of permissible columns.
idx_lengths : dict
    A map of the sparsification structure of the index

Returns
-------
    list of elements
r   r;   r   rB   r?   r   r   	rowspan="r   r   r   r   r   Nr  rC   r@   r>   )r   r   )r}   r   rf   r   ra   rr   r   r`   rl   r   r   r   ri   rh   r   rn   rq   rk   r   )rt   r   r   r   r   r	  r  r  r   r   r   r   rC   r   r  clsdata_elements                    r2   r  !StylerRenderer._generate_body_row  s   4 #G!'*-HAA+.Jt7G7G7J3J # &xx./q'1B0CA3axx's, &"77?F #vq1A5   :;1=N  }} xx()!Adhhuo->qcB  'Fdnn,NN14( +/((7*;)<QCq%@QRSQT'Ut$((t~~ad/C)DELLxx()!Adhhuo->qcB   0G .J !"!'!"+.HA,,,J:J:J1J ! $!Q&!!88F#$Adhhuo%6qc488J;O:PQ  < ##7 Cv***D--ad33#xx'($((5/):1#Qxx's3%1 $"111&9%@
L }}(,'81TXXe_<MaS%QT"#$(((:txx~(,'81TXXe_<MaS%QT"""5!$#89@@xx's!DHHUO+<QC@ KK%S /V ##r1   c                8  ^ U R                   R                  nU[        U R                  5      -
  n[	        US   5       VVVVs/ s HH  u  pV[	        U5       VVs/ s H*  u  pxUS   (       d  M  0 UESU R
                  XWU-
  4   0EPM,     snnPMJ     snnnnUS'   U4S jmU4S jn	/ n
[        U	" U 5      US   5       H  u  pV[        U R                  5      (       a  / nOg[	        USU 5       VVs/ s HL  u  pxUS   S	:X  d  M  U R                  U   (       a  M&  0 UEUS   (       a  US
   OSU R                  XW4   S.EPMN     nnn[	        XcS 5       VVs/ s H2  u  pxUS   (       d  M  US   S:X  d  M  0 UESU R                  XW4   0EPM4     nnnU
R                  X-   5        M     XS'   US;  a  [        SU S35      eUGb0  SU;   a  US   (       a  [        W5      OSn[        [        5      US'   [        [        U R                   R                   5      5       Vs/ s H  oUU R"                  ;  d  M  UPM     nn[        U5       Vs/ s H  oR                  U   (       a  M  UPM     nn[	        U5       Hx  u  nn[	        U5       Hc  u  nnUUS-
  :X  a  SU;   a  M  US   R%                  UU4S5      nUc  M3  US   UU-      R                  SUS-    S[        U5      U-    S35        Me     Mz     ggs  snnf s  snnnnf s  snnf s  snnf s  snf s  snf )a  
Post-process the default render dict for the LaTeX template format.

Processing items included are:
  - Remove hidden columns from the non-headers part of the body.
  - Place cellstyles directly in td cells rather than use cellstyle_map.
  - Remove hidden indexes or reinsert missing th elements if part of multiindex
    or multirow sparsification (so that \multirow and \multicol work correctly).
r   
is_visibler   c                  > UR                  [        [        U R                  5      5       Vs/ s H  o3U R                  ;  d  M  X1-   PM     sn5        U[        U R                  5      -  nU R
                   H  nT" XAU5      nM     U$ s  snf )zH
Extract all visible row indices recursively from concatenated stylers.
)r   r  r[   rU   rh   rb   )r  nrow_indicesr   rb   _concatenated_visible_rowss        r2   r%  CStylerRenderer._translate_latex.<locals>._concatenated_visible_rows_  s|      %c#))n 5R 51#//9Q 5R SYYA # 0 0.|L !1H Ss   B	B	c                    > / nT" U SU5        U$ Nr   r*   )r  r$  r%  s     r2   concatenated_visible_rowsBStylerRenderer._translate_latex.<locals>.concatenated_visible_rowsk  s    %'K&sA{; r1   r   Ntyper   r   r   )r   r   r  )Nzall;dataz	all;indexzskip-last;datazskip-last;indexz`clines` value of zj is invalid. Should either be None or one of 'all;data', 'all;index', 'skip-last;data', 'skip-last;index'.rC   r   r   r   z	skip-lastr   z\cline{-})rU   re   r   rf   r}   rm   r   r   rl   rk   r   
ValueErrorr[   r   rj   r  rC   rh   r   )rt   r   r   index_levelsvisible_index_level_nr   r?   r   r>   r)  r   row_body_headersrow_body_cellsdata_lenvisible_row_indexesr   visible_index_levelsrnlvlnlvlidx_lenr%  s                        @r2   r   StylerRenderer._translate_latexJ  s|    zz)) ,s43C3C/D D $AfI.
 / (n,FA|$ U3TT%5%5a=R9R6R%ST,
 /
&	
		 3D91V9EFA 4##$$#%  #,C,>"?
$ #@Ft+ 594D4DQ4G |, *-_)=%)^^AD%9 #@ ! 
$ (M(:;;FA% 5*-f+*= 534TXXad^4;   KK(9:3 F4 &	  
 
 $VH -S T  .4.>1V9s>*RSH%d+AhK TYY__!56.6a4CSCS:S6   . !./.a6F6Fq6I. ! / ##67A!*+?!@ID#lQ..;&3H 044c1XtDG*(BL188'Qxq5I1J81S0TTVW "A 8 K
H
$4./sZ   K>
K8-K8
K>
1LL*LL+L6L L7LL'L8K>
c	                   [        USL USL USL US:H  USL USL USL USL 45      (       a  U R                  R                  5         U $ Uc  [        S5      OUn[	        U5      nU R
                  R                  U   n	[        U[        5      (       d  U	R                   V
s0 s H  oU_M     nn
U R                  R                  U	R                  5      nU R                  R                  U	R                  5      nU HF  n[        UR                  U R                  U   5      UUUUUUS9nU H  nXR                  X4'   M     MH     U $ s  sn
f )u  
Format the text display value of cells.

Parameters
----------
formatter : str, callable, dict or None
    Object to define how values are displayed. See notes.
subset : label, array-like, IndexSlice, optional
    A valid 2d input to `DataFrame.loc[<subset>]`, or, in the case of a 1d input
    or single key, to `DataFrame.loc[:, <subset>]` where the columns are
    prioritised, to limit ``data`` to *before* applying the function.
na_rep : str, optional
    Representation for missing values.
    If ``na_rep`` is None, no special formatting is applied.
precision : int, optional
    Floating point precision to use for display purposes, if not determined by
    the specified ``formatter``.

    .. versionadded:: 1.3.0

decimal : str, default "."
    Character used as decimal separator for floats, complex and integers.

    .. versionadded:: 1.3.0

thousands : str, optional, default None
    Character used as thousands separator for floats, complex and integers.

    .. versionadded:: 1.3.0

escape : str, optional
    Use 'html' to replace the characters ``&``, ``<``, ``>``, ``'``, and ``"``
    in cell display string with HTML-safe sequences.
    Use 'latex' to replace the characters ``&``, ``%``, ``$``, ``#``, ``_``,
    ``{``, ``}``, ``~``, ``^``, and ``\`` in the cell display string with
    LaTeX-safe sequences.
    Use 'latex-math' to replace the characters the same way as in 'latex' mode,
    except for math substrings, which either are surrounded
    by two characters ``$`` or start with the character ``\(`` and
    end with ``\)``. Escaping is done before ``formatter``.

    .. versionadded:: 1.3.0

hyperlinks : {"html", "latex"}, optional
    Convert string patterns containing https://, http://, ftp:// or www. to
    HTML <a> tags as clickable URL hyperlinks if "html", or LaTeX \href
    commands if "latex".

    .. versionadded:: 1.4.0

Returns
-------
Styler

See Also
--------
Styler.format_index: Format the text display value of index labels.

Notes
-----
This method assigns a formatting function, ``formatter``, to each cell in the
DataFrame. If ``formatter`` is ``None``, then the default formatter is used.
If a callable then that function should take a data value as input and return
a displayable representation, such as a string. If ``formatter`` is
given as a string this is assumed to be a valid Python format specification
and is wrapped to a callable as ``string.format(x)``. If a ``dict`` is given,
keys should correspond to column names, and values should be string or
callable, as above.

The default formatter currently expresses floats and complex numbers with the
pandas display precision unless using the ``precision`` argument here. The
default formatter does not adjust the representation of missing values unless
the ``na_rep`` argument is used.

The ``subset`` argument defines which region to apply the formatting function
to. If the ``formatter`` argument is given in dict form but does not include
all columns within the subset then these columns will have the default formatter
applied. Any columns in the formatter dict excluded from the subset will
be ignored.

When using a ``formatter`` string the dtypes must be compatible, otherwise a
`ValueError` will be raised.

When instantiating a Styler, default formatting can be applied be setting the
``pandas.options``:

  - ``styler.format.formatter``: default None.
  - ``styler.format.na_rep``: default None.
  - ``styler.format.precision``: default 6.
  - ``styler.format.decimal``: default ".".
  - ``styler.format.thousands``: default None.
  - ``styler.format.escape``: default None.

.. warning::
   `Styler.format` is ignored when using the output format `Styler.to_excel`,
   since Excel and Python have inherrently different formatting structures.
   However, it is possible to use the `number-format` pseudo CSS attribute
   to force Excel permissible formatting. See examples.

Examples
--------
Using ``na_rep`` and ``precision`` with the default ``formatter``

>>> df = pd.DataFrame([[np.nan, 1.0, 'A'], [2.0, np.nan, 3.0]])
>>> df.style.format(na_rep='MISS', precision=3)  # doctest: +SKIP
        0       1       2
0    MISS   1.000       A
1   2.000    MISS   3.000

Using a ``formatter`` specification on consistent column dtypes

>>> df.style.format('{:.2f}', na_rep='MISS', subset=[0,1])  # doctest: +SKIP
        0      1          2
0    MISS   1.00          A
1    2.00   MISS   3.000000

Using the default ``formatter`` for unspecified columns

>>> df.style.format({0: '{:.2f}', 1: '£ {:.1f}'}, na_rep='MISS', precision=1)
...  # doctest: +SKIP
         0      1     2
0    MISS   £ 1.0     A
1    2.00    MISS   3.0

Multiple ``na_rep`` or ``precision`` specifications under the default
``formatter``.

>>> (df.style.format(na_rep='MISS', precision=1, subset=[0])
...     .format(na_rep='PASS', precision=2, subset=[1, 2]))  # doctest: +SKIP
        0      1      2
0    MISS   1.00      A
1     2.0   PASS   3.00

Using a callable ``formatter`` function.

>>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
>>> df.style.format({0: '{:.1f}', 2: func}, precision=4, na_rep='MISS')
...  # doctest: +SKIP
        0        1        2
0    MISS   1.0000   STRING
1     2.0     MISS    FLOAT

Using a ``formatter`` with HTML ``escape`` and ``na_rep``.

>>> df = pd.DataFrame([['<div></div>', '"A&B"', None]])
>>> s = df.style.format(
...     '<a href="a.com/{0}">{0}</a>', escape="html", na_rep="NA"
...     )
>>> s.to_html()  # doctest: +SKIP
...
<td .. ><a href="a.com/&lt;div&gt;&lt;/div&gt;">&lt;div&gt;&lt;/div&gt;</a></td>
<td .. ><a href="a.com/&#34;A&amp;B&#34;">&#34;A&amp;B&#34;</a></td>
<td .. >NA</td>
...

Using a ``formatter`` with ``escape`` in 'latex' mode.

>>> df = pd.DataFrame([["123"], ["~ ^"], ["$%#"]])
>>> df.style.format("\\textbf{{{}}}", escape="latex").to_latex()
...  # doctest: +SKIP
\begin{tabular}{ll}
 & 0 \\
0 & \textbf{123} \\
1 & \textbf{\textasciitilde \space \textasciicircum } \\
2 & \textbf{\$\%\#} \\
\end{tabular}

Applying ``escape`` in 'latex-math' mode. In the example below
we enter math mode using the character ``$``.

>>> df = pd.DataFrame([[r"$\sum_{i=1}^{10} a_i$ a~b $\alpha \
...     = \frac{\beta}{\zeta^2}$"], ["%#^ $ \$x^2 $"]])
>>> df.style.format(escape="latex-math").to_latex()
...  # doctest: +SKIP
\begin{tabular}{ll}
 & 0 \\
0 & $\sum_{i=1}^{10} a_i$ a\textasciitilde b $\alpha = \frac{\beta}{\zeta^2}$ \\
1 & \%\#\textasciicircum \space $ \$x^2 $ \\
\end{tabular}

We can use the character ``\(`` to enter math mode and the character ``\)``
to close math mode.

>>> df = pd.DataFrame([[r"\(\sum_{i=1}^{10} a_i\) a~b \(\alpha \
...     = \frac{\beta}{\zeta^2}\)"], ["%#^ \( \$x^2 \)"]])
>>> df.style.format(escape="latex-math").to_latex()
...  # doctest: +SKIP
\begin{tabular}{ll}
 & 0 \\
0 & \(\sum_{i=1}^{10} a_i\) a\textasciitilde b \(\alpha
= \frac{\beta}{\zeta^2}\) \\
1 & \%\#\textasciicircum \space \( \$x^2 \) \\
\end{tabular}

If we have in one DataFrame cell a combination of both shorthands
for math formulas, the shorthand with the sign ``$`` will be applied.

>>> df = pd.DataFrame([[r"\( x^2 \)  $x^2$"], \
...     [r"$\frac{\beta}{\zeta}$ \(\frac{\beta}{\zeta}\)"]])
>>> df.style.format(escape="latex-math").to_latex()
...  # doctest: +SKIP
\begin{tabular}{ll}
 & 0 \\
0 & \textbackslash ( x\textasciicircum 2 \textbackslash )  $x^2$ \\
1 & $\frac{\beta}{\zeta}$ \textbackslash (\textbackslash
frac\{\textbackslash beta\}\{\textbackslash zeta\}\textbackslash ) \\
\end{tabular}

Pandas defines a `number-format` pseudo CSS attribute instead of the `.format`
method to create `to_excel` permissible formatting. Note that semi-colons are
CSS protected characters but used as separators in Excel's format string.
Replace semi-colons with the section separator character (ASCII-245) when
defining the formatting here.

>>> df = pd.DataFrame({"A": [1, 0, -1]})
>>> pseudo_css = "number-format: 0§[Red](0)§-§@;"
>>> filename = "formatted_file.xlsx"
>>> df.style.map(lambda v: pseudo_css).to_excel(filename) # doctest: +SKIP

.. figure:: ../../_static/style/format_excel_css.png
N.na_reprJ   decimal	thousandsr"   
hyperlinks)r   rq   r   slicenon_reducing_slicerC   locrR   dictrV   get_indexer_forrU   _maybe_wrap_formatterr   )rt   	formattersubsetr>  rJ   r?  r@  r"   rA  rC   r>   cisrisciformat_funcris                   r2   formatStylerRenderer.format  sR   P T!$T!3T!$$d"	
 
 %%'K &tF#F+yy}}V$)T**37<<@<Ci<I@ll**4<<8jj((4B/dll2./##%K 0;##RH-   # As   Ec
                   U R                   R                  U5      nUS:X  a  U R                  U R                  pOU R                  U R
                  p[        X;5      n[        USL USL USL US:H  USL USL USL U	SL 45      (       a  U
R                  5         U $ [        U[        5      (       d  U Vs0 s H  o3U_M     nnO4UR                  5        VVs0 s H  u  p=UR                  U5      U_M     nnnU H]  n[        UR                  U5      UUUUUU	S9n[        [!        U5      5       Vs/ s H  nUS:X  a  UU4OUU4PM     sn H  nXU'   M	     M_     U $ s  snf s  snnf s  snf )a[  
Format the text display value of index labels or column headers.

.. versionadded:: 1.4.0

Parameters
----------
formatter : str, callable, dict or None
    Object to define how values are displayed. See notes.
axis : {0, "index", 1, "columns"}
    Whether to apply the formatter to the index or column headers.
level : int, str, list
    The level(s) over which to apply the generic formatter.
na_rep : str, optional
    Representation for missing values.
    If ``na_rep`` is None, no special formatting is applied.
precision : int, optional
    Floating point precision to use for display purposes, if not determined by
    the specified ``formatter``.
decimal : str, default "."
    Character used as decimal separator for floats, complex and integers.
thousands : str, optional, default None
    Character used as thousands separator for floats, complex and integers.
escape : str, optional
    Use 'html' to replace the characters ``&``, ``<``, ``>``, ``'``, and ``"``
    in cell display string with HTML-safe sequences.
    Use 'latex' to replace the characters ``&``, ``%``, ``$``, ``#``, ``_``,
    ``{``, ``}``, ``~``, ``^``, and ``\`` in the cell display string with
    LaTeX-safe sequences.
    Escaping is done before ``formatter``.
hyperlinks : {"html", "latex"}, optional
    Convert string patterns containing https://, http://, ftp:// or www. to
    HTML <a> tags as clickable URL hyperlinks if "html", or LaTeX \href
    commands if "latex".

Returns
-------
Styler

See Also
--------
Styler.format: Format the text display value of data cells.

Notes
-----
This method assigns a formatting function, ``formatter``, to each level label
in the DataFrame's index or column headers. If ``formatter`` is ``None``,
then the default formatter is used.
If a callable then that function should take a label value as input and return
a displayable representation, such as a string. If ``formatter`` is
given as a string this is assumed to be a valid Python format specification
and is wrapped to a callable as ``string.format(x)``. If a ``dict`` is given,
keys should correspond to MultiIndex level numbers or names, and values should
be string or callable, as above.

The default formatter currently expresses floats and complex numbers with the
pandas display precision unless using the ``precision`` argument here. The
default formatter does not adjust the representation of missing values unless
the ``na_rep`` argument is used.

The ``level`` argument defines which levels of a MultiIndex to apply the
method to. If the ``formatter`` argument is given in dict form but does
not include all levels within the level argument then these unspecified levels
will have the default formatter applied. Any levels in the formatter dict
specifically excluded from the level argument will be ignored.

When using a ``formatter`` string the dtypes must be compatible, otherwise a
`ValueError` will be raised.

.. warning::
   `Styler.format_index` is ignored when using the output format
   `Styler.to_excel`, since Excel and Python have inherrently different
   formatting structures.
   However, it is possible to use the `number-format` pseudo CSS attribute
   to force Excel permissible formatting. See documentation for `Styler.format`.

Examples
--------
Using ``na_rep`` and ``precision`` with the default ``formatter``

>>> df = pd.DataFrame([[1, 2, 3]], columns=[2.0, np.nan, 4.0])
>>> df.style.format_index(axis=1, na_rep='MISS', precision=3)  # doctest: +SKIP
    2.000    MISS   4.000
0       1       2       3

Using a ``formatter`` specification on consistent dtypes in a level

>>> df.style.format_index('{:.2f}', axis=1, na_rep='MISS')  # doctest: +SKIP
     2.00   MISS    4.00
0       1      2       3

Using the default ``formatter`` for unspecified levels

>>> df = pd.DataFrame([[1, 2, 3]],
...     columns=pd.MultiIndex.from_arrays([["a", "a", "b"],[2, np.nan, 4]]))
>>> df.style.format_index({0: lambda v: v.upper()}, axis=1, precision=1)
...  # doctest: +SKIP
               A       B
      2.0    nan     4.0
0       1      2       3

Using a callable ``formatter`` function.

>>> func = lambda s: 'STRING' if isinstance(s, str) else 'FLOAT'
>>> df.style.format_index(func, axis=1, na_rep='MISS')
...  # doctest: +SKIP
          STRING  STRING
    FLOAT   MISS   FLOAT
0       1      2       3

Using a ``formatter`` with HTML ``escape`` and ``na_rep``.

>>> df = pd.DataFrame([[1, 2, 3]], columns=['"A"', 'A&B', None])
>>> s = df.style.format_index('$ {0}', axis=1, escape="html", na_rep="NA")
...  # doctest: +SKIP
<th .. >$ &#34;A&#34;</th>
<th .. >$ A&amp;B</th>
<th .. >NA</td>
...

Using a ``formatter`` with LaTeX ``escape``.

>>> df = pd.DataFrame([[1, 2, 3]], columns=["123", "~", "$%#"])
>>> df.style.format_index("\\textbf{{{}}}", escape="latex", axis=1).to_latex()
...  # doctest: +SKIP
\begin{tabular}{lrrr}
{} & {\textbf{123}} & {\textbf{\textasciitilde }} & {\textbf{\$\%\#}} \\
0 & 1 & 2 & 3 \\
\end{tabular}
r   Nr<  r=  )rC   _get_axis_numberrr   rU   rs   rV   refactor_levelsr   r   rR   rE  r   _get_level_numberrG  r   r  r[   )rt   rH  axisrB   r>  rJ   r?  r@  r"   rA  display_funcs_r  levels_
formatter_r8  rM  r   idxs                     r2   format_indexStylerRenderer.format_index  s   \ yy))$/19"&";";TZZC"&"="=t||C!%-T!T!3T!$$d"	
 
   "K)T**7>?we	)wI?I *3):):%E %%e,j8):  
 C/c"##%K FK3s8_U_DAICC8;_U&1s# V  + @  Vs   0EE,E#c                V   U R                   R                  U5      nUS:X  a/  U R                  U R                  pTU R                  U R
                  pvO.U R                  U R                  pTU R                  U R                  pv[        U5      [        [        U5      5      -
  n[        U5      U:w  a  [        SU S35      eUc0  [        UR                  5       V	s/ s H  oU	   (       a  M  U	PM     nn	[        X55      n
S n[!        [        [        U5      5       V	s/ s H  oU;  d  M
  U	PM     sn	5       Hh  u  p[        U
5      S:X  a#  US:X  a  XS   4OU
S   U	4n[#        XU   S9XM'   M7  [!        U
5       H"  u  pUS:X  a  X4OX4n[#        XU   U   S9XM'   M$     Mj     U $ s  sn	f s  sn	f )aY  
Relabel the index, or column header, keys to display a set of specified values.

.. versionadded:: 1.5.0

Parameters
----------
labels : list-like or Index
    New labels to display. Must have same length as the underlying values not
    hidden.
axis : {"index", 0, "columns", 1}
    Apply to the index or columns.
level : int, str, list, optional
    The level(s) over which to apply the new labels. If `None` will apply
    to all levels of an Index or MultiIndex which are not hidden.

Returns
-------
Styler

See Also
--------
Styler.format_index: Format the text display value of index or column headers.
Styler.hide: Hide the index, column headers, or specified data from display.

Notes
-----
As part of Styler, this method allows the display of an index to be
completely user-specified without affecting the underlying DataFrame data,
index, or column headers. This means that the flexibility of indexing is
maintained whilst the final display is customisable.

Since Styler is designed to be progressively constructed with method chaining,
this method is adapted to react to the **currently specified hidden elements**.
This is useful because it means one does not have to specify all the new
labels if the majority of an index, or column headers, have already been hidden.
The following produce equivalent display (note the length of ``labels`` in
each case).

.. code-block:: python

    # relabel first, then hide
    df = pd.DataFrame({"col": ["a", "b", "c"]})
    df.style.relabel_index(["A", "B", "C"]).hide([0,1])
    # hide first, then relabel
    df = pd.DataFrame({"col": ["a", "b", "c"]})
    df.style.hide([0,1]).relabel_index(["C"])

This method should be used, rather than :meth:`Styler.format_index`, in one of
the following cases (see examples):

  - A specified set of labels are required which are not a function of the
    underlying index keys.
  - The function of the underlying index keys requires a counter variable,
    such as those available upon enumeration.

Examples
--------
Basic use

>>> df = pd.DataFrame({"col": ["a", "b", "c"]})
>>> df.style.relabel_index(["A", "B", "C"])  # doctest: +SKIP
     col
A      a
B      b
C      c

Chaining with pre-hidden elements

>>> df.style.hide([0,1]).relabel_index(["C"])  # doctest: +SKIP
     col
C      c

Using a MultiIndex

>>> midx = pd.MultiIndex.from_product([[0, 1], [0, 1], [0, 1]])
>>> df = pd.DataFrame({"col": list(range(8))}, index=midx)
>>> styler = df.style  # doctest: +SKIP
          col
0  0  0     0
      1     1
   1  0     2
      1     3
1  0  0     4
      1     5
   1  0     6
      1     7
>>> styler.hide((midx.get_level_values(0)==0)|(midx.get_level_values(1)==0))
...  # doctest: +SKIP
>>> styler.hide(level=[0,1])  # doctest: +SKIP
>>> styler.relabel_index(["binary6", "binary7"])  # doctest: +SKIP
          col
binary6     6
binary7     7

We can also achieve the above by indexing first and then re-labeling

>>> styler = df.loc[[(1,1,0), (1,1,1)]].style
>>> styler.hide(level=[0,1]).relabel_index(["binary6", "binary7"])
...  # doctest: +SKIP
          col
binary6     6
binary7     7

Defining a formatting function which uses an enumeration counter. Also note
that the value of the index key is passed in the case of string labels so it
can also be inserted into the label, using curly brackets (or double curly
brackets if the string if pre-formatted),

>>> df = pd.DataFrame({"samples": np.random.rand(10)})
>>> styler = df.loc[np.random.randint(0,10,3)].style
>>> styler.relabel_index([f"sample{i+1} ({{}})" for i in range(3)])
...  # doctest: +SKIP
                 samples
sample1 (5)     0.315811
sample2 (0)     0.495941
sample3 (2)     0.067946
r   zS``labels`` must be of length equal to the number of visible labels along ``axis`` (z).c                R    [        U[        5      (       a  UR                  U 5      $ U$ N)rR   r&   rO  )r   r   s     r2   alias_,StylerRenderer.relabel_index.<locals>.alias_	  s"    %%%||A&Lr1   r   )r   )rC   rR  rr   rU   rh   rf   rs   rV   ri   rg   r[   setr.  r  re   rS  r}   r   )rt   labelsrU  rB   rV  r  hidden_labelshidden_lvlsvisible_lenr   rW  r_  airY  ajr8  s                   r2   relabel_indexStylerRenderer.relabel_index{  s   x yy))$/19"&";";TZZC)-)9)94;K;K;"&"="=t||C)-)<)<d>P>P;#hS%7!88v;+%22=bB 
 = %ckk 2I 21a.Q 2EI!%-	
 5S?U?a}>T?UVEB7|q )-q!*oQ&-f2J&G#(1GB&*ai1(cXC*1&r
2*ON'  2 W # J  Vs   F!(F!	F&&F&)rq   rs   rr   ro   r_   rn   r`   r   r   r   rV   rb   ra   rk   rm   rl   rC   ri   rh   rd   rg   rf   rc   rU   r^   r]   rp   rZ   r\   )N   NNNTN)rC   zDataFrame | SeriesrZ   
str | Noner\   rW   r]   zCSSStyles | Noner^   rk  r_   zstr | tuple | list | Noner`   boolrJ   
int | NonereturnNone)NNr   )
r   rl  r   rl  r   rm  r   rm  rD   r&   )NN)
r   rl  r   rl  r   rm  r   rm  rn  r&   )r   rl  r   rl  r   rk  rn  r&   )NNr   N)r   rl  r   rl  r   rm  r   rm  rD   r&   r   zlist[dict] | None)r   rl  r   rW   )r   r   r   rW   r   rE  )r   rE  r   rW   r   rW   )Nr  )r  rW   r  rW   r  rj   r  r&   ra   rk  r   r&   rn  rl  )r   rW   rn  rj   )r   r   r   rW   r   rE  )r   rE  r   rk  rn  ro  )NNNNr<  NNN)rH  ExtFormatter | NonerI  zSubset | Noner>  rk  rJ   rm  r?  r&   r@  rk  r"   rk  rA  rk  rn  r4   )	Nr   NNNr<  NNN)rH  rp  rU  r   rB   Level | list[Level] | Noner>  rk  rJ   rm  r?  r&   r@  rk  r"   rk  rA  rk  rn  r4   )r   N)rb  zSequence | IndexrU  r   rB   rq  rn  r4   )#r+   r,   r-   r.   __doc__r   PackageLoaderr7   Environmentenvget_templater   r   r   r   r   ru   r~   r   r   r   r|   r   r   r   r   r   r   r  r  r   rO  rZ  rh  r0   r*   r1   r2   r4   r4   C   si    !!(,BCF


F

=C$$Z0M**+;<**+;<%%k2N&&|4O
  )-'+-1 $AR AR AR 	AR
 'AR %AR +AR AR AR 
ARN  $#++ + 	+
 + +b  $#

 
 	

 
 

(/ /26/@J/	/&  $#00 0 	0
 0 
0*  $#!%nn n 	n
 n n n`:x];];(+];:>];~=+=+(+=+:>=+~,h && & 	&
 & & & 
&P4$lo$o$ o$ 	o$bdP *. $! $ $!!%M&M M 	M
 M M M M M 
Mb *.,0! $ $!!%z&z z *	z
 z z z z z z 
z~ ,0	\ \ \ *	\
 
\ \r1   r4   c                (    SU;  a  X$S'   U UUUS.UE$ )zU
Template to return container with information for a <td></td> or <th></th> element.
r   )r+  r   classr!  r*   )html_element
html_classr   r!  r   s        r2   r   r     s4     f$"' 	
  r1   c                   ^ U4S jnU(       a	  X:  a  UOU n U(       a	  X:  a  UOUnX-  U:  a  U" X5      u  pX-  U:  a  M  X4$ )a  
Recursively reduce the number of rows and columns to satisfy max elements.

Parameters
----------
rn, cn : int
    The number of input rows / columns
max_elements : int
    The number of allowable elements
max_rows, max_cols : int, optional
    Directly specify an initial maximum rows or columns before compression.
scaling_factor : float
    Factor at which to reduce the number of rows / columns to fit.

Returns
-------
rn, cn : tuple
    New rn and cn values that satisfy the max_elements constraint
c                N   > X:  a  U [        UT-  5      4$ [        U T-  5      U4$ r^  )rW   )r6  cnscaling_factors     r2   
scale_down*_get_trimming_maximums.<locals>.scale_downK  s2    8s2.///rN*+R//r1   r*   )r6  r}  r   r   r   r~  r  s        ` r2   r   r   /  sQ    80 XBXB
'L
 B# 'L
  6Mr1   c                   [        U [        5      (       a  U R                  [        R                  SS9nOU R                  SS9nUc  / n0 n[        U [        5      (       d$  [        U5       H  u  pgXc;  d  M  SUSU4'   M     U$ [        U5       H  u  phSn	[        U5       H  u  pX:  a    M  U(       d  X;  a  SXVU
4'   U	S-  n	M&  M(  U[        R                  La  X;  a  U
nSXVU4'   U	S-  n	MO  U[        R                  La
  U
nSXVU4'   Ml  X;  d  Ms  U	S-  n	X:  a    M  XVW4   S:X  a
  U
nSXVU4'   M  XVU4==   S-  ss'   M     M     UR                  5        VVs0 s H  u  pUS:  d  M  X_M     nnnU$ s  snnf )a  
Given an index, find the level length for each element.

Parameters
----------
index : Index
    Index or columns to determine lengths of each element
sparsify : bool
    Whether to hide or show each distinct element in a MultiIndex
max_index : int
    The maximum number of elements to analyse along the index due to trimming
hidden_elements : sequence of int
    Index positions of elements hidden from display in the index affecting
    length

Returns
-------
Dict :
    Result is a dictionary of (level, initial_position): span
F)sparsifyinclude_names)include_namer   r   )rR   r   _format_multir   
no_default_format_flatr}   r   )rU   r  	max_indexhidden_elementslevelslengthsr   r   r8  r  jr?   
last_labelr  lengthnon_zero_lengthss                   r2   r   r   \  s   4 %$$$$cnnE$R###7GeZ((!&)HA'"#A * F#nFA ,+&'GFO%*% , S^^+!2J
+,J(!Q&!CNN* 
+,J()!Q&!$0z?+q0!"J/0G
O, 
O,1,; % $D 07}}/>OG&A+   	s   E9.E9c                    X4U;   $ )z'
Index -> {(idx_row, idx_col): bool}).
r*   )idx_rowidx_colr  s      r2   r   r     s     ((r1   c                z    U  VVs/ s H&  nUS   R                  S5        H
  nX!S   S.PM     M(     snn$ s  snnf )z
looks for multiple CSS selectors and separates them:
[{'selector': 'td, th', 'props': 'a:v;'}]
    ---> [{'selector': 'td', 'props': 'a:v;'},
          {'selector': 'th', 'props': 'a:v;'}]
r'   ,r)   r'   r)   )split)stylescss_dictr'   s      r2   r   r     sN     H ,2237H (9:7 	;  s   -7c                    [        U 5      (       d  [        U 5      (       a  U(       a  U SU S3 $ U SU S3 $ [        U 5      (       a  U(       a  U S $ [        U 5      $ U $ )a}  
Format the display of a value

Parameters
----------
x : Any
    Input variable to be formatted
precision : Int
    Floating point precision used if ``x`` is float or complex.
thousands : bool, default False
    Whether to group digits with thousands separated with ",".

Returns
-------
value : Any
    Matches input type, or string if input is float or complex or int with sep.
z,.fr<  r  )r   r   r   r&   )r   rJ   r@  s      r2   rL   rL     s_    $ {{jmm(1!Byk?#K!Ai[>9JK	A$!A0#a&0Hr1   c                   ^ ^^ UU U4S jnU$ )z
Takes a string formatting function and wraps logic to deal with thousands and
decimal parameters, in the case that they are non-standard and that the input
is a (float, complex, int).
c                  > [        U 5      (       d   [        U 5      (       d  [        U 5      (       a  TS:w  aA  Tb>  TS:w  a8  T" U 5      R                  SS5      R                  ST5      R                  ST5      $ TS:w  a!  Tb  TS:X  a  T" U 5      R                  ST5      $ TS:X  a!  Tb  TS:w  a  T" U 5      R                  ST5      $ T" U 5      $ )Nr<  r  u   §_§-)r   r   r   r   )r   r?  rH  r@  s    r2   wrapper(_wrap_decimal_thousands.<locals>.wrapper  s    A;;*Q--:a==#~)"7I<LaLWS(+WS'*WXy1	 CY%6)s:J |++C99CI$9i3>N |++C;;|r1   r*   )rH  r?  r@  r  s   ``` r2   _wrap_decimal_thousandsr    s     Nr1   c                    [        U [        5      (       aA  US:X  a  [        U 5      $ US:X  a  [        U 5      $ US:X  a  [	        U 5      $ [        SU 35      eU $ )z/if escaping: only use on str, else return inputhtmllatexz
latex-mathz@`escape` only permitted in {'html', 'latex', 'latex-math'}, got )rR   r&   escape_html_escape_latex_escape_latex_mathr.  )r   r"   s     r2   _str_escaper    sj    !SVq>!w ##|#%a((H  Hr1   c                   ^ [        U [        5      (       a;  US:X  a  SmOUS:X  a  SmO[        S5      eSn[        R                  " UU4S jU 5      $ U $ )zMuses regex to detect a common URL pattern and converts to href tag in format.r  z%<a href="{0}" target="_blank">{0}</a>r  z\href{{{0}}}{{{0}}}z3``hyperlinks`` format can only be 'html' or 'latex'zE((http|ftp)s?:\/\/|www.)[\w/\-?=%.:@]+\.[\w/\-&?=%.,':;~!@#$*()\[\]]+c                D   > TR                  U R                  S5      5      $ r(  )rO  group)mhrefs    r2   rM   _render_href.<locals>.<lambda>  s    T[[%<r1   )rR   r&   r.  resub)r   rO  patr  s      @r2   _render_hrefr    sT    !SV:Dw)DRSSVvvc<a@@Hr1   c                h  ^ ^^^^^	^
 [        T [        5      (       a  U 4S jmON[        T 5      (       a  T mO;T c!  Uc  [        S5      OUn[	        [
        X$SLS9mO[        S[        T 5       35      eTb  UU4S jnOTnUS:w  d	  Ub  US:w  a  [        XsUS	9m	OUm	Tb  U	U4S
 jm
OT	m
Tc  T
$ U
U4S j$ )z
Allows formatters to be expressed as str, callable or None, where None returns
a default formatting function. wraps with na_rep, and precision where they are
available.
c                &   > TR                  U 5      $ r^  rO  )r   rH  s    r2   rM   '_maybe_wrap_formatter.<locals>.<lambda>%  s    9++A.r1   NrF   )rJ   r@  z*'formatter' expected str or callable, got c                $   > T" [        U TS95      $ )Nr!   )r  )r   r"   func_0s    r2   rM   r  4  s    6+a"?@r1   r<  r  )r?  r@  c                $   > T" [        U TS95      $ )Nr  )r  )r   func_2rA  s    r2   rM   r  @  s    6,q"DEr1   c                4   > [        U 5      SL a  T$ T" U 5      $ )NT)r   )r   func_3r>  s    r2   rM   r  H  s    DGtOC&)Cr1   )	rR   r&   callabler   r   rL   rT   r+  r  )rH  r>  rJ   r?  r@  r"   rA  func_1r  r  r  s   ``   `` @@@r2   rG  rG    s     )S!!.	)				5>5FJ01I 	 )QU@U
 DT)_DUVWW @ #~)/I4D(IV E ~CCr1   c                N   [         [        R                  [        [        [
        4n[        X5      (       a  [        SS2U 4   n SS jn[        U 5      (       d  [        U [        5      (       d  U //n O%U /n O!U  Vs/ s H  o2" U5      (       a  UOU/PM     n n[        U 5      $ s  snf )z
Ensure that a slice doesn't reduce to a Series or Scalar.

Any user-passed `subset` should have this called on it
to make sure we're always working with DataFrames.
Nc                    [        U [        5      (       a  [        S U  5       5      $ [        U [        5      =(       d    [	        U 5      $ )z[
Returns
-------
bool
    True if slice does *not* reduce,
    False if `part` is a tuple.
c              3  f   #    U  H'  n[        U[        5      =(       d    [        U5      v   M)     g 7fr^  )rR   rB  r   ).0ss     r2   	<genexpr>3non_reducing_slice.<locals>.pred.<locals>.<genexpr>d  s#     O$Q
1e,?Q?$s   /1)rR   r   anyrB  r   )parts    r2   pred non_reducing_slice.<locals>.predX  s9     dE""O$OOOdE*@l4.@@r1   rn  rl  )r   npndarrayr   rj   r&   rR   r   r   rB  r   )slice_kindsr  ps       r2   rC  rC  K  s     

E45E&  AvI&A  &%((hZF XF 288AtAww!QC'8= 9s   :B"c                n   [        U [        5      (       a}  U R                  S5      n U Vs/ s H]  nUR                  5       S:w  d  M  UR                  S5      S   R                  5       UR                  S5      S   R                  5       4PM_     sn$ U $ s  snf ! [         a    [        SU  S35      ef = f)z
Convert css-string to sequence of tuples format if needed.
'color:red; border:1px solid black;' -> [('color', 'red'),
                                         ('border','1px solid red')]
;r   :r   r   zSStyles supplied as string must follow CSS rule formats, for example 'attr: val;'. 'z' was given.)rR   r&   r  strip
IndexErrorr.  )styler  r   s      r2   maybe_convert_css_to_tuplesr  v  s     %KK
	 A779? Ca&&(!''#,q/*?*?*AB  L
  	..3WLB 	s#   B BABB B B4c                   U c   [        [        UR                  5      5      nU$ [        U [        5      (       a  U /nU$ [        U [
        5      (       a  UR                  U 5      /nU$ [        U [         5      (       a:  U  Vs/ s H+  n[        U[        5      (       d  UR                  U5      OUPM-     nnU$ [        S5      es  snf )a,  
Returns a consistent levels arg for use in ``hide_index`` or ``hide_columns``.

Parameters
----------
level : int, str, list
    Original ``level`` arg supplied to above methods.
obj:
    Either ``self.index`` or ``self.columns``

Returns
-------
list : refactored arg with a list of levels to hide
z4`level` must be of type `int`, `str` or list of such)rj   r  re   rR   rW   r&   rT  r.  )rB   r  rW  levs       r2   rS  rS    s    $ }!%"45 N 
E3		' N 
E3		((/0 N 
E4	 	  
 /9c.B.BC!!#&K 	 
 N OPP
s    2Cc                  l    \ rS rSrSr/ SQS\" 5       4       SS jjr\S 5       rSS jr	SS jr
S	rg
)Tooltipsi  aA  
An extension to ``Styler`` that allows for and manipulates tooltips on hover
of ``<td>`` cells in the HTML result.

Parameters
----------
css_name: str, default "pd-t"
    Name of the CSS class that controls visualisation of tooltips.
css_props: list-like, default; see Notes
    List of (attr, value) tuples defining properties of the CSS class.
tooltips: DataFrame, default empty
    DataFrame of strings aligned with underlying Styler data for tooltip
    display.

Notes
-----
The default properties for the tooltip CSS class are:

    - visibility: hidden
    - position: absolute
    - z-index: 1
    - background-color: black
    - color: white
    - transform: translate(-20px, -20px)

Hidden visibility is a key prerequisite to the hover functionality, and should
always be included in any manual properties specification.
))
visibilityhidden)positionabsolute)zz-indexr   )background-colorblack)colorwhite)	transformztranslate(-20px, -20px)zpd-tc                6    X l         Xl        X0l        / U l        g r^  )
class_nameclass_propertiestt_datar]   )rt   	css_propscss_namerp   s       r2   ru   Tooltips.__init__  s     # )')r1   c                N    SU R                    3[        U R                  5      S./$ )z
Combine the ``_Tooltips`` CSS class name and CSS properties to the format
required to extend the underlying ``Styler`` `table_styles` to allow
tooltips to render in HTML.

Returns
-------
styles : List
r<  r  )r  r  r  )rt   s    r2   _class_stylesTooltips._class_styles  s0      014T5J5JK
 	
r1   c                    SU-   S-   [        U5      -   S-   [        U5      -   nUSU 3-   S/S.USU S3-   S	S
U S
34/S./$ )aj  
For every table data-cell that has a valid tooltip (not None, NaN or
empty string) must create two pseudo CSS entries for the specific
<td> element id which are added to overall table styles:
an on hover visibility change and a content change
dependent upon the user's chosen display string.

For example:
    [{"selector": "T__row1_col1:hover .pd-t",
     "props": [("visibility", "visible")]},
    {"selector": "T__row1_col1 .pd-t::after",
     "props": [("content", "Some Valid Text String")]}]

Parameters
----------
uuid: str
    The uuid of the Styler instance
name: str
    The css-name of the class used for styling tooltips
row : int
    The row index of the specified tooltip string data
col : int
    The col index of the specified tooltip string data
text : str
    The textual content of the tooltip to be displayed in HTML.

Returns
-------
pseudo_css : List
z#T_rz   _colz:hover .)r  visibler  z .z::aftercontentr   )r&   )rt   rZ   r   r?   r>   textselector_ids          r2   _pseudo_cssTooltips._pseudo_css  sz    > dlV+c#h6?#c(J (HTF*;;34
 (BtfG*<<$$qk23	
 		
r1   c                T   U R                   R                  UR                  5      U l         U R                   R                  (       a  U$ U R                  nU R                   R                  5       U R                   R                  S5      -  n[        [        U R                   R                  5      5       VVs/ s H  n[        [        U R                   R                  5      5        H{  nUR                  XV4   (       a  M  XQR                  ;   a  M+  XaR                  ;   a  M<  U R                  UR                  X5U[!        U R                   R                  XV4   5      5      PM}     M     snn VVs/ s H  nU  H  nUPM     M     snnU l        U R"                  (       a~  US    H9  n	U	 H0  n
U
S   S:X  d  M  [!        U
S   5      SU R                   S3-   U
S'   M2     M;     US   R%                  U R&                  5        US   R%                  U R"                  5        U$ s  snnf s  snnf )	a  
Mutate the render dictionary to allow for tooltips:

- Add ``<span>`` HTML element to each data cells ``display_value``. Ignores
  headers.
- Add table level CSS styles to control pseudo classes.

Parameters
----------
styler_data : DataFrame
    Underlying ``Styler`` DataFrame used for reindexing.
uuid : str
    The underlying ``Styler`` uuid for CSS id.
d : dict
    The dictionary prior to final render

Returns
-------
render_dict : Dict
r   r   r+  r  r   z<span class="z	"></span>r]   )r  reindex_likerC   emptyr  r   eqr  r[   rU   rV   ilocrh   ri   r  rZ   r&   r]   r   r  )rt   stylerr   r   maskr   r  sublistr  r?   items              r2   r   Tooltips._translate  s   * ||00=<<H!!#(;<
 s4<<#5#567	7As4<<#7#789AIIadO	 X
 ... X 111 X  dq#dll>O>OPQPT>U:VW9 X7	
	 !  ! 	
 yDF|t+_ 56 -doo->iHI _-   ! n$$T%7%78n$$T%6%673	
s    5AH>HH AH.H$)r  r  r]   r  N)r  r(   r  r&   rp   r   rn  ro  )
rZ   r&   r   r&   r?   rW   r>   rW   r  r&   )r  r4   r   rE  )r+   r,   r-   r.   rr  r   ru   propertyr  r  r   r0   r*   r1   r2   r  r    s`    >$
 'k* * * * 
*$ 
 
")
V6r1   r  c                b   ^ / SQmU SL=(       a    [        U4S jU  5       5      =(       d    USL$ )a$  
Indicate whether LaTeX {tabular} should be wrapped with a {table} environment.

Parses the `table_styles` and detects any selectors which must be included outside
of {tabular}, i.e. indicating that wrapping must occur, and therefore return True,
or if a caption exists and requires similar.
)toprulemidrule
bottomrulecolumn_formatNc              3  2   >#    U  H  oS    T;  v   M     g7f)r'   Nr*   )r  r   IGNORED_WRAPPERSs     r2   r  ._parse_latex_table_wrapping.<locals>.<genexpr>`  s     L|!*%55|s   )r  )r]   r_   r  s     @r2   r   r   T  s>     M 	D  	ML|LL 
	r1   c                    U SSS2    H2  nUS   U:X  d  M  [        US   S   S   5      R                  SS5      s  $    g)	uE  
Return the first 'props' 'value' from ``tables_styles`` identified by ``selector``.

Examples
--------
>>> table_styles = [{'selector': 'foo', 'props': [('attr','value')]},
...                 {'selector': 'bar', 'props': [('attr', 'overwritten')]},
...                 {'selector': 'bar', 'props': [('a1', 'baz'), ('a2', 'ignore')]}]
>>> _parse_latex_table_styles(table_styles, selector='bar')
'baz'

Notes
-----
The replacement of "§" with ":" is to avoid the CSS problem where ":" has structural
significance and cannot be used in LaTeX labels, but is often required by them.
Nr'   r)   r   r      §r  )r&   r   )r]   r'   r  s      r2   r   r   d  sO    " dd#(uW~a(+,44T3?? $ r1   c           
        U(       a  [        U 5      n U SSS2    Hn  u  p4SU SU S3SU SU 3SU SU 3SU SU S3SU S	U S3S
.nSU U SU 3nS H0  nU[        U5      ;   d  M  XV   R                  S[        XFS95      n  Ml     Mp     U$ )aM  
Mutate the ``display_value`` string including LaTeX commands from ``latex_styles``.

This method builds a recursive latex chain of commands based on the
CSSList input, nested around ``display_value``.

If a CSS style is given as ('<command>', '<options>') this is translated to
'\<command><options>{display_value}', and this value is treated as the
display value for the next iteration.

The most recent style forms the inner component, for example for styles:
`[('c1', 'o1'), ('c2', 'o2')]` this returns: `\c1o1{\c2o2{display_value}}`

Sometimes latex commands have to be wrapped with curly braces in different ways:
We create some parsing flags to identify the different behaviours:

 - `--rwrap`        : `\<command><options>{<display_value>}`
 - `--wrap`         : `{\<command><options> <display_value>}`
 - `--nowrap`       : `\<command><options> <display_value>`
 - `--lwrap`        : `{\<command><options>} <display_value>`
 - `--dwrap`        : `{\<command><options>}{<display_value>}`

For example for styles:
`[('c1', 'o1--wrap'), ('c2', 'o2')]` this returns: `{\c1o1 \c2o2{display_value}}
Nr  z{\z--to_parse r-  \z--to_parse} z--to_parse{z--to_parse}{)--wrap--nowrap--lwrap--rwrap--dwrapr   )r  r  r  r  r  z
--to_parser   arg)_parse_latex_css_conversionr&   r   _parse_latex_options_strip)latex_stylesr   convert_csscommandoptionsrH  r  s          r2   r   r   {  s    8 2<@(2.WI[rBWI[@gYmM?CG9LrBgYn]O2F
	 WIgYa?JCc'l" ) 6 6 "<7"T!  K / r1   c                ,   [        U S   U S   U5      nSU ;   a  U S   nSU;   a  XfR                  S5      S-   S n[        USUR                  S5       5      nSU:X  a%  U(       a  S	U S
3OU nU(       a  SOSn	XUS-
  -  -   $ SU:X  a%  U(       a  S	U S
3OU nU(       a  SOSn	XS-
  -  U-   $ SU SU SU S
3$ SU;   aG  US:X  a  U$ XfR                  S5      S-   S n
[        U
SU
R                  S5       5      n
SU SU
 SU S
3$ U(       a  S	U S
3$ U$ )a  
Refactor the cell `display_value` if a 'colspan' or 'rowspan' attribute is present.

'rowspan' and 'colspan' do not occur simultaneouly. If they are detected then
the `display_value` is altered to a LaTeX `multirow` or `multicol` command
respectively, with the appropriate cell-span.

``wrap`` is used to enclose the `display_value` in braces which is needed for
column headers using an siunitx package.

Requires the package {multirow}, whereas multicol support is usually built in
to the {tabular} environment.

Examples
--------
>>> cell = {'cellstyle': '', 'display_value':'text', 'attributes': 'colspan="3"'}
>>> _parse_latex_header_span(cell, 't', 'c')
'\\multicolumn{3}{c}{text}'
r   r   r   r   	   Nr   znaive-l{r-  z & {}z &r   znaive-rz{} & z& z\multicolumn{z}{r  naivez
\multirow[z]{z}{*}{)r   findrW   )cellmultirow_alignmulticol_alignwrapr  display_valattrscolspanoutblanksrowspans              r2   r   r     sy   4 +[40+K t\"%JJ{3a79:G'"5GLL$567GN*.2;-r*;-$(dw{333n,.2;-r*;-$(d1-33$WIT.1Ak]RTUUE!(""JJ{3a79:G'"5GLL$567G  0G9Ik]RTUUK=##r1   c                    [        U 5      R                  US5      R                  SS5      R                  SS5      R                  5       $ )z
Strip a css_value which may have latex wrapping arguments, css comment identifiers,
and whitespaces, to a valid string for latex options parsing.

For example: 'red /* --wrap */  ' --> 'red'
r   z/*z*/)r&   r   r  r  s     r2   r  r    s>     u:c2&..tR8@@rJPPRRr1   c                ~   S nS nS nU[        USSS9[        USSS9US	.n/ nU  H  u  pg[        U[        5      (       a(  S
U;   a"  UR                  XgR	                  S
S5      45        Xd;   d  MI  SnS H   n	U	[        U5      ;   d  M  U	[        Xy5      px  O   XF   " Xx5      n
U
c  M  UR                  U
/5        M     U$ )z
Convert CSS (attribute,value) pairs to equivalent LaTeX (command,options) pairs.

Ignore conversion if tagged with `--latex` option, skipped if no conversion found.
c                    U S;   a  SU 4$ g )N)boldbolderbfseriesr*   r  s     r2   font_weight0_parse_latex_css_conversion.<locals>.font_weight  s    &&#''r1   c                0    U S:X  a  SU 4$ U S:X  a  SU 4$ g )Nitalicitshapeobliqueslshaper*   r  s     r2   
font_style/_parse_latex_css_conversion.<locals>.font_style  s/    H&&I&&r1   c           	        US:w  a  UOUnU S   S:X  a*  [        U 5      S:X  a  USU SS R                  5        SU 34$ U S   S:X  a]  [        U 5      S	:X  aN  U S   R                  5       S
-   U S
   R                  5       S
-   U S   R                  5       S
-   3nUSU SU 34$ U SS S:X  Ga,  [        R                  " SU 5      S   R	                  5       nSU;   a  [        USS 5      S-  O[        U5      S-  n[        R                  " SU 5      S   R	                  5       nSU;   a  [        USS 5      S-  O[        U5      S-  nU S   S:X  a)  [        R                  " SU 5      S   R	                  5       nO([        R                  " SU 5      S   R	                  5       nSU;   a  [        USS 5      S-  O[        U5      S-  nUSUS SUS SUS SU 34$ USU  SU 34$ )a  
CSS colors have 5 formats to process:

 - 6 digit hex code: "#ff23ee"     --> [HTML]{FF23EE}
 - 3 digit hex code: "#f0e"        --> [HTML]{FF00EE}
 - rgba: rgba(128, 255, 0, 0.5)    --> [rgb]{0.502, 1.000, 0.000}
 - rgb: rgb(128, 255, 0,)          --> [rbg]{0.502, 1.000, 0.000}
 - string: red                     --> {red}

Additionally rgb or rgba can be expressed in % which is also parsed.
r   r   #   z[HTML]{r   Nr-           rgbz(?<=\()[0-9\s%]+(?=,)%r  d      z(?<=,)[0-9\s%]+(?=,)az(?<=,)[0-9\s%]+(?=\))z[rgb]{z.3fz, r  )r[   upperr  findallr  floatrW   )	r   user_argr  comm_argr  valr   gbs	            r2   r  *_parse_latex_css_conversion.<locals>.color  s    #b.hh8s?s5zQhuQRy'8&9C5AAA8s?s5zQ1X^^%a'(q)9!);(<U1X^^=Ma=O<PQChse2cU3332AY%

4e<Q?EEGA'*axaf#SVc\A

2E:1=CCEA'*axaf#SVc\AQx3JJ6>qAGGIJJ8%@CIIK'*axaf#SVc\AgaWBqgR#wbFFFbr#///r1   	cellcolorr  )r  rF  r  r   )zfont-weightr  r  z
font-stylez--latex)r  r  r  r  r  )r   rR   r&   r   r   r  r   )r  r.  r5  r  CONVERTED_ATTRIBUTESr  	attributer   r  r   latex_styles              r2   r  r    s    
0D ##E;S"= 	1 L"	eS!!i5&8MM)R,H IJ,CLE
?!"$>u$H M /9%EK&##[M2 # r1   c                   U R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  S	S
5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  SS5      $ )a<  
Replace the characters ``&``, ``%``, ``$``, ``#``, ``_``, ``{``, ``}``,
``~``, ``^``, and ``\`` in the string with LaTeX-safe sequences.

Use this if you need to display text that might contain such characters in LaTeX.

Parameters
----------
s : str
    Input to be escaped

Return
------
str :
    Escaped string
r  u   ab2§=§8yzu   ab2§=§8yz u   ab2§=§8yz\space &z\&r>  z\%$\$r8  z\#r   z\_r  z\{r-  z\}z~ z~\space ~z\textasciitilde z^ z^\space ^z\textasciicircum z\textbackslash )r   )r  s    r2   r  r  8	  s    $ 	
		$&	!6	7	e		e		e		e		e		e		e		{	#	)	*	{	#	*	+	 2	3r1   c           	        U R                  SS5      n [        R                  " S5      nSnUR                  X5      n/ nU(       ay  UR	                  [        XUR                  5       S    5      5        UR	                  UR                  5       5        UR                  5       S   nUR                  X5      nU(       a  My  UR	                  [        X[        U 5       5      5        SR                  U5      R                  SS5      $ )a8  
All characters in LaTeX math mode are preserved.

The substrings in LaTeX math mode, which start with
the character ``$`` and end with ``$``, are preserved
without escaping. Otherwise regular LaTeX escaping applies.

Parameters
----------
s : str
    Input to be escaped

Return
------
str :
    Escaped string
rR     rt8§=§7wz\$.*?\$r   r   r   )
r   r  compilesearchr   r  spanr  r[   join)r  patternpospsress        r2   _math_mode_with_dollarr`  [	  s    $ 	
		%(Ajj$G
C		B
C


=1!678

288:ggil^^A#	 " JJ}QSV_-.773<66r1   c                j   U R                  SS5      R                  SS5      n / n[        R                  " SU 5       H  nUR                  S5      (       aI  UR	                  S5      (       a3  UR                  UR                  SS5      R                  SS5      5        Mb  SU;   aB  SU;   a<  UR                  [        U5      R                  SS5      R                  SS5      5        M  UR                  [        U5      R                  SS5      R                  SS	5      5        M     S
R                  U5      $ )a:  
All characters in LaTeX math mode are preserved.

The substrings in LaTeX math mode, which start with
the character ``\(`` and end with ``\)``, are preserved
without escaping. Otherwise regular LaTeX escaping applies.

Parameters
----------
s : str
    Input to be escaped

Return
------
str :
    Escaped string
\(u   LEFT§=§6yzLEFTz\)u   RIGHTab5§=§RIGHTu   LEFT§=§6yz|ab5§=§RIGHTLEFTRIGHTz\textbackslash (z\textbackslash )r   )r   r  r  
startswithendswithr   r  r[  )r  r_  r  s      r2   _math_mode_with_parenthesesrg  |	  s    $ 	
		%,-55e=RSA
C6:??6""t}}W'='=JJt||FE2::7EJKt^4JJd#++FE:BB7ER JJd#!45"56 ; 773<r1   c                   U R                  SS5      n [        R                  " S5      R                  U S5      n[        R                  " S5      R                  U S5      n/ nU(       a"  UR	                  UR                  5       S   5        U(       a"  UR	                  UR                  5       S   5        [        U5      S:X  a  [        U R                  SS5      5      $ XS      S:X  a  [        U R                  SS5      5      $ XS   S-
  US   S-    S:X  a  [        U R                  SS5      5      $ [        U R                  SS5      5      $ )	ak  
All characters in LaTeX math mode are preserved.

The substrings in LaTeX math mode, which either are surrounded
by two characters ``$`` or start with the character ``\(`` and end with ``\)``,
are preserved without escaping. Otherwise regular LaTeX escaping applies.

Parameters
----------
s : str
    Input to be escaped

Return
------
str :
    Escaped string
rR  rV  rW  r   z\(.*?\)rQ  r   rb  )
r   r  rX  rY  r   rZ  r[   r  r`  rg  )r  ps_dps_pmodes       r2   r  r  	  s   $ 	
		%(A::j!((A.D::j!((A.DDDIIKN#DIIKN#
4yA~QYY~u=>>azT%aii&FGGa1tAw{#u,*199^U+KLLQYY~u=>>r1   )
ry  r&   rz  rk  r   r   r!  rl  rn  rE  )NNg?)r~  rD  rn  ztuple[int, int]r^  )rU   r   r  rl  r  rW   r  zSequence[int] | Noner  )r  	CSSStylesrn  rl  )F)r   r   rJ   rW   r@  rl  rn  r   )rH  r	   r?  r&   r@  rk  rn  r	   )NNNr<  NNN)rH  zBaseFormatter | Noner>  rk  rJ   rm  r?  r&   r@  rk  r"   rk  rA  rk  rn  r	   )r  Subset)r  r(   rn  CSSList)rB   rq  r  r   rn  z	list[int])r]   rl  r_   rk  rn  rl  )r]   rl  r'   r&   rn  rk  )r  rn  r   r&   r  rl  rn  r&   )FF)r  zdict[str, Any]r  r&   r   r&   r!  rl  r  rl  rn  r&   )r   zstr | floatr  r&   rn  r&   )r  rn  rn  rn  )r  r&   rn  r&   )\
__future__r   collectionsr   collections.abcr   	functoolsr   r  typingr   r   r	   r
   r   r   r   rZ   r   numpyr  pandas._configr   pandas._libsr   pandas.compat._optionalr   pandas.core.dtypes.commonr   r   r   pandas.core.dtypes.genericr   r6   r   r   r   r   r   r   pandas.api.typesr   pandas.core.commoncorecommonr   pandas._typingr   r   r   
markupsafer"   r  r&   BaseFormatterrE  ExtFormatterr   rD  CSSPairrj   rn  r(   r$   rl  rB  rm  r4   r   r   r   r   r   rL   r  r  r  rG  rC  r  rS  r  r   r   r   r   r  r  r  r`  rg  r  r*   r1   r2   <module>r     s   " # $  	     %  > 
 1  *     
$H4V	W ,c8m$]Dh}.E)E$FFG
U3:&&
'
w-c7l#i 
 M		uh%	&T Tn.  	 
2 * * *b -1	NNN N *	Nb)2"%2<6" '+  !3D#3D3D 3D 	3D
 3D 3D 3D 3Dl(V,%	 Dc cL 0 DI--*--<@--h 4
44 4 	4
 4 	4nSIX F7B!H!?r1   