Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/io/formats/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/io/formats/__pycache__/style_render.cpython-312.pyc

�

Mٜgc��@�ddlmZddlmZddlmZddlmZddlZddl	m
Z
mZmZm
Z
mZmZmZddlmZddlZddlmZdd	lmZdd
lmZddlmZmZmZddlm Z dd
l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+cm,Z-e
rddl.m/Z/m0Z0edd��Z1ddl2m3Z4ee5efZ6ee6e7eee6ffZ8e9e5ee5e:ffZ;e<e;Z=ee5e=fZ>Gd�de�Z?e<e?Z@eeAee#fZBGd�d�ZC										d1d�ZD			d2			d3d�ZE	d4							d5d�ZFd6d�ZGd7d�ZHd8d9d�ZI								d:d�ZJd�ZKd �ZL							d;															d<d!�ZMd=d"�ZNd>d#�ZO						d?d$�ZPGd%�d&�ZQd@d'�ZRdAd(�ZS	d8							dBd)�ZT		dC											dDd*�ZUdEd+�ZVdFd,�ZWdGd-�ZXdGd.�ZYdGd/�ZZdGd0�Z[y)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�"�eZdZUded<ded<y)�CSSDict�str�selector�
CSSProperties�propsN)�__name__�
__module__�__qualname__�__annotations__���I/usr/local/lib/python3.12/site-packages/pandas/io/formats/style_render.pyr$r$:s
���M��r.r$c��eZdZdZejdd�Zejed��Zejd�Z
ejd�Zejd�Zejd	�Z
ejd
�Z							d																	dd�Z			d 									d!d
�Z		d"									d#d�Z								d$d�Z		d"									d#d�Zd�Z				d%											d&d�Zd'd�Z						d(d�Z						d(d�Zd)d�Z		d*													d+d�Zd,d�Z						d-d�Zd.d�Z								d/																	d0d�Z									d1																			d2d�Z		d3							d4d�Z y)5�StylerRendererzT
    Base class to process rendering a Styler with a specified jinja2 template.
    �pandaszio/formats/templatesT)�loader�trim_blockszhtml.tplzhtml_table.tplzhtml_style.tplz	latex.tplz
string.tplNc	���t|t�r|j�}t|t�st	d��||_|j|_|j|_t|t�r|dkrt	d��|xs!t�jdtd|�|_t|j�|_||_||_||_||_ddddd	d
ddd
ddd�|_g|_d|_d|_dg|jj.z|_dg|jj.z|_g|_g|_t9t:�|_t9t:�|_t9t:�|_ t9tB�|_"g|_#d|_$��tKd�n��t9�fd��|_&t9�fd��|_'t9�fd��|_(y)Nz&``data`` must be a Series or DataFramerz1``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)r7r8r9r:r;r<r=r>r?r@rAF�styler.format.precisionc�&��tt���S�N��	precision�r�_default_formatterrEs�r/�<lambda>z)StylerRenderer.__init__.<locals>.<lambda>��
����(:�i� Pr.c�&��tt���SrDrGrEs�r/rIz)StylerRenderer.__init__.<locals>.<lambda>�rJr.c�&��tt���SrDrGrEs�r/rIz)StylerRenderer.__init__.<locals>.<lambda>�rJr.))�
isinstancer�to_framer�	TypeErrorr?�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)	�selfr?rUrWrXrYrZr[rFs	        `r/�__init__zStylerRenderer.__init__Ps�����d�F�#��=�=�?�D��$�	�*��D�E�E�#��	� �J�J��
�"�l�l����(�C�(�H�q�L��O�P�P��<�E�G�K�K�(;�#�b�(�*;�<��	��D�I�I���
�(��� 0������ ��
�(�(�&���"�"�����
���35���&+���',���"'��4�:�:�+=�+=�!=���$)�7�T�\�\�-A�-A�#A���*,���-/���:E�d�:K���@K�D�@Q���BM�d�BS���?J�3�?O���9;��
�)-��
�5>�5F�J�0�1�I�	�

�P�Q�	
��

�P�Q�	
�!�

�P�Q�	
�#r.c���|j�g}t|j�}t|j�D�]\}}	|j
|	_|j|	_|jd�|��}
i|j�|
�d�|
�d�|
�d�|
�d�d��|	_|	j|||||�}|j|�|	jj�D]\\}}
}||j||z|
f<�|	jj�D]\\}}
}||j||z|
f<�|t|	j�z
}��|j||||||�}|S)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`
        rA�_data�_row_heading�_row�_foot)r?r7r;rA)�_computerVrP�	enumerater]rardr\�_render�appendrf�itemsrg�
_translate)ro�sparse_index�sparse_columns�max_rows�max_colsr@�dxs�ctx_len�ir]rA�dx�r�c�v�ds                r/rxzStylerRenderer._render�s���	
�
�
�����d�j�j�/��(��):�):�;�O�A�|�'+�'7�'7�L�$�*.�*=�*=�L�'��h�h�v�&�'��s�+�D� ��(�(� ��&���"&��|�4���t�}��&��� �L���%�%��n�h��%��B�
�J�J�r�N�)�-�-�3�3�5�	���A��-.����!�g�+�q�)�*�6�)�3�3�9�9�;�	���A��34�����G��Q�/�0�<�
�s�<�-�-�.�.�G�+ <�.
�O�O��.�(�H�e�S�
���r.c��|j||||d�}|j|�|jjdi|�|j|j
d���S)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-)rx�update�
template_html�render�template_html_table�template_html_style�ror|r}r~r�kwargsr�s       r/�_render_htmlzStylerRenderer._render_html�s`��
�L�L��~�x��8�T��	�����(�t�!�!�(�(�
��
��3�3��3�3�
�	
r.c��|j||dd�}|j||��t|jjd<t
|jjd<t|jjd<t|jjd<|j|�|jjdi|��S)z1
        Render a Styler in latex format
        N)�clines�
parse_wrap�parse_table�
parse_cell�parse_headerr-)
rx�_translate_latex�_parse_latex_table_wrapping�template_latex�globals�_parse_latex_table_styles�_parse_latex_cell_styles�_parse_latex_header_spanr�r�)ror|r}r�r�r�s      r/�
_render_latexzStylerRenderer._render_latex�s���
�L�L��~�t�T�B�����a���/�4O����#�#�L�1�5N����#�#�M�2�4L����#�#�L�1�6N����#�#�N�3�	�����)�t�"�"�)�)�.�A�.�.r.c��|j||||�}|j|�|jjdi|��S)z2
        Render a Styler in string format
        r-)rxr��template_stringr�r�s       r/�_render_stringzStylerRenderer._render_string�s@��
�L�L��~�x��J��	�����*�t�#�#�*�*�/�Q�/�/r.c���|jj�|jj�|jj�|}|jD]\}}}||�|i|��}�|S)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)
        )rf�clearrgrhrj)ror��func�argsr�s     r/rvzStylerRenderer._compute�sh��	
����������������� ���"&�*�*��D�$����T�
�D�+�F�+�A�#-��r.c�N�|�g}||jd<|jt|jxsg�|jd�}td�}|r|n
td�}|r|n
td�}t
t|jj�t|jj�|||�\}}tt�|_
|j||�}	|jd|	i�t!|j|||j"�}
|jd|
i�tt�|_tt�|_|j)|
||�}|jd|i�d	d
dd�}|j+�D]P\}
}t-||�j+�D��cgc]\}}t|�|d
���}}}|j|
|i��R|D]G}|dj/|d�|dj/|d�|dj/|d��I|j0}td�s"|xsd}d|vr|j3dd�}n|dz
}|jd|i�|j4r|j4j7||�}|Scc}}w)aj
        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)rUrXrZzstyler.render.max_elementszstyler.render.max_rowszstyler.render.max_columns�head�
index_lengths�body�
cellstyle_map�cellstyle_map_index�cellstyle_map_columns)�	cellstyle�cellstyle_index�cellstyle_columns)r(�	selectorsr�r�zstyler.html.mathjax�zclass="zclass="tex2jax_ignore z class="tex2jax_ignore"rY)r\rU�format_table_stylesrXrZr�_get_trimming_maximumsrVr?rPrQrrer��_translate_headerr��_get_level_lengthsrcr�r��_translate_bodyrz�getattr�extendrY�replacerkr{)ror|�sparse_colsr~rr@r�r��max_elementsr��idx_lengthsr��ctx_maps�k�attrr(r��mapr��
table_attrs                    r/r{zStylerRenderer._translates���H�;��C�"'�������I�I�/��0A�0A�0G�R�H��|�|�
��"�">�?��'�8�Z�8P�-Q��'�8�Z�8S�-T��3���	�	��� ���	�	�!�!�"����
���(�
���	
�"��%�%�k�8�<��	���&�$�� �)��J�J��h��0@�0@�
��	
���/�;�/�0�JU��K
���

���	
� ��)�)�+�x��J��	���&�$�� �)�4�!8�
��
 �~�~�'�G�A�t�)0��d�(;�(A�(A�(C��(C�$�E�9��u�+�I�>�(C�
��
�H�H�a��X��(��B�
�f�I���R��Z�(�
�k�N�!�!�"�[�/�2�
�� �'�'��$�%�
���*�*�
��/�0�#�)�r�J��J�&�'�/�/�	�;S�T�
��7�7�
�	���$�j�1�2��=�=��
�
�(�(��q�1�A����3s�/J!c���t|j|||j�}|jjj	�}|jjj
dk(r|D�cgc]}|g��}}t
t|��}g}t|j�D]0\}}|s|s�|j||f||�}	|j|	��2|jjjrutj|jjj�rEt!|j"�s0|j$s$|j'|||�}
|j|
�|Scc}w)aN
        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�rQrdr?�tolistr`re�ziprwrb�_generate_col_header_rowryrP�names�com�any_not_none�allrar^�_generate_index_names_row)ro�
sparsify_colsr�col_lengths�clabels�xr�r��hide�
header_row�index_names_rows           r/r�z StylerRenderer._translate_headerss;��4)��L�L�-��4�3F�3F�
���)�)�#�#�*�*�,���9�9���$�$��)�$+�,�G�q��s�G�G�,��s�G�}�%���� ��!3�!3�4�G�A�t��7���6�6��G��h���J�
�K�K�
�#�5�
�I�I�O�O�!�!�� � �$�)�)�/�/�"7�"7�8���(�(�)��)�)�"�<�<���;��O�
�K�K��(����5-s�.
E,c��|\}}td|jd|jdd�g|jjt	|j
�z
dz
z}|jjj|}td|�#|jd�d|jd�|��n"|jd�d|jd�|��|�|js|n|jdt|j
��g}g}	d	}
t||�D�]�\}}t|||�}
|
r|
|j||fd	�z
}
|j|
||	d|jd
�d|jd�|�d|jd���r�nttd|jd
�d|jd�|�d|jd�|��||
|j||f|�|j||fd	�dkDrd
|j||fd	��d�nd��}|j r(|jd�|�d|jd�|��|d<|
r�||f|j"vr�|j"||fr�|jd�|�d|jd�|��|d<|j$t'|j"||f�j)|jd�|�d|jd�|���|	j)|����||z|	zS)aD
        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
        �thr@r�Tr�� r>r9rr8r<r:�	colspan="�"r���
display_value�
attributes�_�id)�_elementr\rPr`�sumrar?rQr�r_r�rw�_is_visible�get�_check_trimrnr[rhr��tuplery)ro�iterrr�r�r��index_blanks�name�column_name�column_headers�visible_col_countr��value�header_element_visible�header_elements               r/r�z'StylerRenderer._generate_col_header_row�sl��0�
��7�
�T�4�8�8�G�,�d�h�h�}�.E�t�L�
�
�Z�Z�
�
�#�d�&6�&6�"7�
7�!�
;�=���y�y� � �&�&�q�)�����|��x�x��(�)��4�8�8�G�+<�*=�a�S�A� �H�H�\�2�3�1�T�X�X�g�5F�4G��s�K��$�T�-C�-C���X�X�m�,���(�(�)�)�
�

�� "��!"��!�'�!�*�-�H�A�u�%0��A�{�%C�"�%�!�[�_�_�a��V�Q�%?�?�!����!�����8�8�M�*�+�1�T�X�X�g�->�,?��s�!��8�8�J�'�(�*���%���x�x�
�.�/�q����'�1B�0C�A�3�a��x�x���'��s�,��&�A�d�9�9�1�a�&�A�%�H�#����1�v�q�1�A�5� �����A��� :�;�1�=���N� �}�}�*.�(�(�7�*;�)<�Q�C�q����%��@Q�RS�QT�'U��t�$�&���F�d�.�.�.��$�$�Q��T�*�*.�(�(�7�*;�)<�Q�C�q����%��@Q�RS�QT�'U��t�$��*�*�5��1A�1A�!�Q�$�1G�+H�I�P�P��x�x��(�)�!��A�d�h�h�u�o�->�q�c�B��
�!�!�.�1�U.�X�k�)�N�:�:r.c��|}t|jjj�D��cgc]S\}}t	d|j
d�d|j
d�|��|�|j
dn||j|���U}}}g}d}	|r�|jjdz
}
t||
�D]�\}}t||
|�}|r|	dz
}	|j|	||d|j
d�d|j
d	�|�d|j
d
��|j
d�r||zS|jt	d|j
d�d|j
d	�|��|j
d||jv����||zScc}}w)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�r9r�r>r�rr�r@r:r<)
rwr?rPr�r�r\rarQr`r�r�ryrd)
ror�rr�r�r�r��index_names�
column_blanksr��
last_levelr�r�s
             r/r�z(StylerRenderer._generate_index_names_rows���,��%�T�Y�Y�_�_�%:�%:�;�
�<���4�

���8�8�L�)�*�!�D�H�H�W�,=�+>�q�c�B�+/�<�����'�T��$�$�Q�'�'�	
�<�	�
�!�
�!"������-�-��1�J�%�g�j�&9�:���5�)4�Q�
�K�)P�&�)�%��*�%��#�#�%��!���x�x��(�)��4�8�8�E�?�*;�A�3�a�����@T�?U�V��H�H�]�+�
���]�*�*��$�$����8�8�G�,�-�Q�t�x�x���.?��s�C�����/���!4�!4�4�	��;�.�]�*�*��K
s�AF	c���|jjj�}t|jjt�s|D�cgc]}|g��}}g}d}t|jj
��D�cgc]}|d|jvs�|��c}D]H\}	}
|dz
}|j|||d�r|S|j|	|
|f||�}|j|��J|Scc}wcc}w)a�
        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.
        rr�r;)r?rPr�rMrrw�
itertuplesrcr��_generate_body_rowry)ror�r~r�rlabelsr�r��visible_row_count�zr��row_tup�body_rows            r/r�zStylerRenderer._translate_bodyMs��,�)�)�/�/�(�(�*���$�)�)�/�/�:�6�$+�,�G�q��s�G�G�,���!"�� ����!5�!5�!7�8�
�8�!�A�a�D��HX�HX�<X�A�8�
�J�A�w�
��"�����!����	����	�.�.��G�W�%�x���H�
�K�K��!�
� ���)-��
s�
C-�C2�C2c	��||kDrF|dk(r!|j|j|��y|jt|||dd���yy)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)ry�_generate_trimmed_rowr�)ro�count�max�obj�elementr\r�s       r/r�zStylerRenderer._check_trim{sQ��@�3�;��%���
�
�4�5�5�c�:�;���
�
�8�G�S�%��"�M�N��r.c
��t|jjj�D�cgc]Q}t	d|j
d�d|j
d�|�d|j
d��d|j|d����S}}g}d	}t|j�D]�\}}||jv}|r|d
z
}|j|||d|j
d�d|j
d�d|j
d
���r||zS|jt	d|j
d�d|j
d�|�d|j
d��d|d�����||zScc}w)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�r7r�r>r=�...r�r�rr��tdr?r<r:)�ranger?rPr`r�r\rarwrQrdr�ry)rorr��
index_headersr?r�r��data_element_visibles        r/r�z$StylerRenderer._generate_trimmed_row�s���0�4�9�9�?�?�2�2�3�
�4��
���x�x�
�.�/�q����'�1B�0C�A�3�a��x�x�
�+�,�.���$�$�Q�'�'��	
�4�	�
���!"���d�l�l�+�D�A�q�#$�D�,?�,?�#?� �#�!�Q�&�!����!�����8�8�F�#�$�A�d�h�h�z�&:�%;�1�T�X�X�j�=Q�<R�S����t�#�#�
�K�K����x�x��'�(��$�(�(�5�/�):�1�#�Q�t�x�x�
�?S�>T�U��(�!��
�,�.�t�#�#��O
s�AEc�Z�|\}}}g}t||�D�]�\}}	t|||�xr|j|}
td|jd�d|jd�|�d|jd�|��|	|
|j
||f|	�|j
||fd�dkDrd|j
||fd��d	�nd
��}|jr(|jd�|�d|jd�|��|d
<|
r�||f|jvr�|j||fr�|jd�|�d|jd�|��|d
<|jt|j||f�j|jd�|�d|jd�|���|j|����g}d}
t|dd�D�]�\}}	||jvxr||jv}|r|
dz
}
|j|
||d|jd�d|jd�|�d|jd���r||zSd
}||f|jvrd|j||fz}td|jd�d|jd�|�d|jd�|�|��|	|d
|j ||f|	���}|jr(|jd�|�d|jd�|��|d
<|r�||f|j"vr�|j"||fr�|jd�|�d|jd�|��|d
<|j$t|j"||f�j|jd�|�d|jd�|���|j|����||zS)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�r7r�r>r;rr��	rowspan="r�r�r�r�r�Nrr?r<r:)r�r�)rwr�rar�r\rmr�r[rgr�r�ryrdrcr�rirlrfr�)ror�rr�r�r�r�rr�r�r�r�r?r�r�cls�data_elements                 r/r�z!StylerRenderer._generate_body_row�sH��4#���7�G��
�!�'�!�*�-�H�A�u��A�q�+�.�J�t�7G�7G��7J�3J�
#�&���x�x�
�.�/�q����'�1B�0C�A�3�a��x�x���'��s�,��&�?�d�7�7��A��?��F�#����1�v�q�1�A�5� �����A��� :�;�1�=���N� �}�}��x�x��(�)�!��A�d�h�h�u�o�->�q�c�B����'���F�d�n�n�,��N�N�1�a�4�(�+/�(�(�7�*;�)<�Q�C�q����%��@Q�RS�QT�'U��t�$��(�(��t�~�~�a��d�/C�)D�E�L�L��x�x��(�)�!��A�d�h�h�u�o�->�q�c�B��
� � ��0�G.�J��!"��!�'�!�"�+�.�H�A�u���,�,�,�J��$�:J�:J�1J�
!�$�!�Q�&�!����!�����8�8�F�#�$�A�d�h�h�u�o�%6�q�c��4�8�8�J�;O�:P�Q���<�t�#�#�7�C��1�v��*�*�*��D�-�-�a��d�3�3��#���x�x��'�(��$�(�(�5�/�):�1�#�Q��x�x���'��s�3�%�1��$��9�d�1�1�1�a�&�9�%�@�
�L��}�}�(,�����'8���1�T�X�X�e�_�<M�a�S�%Q��T�"�#��A��$�(�(�(:�t�x�x��1��~�(,�����'8���1�T�X�X�e�_�<M�a�S�%Q��T�"��"�"�5����!�Q�$��#8�9�@�@��x�x���'��s�!�D�H�H�U�O�+<�Q�C�@��
�K�K��%�S/�V�t�#�#r.c���|jj}|t|j�z
}t	|d�D����cgc]@\}}t	|�D��cgc]$\}}|dri|�d|j
|||z
fi���&c}}��Bc}}}}|d<�fd���fd�}	g}
t
|	|�|d�D]�\}}t|j�rg}nWt	|d|�D��cgc]>\}}|dd	k(r1|j|s"i|�|dr|d
nd|j||fd����@}}}t	||d�D��cgc])\}}|dr|dd
k(ri|�d|j||fi���+}}}|
j||z���|
|d<|dvrtd|�d���|��d|vr|drt�nd}
tt�|d<tt|j j��D�cgc]}||j"vs�|��}}t|�D�cgc]}|j|r�|��}}t	|�D]o\}}t	|�D]\\}}||dz
k(rd|vr�|dj%||fd�}|��-|d||zjd|dz�dt|�|
z�d���^�qyycc}}wcc}}}}wcc}}wcc}}wcc}wcc}w)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���|jtt|j��D�cgc]}||jvs�||z��c}�|t|j�z
}|j
D]}�|||�}�|Scc}w)z`
            Extract all visible row indices recursively from concatenated stylers.
            )r�rrVrPrcr])r�n�row_indicesr�r]�_concatenated_visible_rowss     �r/rzCStylerRenderer._translate_latex.<locals>._concatenated_visible_rows_s����
��� %�c�#�)�)�n� 5�R� 5�1��#�/�/�9Q��Q�� 5�R�
�
��S�Y�Y���A� #� 0� 0��.�|�Q��L��!1��H��Ss�B�Bc� ��g}�|d|�|S�Nrr-)rrrs  �r/�concatenated_visible_rowszBStylerRenderer._translate_latex.<locals>.concatenated_visible_rowsks���%'�K�&�s�A�{�;��r.r�N�typer�r�r�)r�r�r)Nzall;dataz	all;indexzskip-last;datazskip-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'.r?rr�r�z	skip-lastr�z\cline{�-�})rPr`r�rarwrhr�r�rgrfry�
ValueErrorrVrrerr?rcr�)ror�r��index_levels�visible_index_level_nr�r;r�r:rr��row_body_headers�row_body_cells�data_len�visible_row_indexesr��visible_index_levels�rn�lvln�lvl�idx_lenrs                     @r/r�zStylerRenderer._translate_latexJs�����z�z�)�)�� ,�s�4�3C�3C�/D� D��$�A�f�I�.�

�/���3�(��n�
�,�F�A�s��|�$�U�3�T��T�%5�%5�a��=R�9R�6R�%S�T�,�
�
/�

��&�	�
	�	����3�D�9�1�V�9�E�F�A�s��4�#�#�$�#%� �#,�C�
��,>�"?�
$�#@���3��F��t�+�D�4D�4D�Q�4G�����|�,�*-�_�)=��%)�^�^�A�q�D�%9��#@�!�
$�(��L�M�(:�;��;�F�A�s���%�#�f�+��*=�5�3�4��T�X�X�a��d�^�4�;�
��
�K�K�(�>�9�:�3F�4��&�	��
�
��$�V�H�-S�T��
���.4��.>�1�V�9�s�>�*�RS�H�%�d�+�A�h�K� ��T�Y�Y�_�_�!5�6�.�6�a�!�4�CS�CS�:S��6�
 �.�!��.�/�.�a�d�6F�6F�q�6I��.�
!�/�#�#6�7���A�!*�+?�!@�I�D�#��l�Q�.�.�;�&�3H� ���0�4�4�c�1�X�t�D�G��*��(��B��L�1�8�8�'��Q��x�q��5I�1J�8�1S�0T�TV�W��"A�8���K
��
��H
$����4.��/s=�J3
�)J-�J3
�!AJ;�8.K�,K�K�K�(K�-J3
c	�x�t|du|du|du|dk(|du|du|du|duf�r|jj�|S|�td�n|}t	|�}|j
j|}	t|t�s|	jD�
cic]}
|
|��}}
|jj|	j�}|jj|	j�}|D]H}
t|j|j|
�||||||��}|D]}||j||
f<��J|Scc}
w)u8%
        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_reprF�decimal�	thousandsr"�
hyperlinks)r�rlr��slice�non_reducing_slicer?�locrM�dictrQ�get_indexer_forrP�_maybe_wrap_formatterr�)ro�	formatter�subsetr(rFr)r*r"r+r?r:�cis�ris�ci�format_func�ris                r/�formatzStylerRenderer.format�sP��P��T�!��$���T�!��3���T�!��$���$���d�"�	
�
�
���%�%�'��K� &���t��F��#�F�+���y�y�}�}�V�$���)�T�*�37�<�<�@�<�C��i��<�I�@��l�l�*�*�4�<�<�8���j�j�(�(����4���B�/��
�
�d�l�l�2�.�/��#��#��%��K���0;��#�#�R��H�-������#As�
D7c
��|jj|�}|dk(r|j|j}}
n|j|j
}}
t
||�}t|du|du|du|dk(|du|du|du|	duf�r|
j�|St|t�s|D�cic]}||��}}n2|j�D��
cic]\}}
|j|�|
��}}}
|D]Z}t|j|�||||||	��}tt!|��D�cgc]}|dk(r||fn||f��c}D]}||
|<�	�\|Scc}wcc}
}wcc}w)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}
        rNr&r')r?�_get_axis_numberrmrPrnrQ�refactor_levelsr�r�rMr/rz�_get_level_numberr1r�rrV)ror2�axisr>r(rFr)r*r"r+�display_funcs_r�levels_�
formatter_r#r7r��idxs                  r/�format_indexzStylerRenderer.format_index�s���\�y�y�)�)�$�/���1�9�"&�";�";�T�Z�Z�C�N�"&�"=�"=�t�|�|�C�N�!�%��-����T�!���
��T�!��3���T�!��$���$���d�"�	
�
�
� � �"��K��)�T�*�7>�?�w�e��	�)�w�I�?�*3���):��):�%�E�:��%�%�e�,�j�8�):�
��
�C�/��
�
�c�"��#��#��%��K�FK�3�s�8�_�U�_��D�A�I��C��C��8�;�_�U��&1��s�#�V�����+@���� Vs�(
E�E
�#Ec�N�|jj|�}|dk(r1|j|j}}|j|j
}}n0|j|j}}|j|j}}t|�tt|��z
}t|�|k7rtd|�d���|�(t|j�D�	cgc]
}	||	r�	|	��}}	t||�}
d�}t!tt|��D�	cgc]	}	|	|vs�|	��c}	�D]p\}}	t|
�dk(r'|dk(r|	|
dfn|
d|	f}
t#|||��||
<�;t!|
�D](\}}|dk(r|	|fn||	f}
t#||||��||
<�*�r|Scc}	wcc}	w)aa
        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
        rzS``labels`` must be of length equal to the number of visible labels along ``axis`` (z).c�H�t|t�r|j|�S|S�N)rMr%r9)r�r�s  r/�alias_z,StylerRenderer.relabel_index.<locals>.alias_	s���%��%��|�|�A��&��Lr.r�)r�)r?r;rmrPrcrarnrQrdrbrV�setrrr`r<rwr)ro�labelsr>r>r?r�
hidden_labels�hidden_lvls�visible_lenr�r@rG�airB�ajr#s                r/�
relabel_indexzStylerRenderer.relabel_index{s���x�y�y�)�)�$�/���1�9�"&�";�";�T�Z�Z�C�N�)-�)9�)9�4�;K�;K�;�M�"&�"=�"=�t�|�|�C�N�)-�)<�)<�d�>P�>P�;�M��#�h��S��%7�!8�8���v�;�+�%��2�2=��b�B��
�
�=� %�c�k�k� 2�I� 2�1�+�a�.�Q� 2�E�I�!�%��-��	�
�5��S��?�U�?�a�a�}�>T��?�U�V�E�B���7�|�q� �)-���q�'�!�*�o����Q���&-�f�F�2�J�&G��s�#�(��1�G�B��&*�a�i�1�c�(�c�1�X�C�*1�&��r�
�2��*O�N�3�'� 2�W����#J�� Vs�
F�#F�	F"�F")N�NNNTN)r?zDataFrame | SeriesrU�
str | NonerWrRrXzCSSStyles | NonerYrQrZzstr | tuple | list | Noner[�boolrF�
int | None�return�None)NNr�)
r|rRr}rRr~rSrrSr@r%)NN)
r|rRr}rRr~rSrrSrTr%)r|rRr}rRr�rQrTr%)NNr�N)r|rRr�rRr~rSrrSr@r%r�zlist[dict] | None)r�rRrrR)r�rrrRr�r/)r�r/r~rRrrR)Nr)r�rRrrRrrerr%r\rQr�r%rTrR)rrRrTre)r�r�rrRr�r/)r�r/r�rQrTrU)NNNNr&NNN)r2�ExtFormatter | Noner3z
Subset | Noner(rQrFrSr)r%r*rQr"rQr+rQrTr1)	NrNNNr&NNN)r2rVr>rr>�Level | list[Level] | Noner(rQrFrSr)r%r*rQr"rQr+rQrTr1)rN)rIzSequence | Indexr>rr>rWrTr1)!r)r*r+�__doc__r�
PackageLoaderr3�Environment�env�get_templater�r�r�r�r�rprxr�r�r�rvr{r�r�r�r�r�r�r�r�r9rCrOr-r.r/r1r1Csc����
!�
!�(�,B�
C�F�
�
�
�F��
�
=�C��$�$�Z�0�M��*�*�+;�<���*�*�+;�<���%�%�k�2�N��&�&�|�4�O�
 ��)-�'+�-1�� $�AR� �AR��AR��	AR�
'�AR�%�
AR�+�AR��AR��AR�
�AR�N $�#��
+��+��+��	+�
�+��
+�b $�#�
��
��
��	
�
�
�

�
�(
/� �
/�26�
/�@J�
/�	�
/�& $�#�
0��
0��
0��	
0�
�
0�

�
0��* $�#��!%�n��n��n��	n�
�n��
n��n�`:�x];��];�(+�];�:>�];�~=+��=+�(+�=+�:>�=+�~,�h��&��&��&��	&�
�&��
&��&�
�&�P4$�lo$��o$��o$��	o$�bd�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�	\� �\��\�*�	\�

�\r.r1c�&�d|vr||d<||||d�|�S)z]
    Template to return container with information for a <td></td> or <th></th> element.
    r�)rr��classrr-)�html_element�
html_classr�rr�s     r/r�r�s6���f�$�"'������� �	�
��r.c�|���fd�}|r	||kDr|n|}|r	||kDr|n|}||z|kDr|||�\}}||z|kDr�||fS)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��||k\r|t|�z�fSt|�z�|fSrF)rR)r!�cn�scaling_factors  �r/�
scale_downz*_get_trimming_maximums.<locals>.scale_downKs4���
��8��s�2��.�/�/�/��r�N�*�+�R�/�/r.r-)r!rcr�r~rrdres     ` r/r�r�/s_���80���h��X�B����h��X�B��
�r�'�L�
 ��B��#���B�
�r�'�L�
 ��r�6�Mr.c���t|t�r"|jtjd��}n|jd��}|�g}i}t|t�s!t
|�D]\}}||vs�d|d|f<�|St
|�D]�\}}d}	t
|�D]�\}
}|	|kDr� |s|
|vs�d|||
f<|	dz
}	�!|tjur|
|vr|
}d|||f<|	dz
}	�F|tjur
|
}d|||f<�b|
|vs�g|	dz
}	|	|kDr��||fdk(r
|
}d|||f<��|||fxxdz
cc<����|j�D�
�cic]\}
}|dk\s�|
|��}}
}|Scc}}
w)aZ
    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)rMr�
_format_multir�
no_default�_format_flatrwrz)rPrg�	max_index�hidden_elements�levels�lengthsr�r�r#r��jr;�
last_labelr�length�non_zero_lengthss                r/r�r�\s���4�%��$��$�$�c�n�n�E�$�R���#�#��#�7�������G��e�Z�(�!�&�)�H�A�u���'�"#���A���*����F�#���3�����n�F�A�s� �9�,����O�+�&'�G�Q��F�O�%��*�%��S�^�^�+�!�?�2J��
�+,���J��(�!�Q�&�!��C�N�N�*��
�+,���J��(��/�)�!�Q�&�!�$�y�0���A�z�?�+�q�0�!"�J�/0�G�Q�
�O�,��Q�
�O�,��1�,�;%�$�D07�}�}���/>�O�G�V�&�A�+����������	s�
E�Ec��||f|vS)z/
    Index -> {(idx_row, idx_col): bool}).
    r-)�idx_row�idx_colrps   r/r�r��s��
�W���(�(r.c�p�|D��cgc]#}|djd�D]
}||dd����%c}}Scc}}w)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   r/r�r��sP�����H� ��,�2�2�3�7�H����(9�:�7�	;�����s�(2c��t|�st|�r|r|d|�d��S|d|�d��St|�r|r|d�St|�S|S)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&ry)rrrr%)r�rFr*s   r/rHrH�sY��$��{�j��m�(1�!�B�y�k��?�#�K�!�A�i�[��>�9J�K�	�A��$�!�A��0�#�a�&�0��Hr.c��������fd�}|S)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�n��t|�st|�st|�r��dk7r?��=�dk7r8�|�jdd�jd��jd��S�dk7r���dk(r�|�jd��S�dk(r���dk7r�|�jd��S�|�S)Nr&ryu§_§-)rrrr�)r�r)r2r*s ���r/�wrapperz(_wrap_decimal_thousands.<locals>.wrapper�s�����A�;�*�Q�-�:�a�=��#�~�)�"7�I��<L��a�L��W�S�(�+��W�S�'�*��W�X�y�1�	��C��Y�%6�)�s�:J� ��|�+�+�C��9�9��C��I�$9�i�3�>N� ��|�+�+�C��;�;���|�r.r-)r2r)r*r�s``` r/�_wrap_decimal_thousandsr��s���
��Nr.c��t|t�r>|dk(rt|�S|dk(rt|�S|dk(rt	|�Std|����|S)z/if escaping: only use on str, else return input�html�latexz
latex-mathz@`escape` only permitted in {'html', 'latex', 'latex-math'}, got )rMr%�escape_html�
_escape_latex�_escape_latex_mathr)r�r"s  r/�_str_escaper��sg���!�S���V���q�>�!�
�w�
� ��#�#�
�|�
#�%�a�(�(����H���
�
�Hr.c���t|t�r7|dk(rd�n|dk(rd�ntd��d}tj|�fd�|�S|S)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���j|jd��Sr)r9�group)�m�hrefs �r/rIz_render_href.<locals>.<lambda>s���T�[�[������%<r.)rMr%r�re�sub)r�r9�patr�s   @r/�_render_hrefr�sQ����!�S���V��:�D�
�w�
�)�D��R�S�S�V���v�v�c�<�a�@�@��Hr.c�L������	�
�t�t�r�fd��nKt��r��n=��$|�td�n|}t	t
||du���nt
dt����������fd�}n�}|dk7s|�|dk7rt|||�	��	n|�	���	�fd
��
n�	�
���
S�
�fd�S)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�&���j|�SrF�r9)r�r2s �r/rIz'_maybe_wrap_formatter.<locals>.<lambda>%s���9�+�+�A�.r.NrB)rFr*z*'formatter' expected str or callable, got c�*���t|����S)Nr!)r�)r�r"�func_0s ��r/rIz'_maybe_wrap_formatter.<locals>.<lambda>4s���6�+�a��"?�@r.r&ry)r)r*c�*���t|����S)Nr�)r�)r��func_2r+s ��r/rIz'_maybe_wrap_formatter.<locals>.<lambda>@s���6�,�q��"D�Er.c�2��t|�dur�S�|�S)NT)r)r��func_3r(s ��r/rIz'_maybe_wrap_formatter.<locals>.<lambda>Hs���D��G�t�O��C�&��)�Cr.)	rMr%�callablerrrHrOrr�)r2r(rFr)r*r"r+�func_1r�r�r�s``   `` @@@r/r1r1s�����)�S�!�.��	�)�	���	�	�5>�5F�J�0�1�I�	���)�	�QU�@U�
���D�T�)�_�DU�V�W�W���@�����#�~�)�/�I��4D�(���I�V������E�����~��
�C�Cr.c�J�ttjttt
f}t
||�r
tdd�|f}dd�}t|�s-t
|t�s|gg}t|�S|g}t|�S|D�cgc]}||�r|n|g��}}t|�Scc}w)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��t|t�rtd�|D��St|t�xst	|�S)z�
        Returns
        -------
        bool
            True if slice does *not* reduce,
            False if `part` is a tuple.
        c3�VK�|]!}t|t�xst|����#y�wrF)rMr,r)�.0�ss  r/�	<genexpr>z3non_reducing_slice.<locals>.pred.<locals>.<genexpr>ds$����O�$�Q�
�1�e�,�?��Q��?�$�s�'))rMr��anyr,r)�parts r/�predz non_reducing_slice.<locals>.predXs6���d�E�"��O�$�O�O�O��d�E�*�@�l�4�.@�@r.�rTrR)r�np�ndarrayrrer%rMrrr,r�)�slice_�kindsr��ps    r/r-r-Ks�����
�
�E�4��5�E��&�%� ��A�v�I�&��A� ����&�%�(��h�Z�F���=���X�F�
��=��28�8��A�t�A�w�!�Q�C�'���8���=���9s�?B c�V�t|t�rw|jd�}	|D�cgc]Y}|j�dk7rD|jd�dj�|jd�dj�f��[c}S|Scc}w#t$rtd|�d���wxYw)z�
    Convert css-string to sequence of tuples format if needed.
    'color:red; border:1px solid black;' -> [('color', 'red'),
                                             ('border','1px solid red')]
    �;r��:rr�zSStyles supplied as string must follow CSS rule formats, for example 'attr: val;'. 'z' was given.)rMr%r{�strip�
IndexErrorr)�styler�r�s   r/�maybe_convert_css_to_tuplesr�vs����%����K�K����
	����A��7�7�9��?������a��&�&�(�!�'�'�#�,�q�/�*?�*?�*A�B���
��L����
�	��.�.3�W�L�B��
�	�s�B�AB
�B�
B�B(c�\�|� tt|j��}|St|t�r|g}|St|t
�r|j
|�g}|St|t�r2|D�cgc]%}t|t�s|j
|�n|��'}}|Std��cc}w)aX
    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)rerr`rMrRr%r=r)r>rr@�levs    r/r<r<�s���$
�}�!�%����"4�5���N�
�E�3�	��'���N�
�E�3�	��(�(��/�0���N�
�E�4�	 ��
���/9��c�.B�C�!�!�#�&��K��	�
��N��O�P�P��
s�0*B)c�\�eZdZdZgd�de�f							d	d�Zed��Zd
d�Zdd�Z	y)�Tooltipsa�
    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)zz-indexr�)�background-color�black)�color�white)�	transformztranslate(-20px, -20px)zpd-tc�<�||_||_||_g|_yrF)�
class_name�class_properties�tt_datarX)ro�	css_props�css_namerks    r/rpzTooltips.__init__�s"��#��� )������')��r.c�N�d|j��t|j�d�gS)a
        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&rz)r�r�r�)ros r/�
_class_styleszTooltips._class_styles�s0�� ����0�1�4�T�5J�5J�K�
�
�	
r.c��d|zdzt|�zdzt|�z}|d|��zdgd�|d|�d�zd	d
|�d
�fgd�gS)a:
        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_rt�_colz:hover .)r��visiblerzz .z::after�contentr�)r%)rorUr�r;r:�text�selector_ids       r/�_pseudo_csszTooltips._pseudo_css�sz��>�d�l�V�+�c�#�h�6��?�#�c�(�J��(�H�T�F�*;�;�3�4�
�
(�B�t�f�G�*<�<�$��$��q�k�2�3�
�	
�		
r.c��|jj|j�|_|jjr|S|j}|jj�|jj
d�z}tt|jj��D��cgc]�}tt|jj��D]p}|j||fs]||jvsO||jvsA|j|j|||t!|jj||f����r��c}}D��cgc]}|D]}|���
c}}|_|j"rx|dD]4}	|	D]-}
|
ddk(s�t!|
d�d|j�d�z|
d<�/�6|dj%|j&�|dj%|j"�|Scc}}wcc}}w)	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�rrr�z
<span class="z	"></span>rX)r��reindex_liker?�emptyr�r�eqrrVrPrQ�ilocrcrdr�rUr%rXr�r�)ro�stylerr�r��maskr�rq�sublistr�r;�items           r/r{zTooltips._translates���*�|�|�0�0����=����<�<����H��������!�!�#�������(;�<��
�s�4�<�<�#5�#5�6�7�	�7�A��s�4�<�<�#7�#7�8�9�A��I�I�a��d�O��F�.�.�.��F�1�1�1�
� � ����d�A�q�#�d�l�l�>O�>O�PQ�ST�PT�>U�:V�W�9�X�7�	�

�	��!��
�!�
�	�

��������y���D��F�|�t�+���_� 5�6� -�d�o�o�->�i�H�I��_�-� �!�
�n��$�$�T�%7�%7�8�
�n��$�$�T�%6�%6�7����3	��

s
�0B"G8�G>N)r�r'r�r%rkrrTrU)
rUr%r�r%r;rRr:rRr�r%)r�r1r�r/)
r)r*r+rXrrp�propertyr�r�r{r-r.r/r�r��s`���>$
��'�k�*� �*��*��*�
�*�$�
��
�")
�V6r.r�c�L��gd��|duxrt�fd�|D��xs|duS)a8
    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_formatNc3�,�K�|]}|d�v���
y�w)r&Nr-)r�r��IGNORED_WRAPPERSs  �r/r�z._parse_latex_table_wrapping.<locals>.<genexpr>`s�����L�|�!��*�
�%5�5�|�s�)r�)rXrZr�s  @r/r�r�Ts>���M��	�D� �	M��L�|�L�L��
��	�r.c�z�|ddd�D]0}|d|k(s�t|ddd�jdd�cSy)	uy
    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.
    N���r&r(rr��§r�)r%r�)rXr&r�s   r/r�r�dsO��"�d��d�#������(��u�W�~�a�(��+�,�4�4�T�3�?�?�$�r.c
��|rt|�}|ddd�D]n\}}d|�d|�d�d|�d|��d|�d|��d|�d|�d�d|�d	|�d�d
�}d|�|�d|��}dD]1}|t|�vs�||jd
t||���}�n�p|S)a�
    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�optionsr2r�s       r/r�r�{s���8�2�<�@��(��2��.�����W�I�[���r�B��W�I�[���@��g�Y�m�M�?�C��G�9�L���r�B��g�Y�n�]�O�2�F�
�	��W�I�g�Y�a�
��?�
�J�C��c�'�l�"� )�#�� 6� 6� �"<�7�PS�"T�!�
��K�/��r.c���t|d|d|�}d|vr�|d}d|vr�||jd�dzd}t|d|jd��}d|k(r|rd	|�d
�n|�}|rdnd}	||	|d
z
zzSd|k(r|rd	|�d
�n|�}|rdnd}	|	|d
z
z|zSd|�d|�d|�d
�Sd|vrG|dk(r|S||jd�dzd}
t|
d|
jd��}
d|�d|
�d|�d
�S|rd	|�d
�S|S)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�znaive-l�{rz & {}z &r�znaive-rz{} & z& z
\multicolumn{z}{r
�naivez
\multirow[z]{z}{*}{)r��findrR)�cell�multirow_align�multicol_align�wrapr��display_val�attrs�colspan�out�blanks�rowspans           r/r�r��s���4+��[��4��0�+��K��t���\�"���%���E�J�J�{�3�a�7�9�:�G��'�"5�G�L�L��$5�6�7�G��N�*�.2��;�-�r�*�;�-��$(��d���V�w��{�3�3�3��n�,�.2��;�-�r�*�;�-��$(��d����1��-��3�3�$�W�I�T�.�1A��k�]�RT�U�U�
�E�
!���(�"�"��E�J�J�{�3�a�7�9�:�G��'�"5�G�L�L��$5�6�7�G� �� 0��G�9�I�k�]�RT�U�U���K�=��#�#��r.c��t|�j|d�jdd�jdd�j�S)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  r/r�r��s>���u�:���c�2�&�.�.�t�R�8�@�@��r�J�P�P�R�Rr.c�t�d�}d�}d�}|t|dd��t|dd��|d	�}g}|D]�\}}t|t�r'd
|vr#|j||j	d
d�f�||vs�Bd}dD]}	|	t|�vs�|	t||	�}}n||||�}
|
��w|j
|
g���|S)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��|dvrd|�fSy)N)�bold�bolder�bfseriesr-r�s  r/�font_weightz0_parse_latex_css_conversion.<locals>.font_weight�s���&�&��#��'�'�r.c�,�|dk(rd|�fS|dk(rd|�fSy)N�italic�itshape�oblique�slshaper-r�s  r/�
font_stylez/_parse_latex_css_conversion.<locals>.font_style�s/���H�����&�&��I�����&�&�r.c	��|dk7r|n|}|ddk(r)t|�dk(r|d|ddj��d|��fS|ddk(r\t|�d	k(rN|dj�d
z�|d
j�d
z�|dj�d
z��}|d|�d|��fS|dddk(�r!tjd
|�dj	�}d|vrt|dd�dzn
t
|�dz}tjd|�dj	�}d|vrt|dd�dzn
t
|�dz}|ddk(r(tjd|�dj	�}n'tjd|�dj	�}d|vrt|dd�dzn
t
|�dz}|d|d�d|d�d|d�d|��fS|d|�d|��fS)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�)rV�upperr��findallr��floatrR)	r��user_argr��comm_argr��valr��g�bs	         r/r�z*_parse_latex_css_conversion.<locals>.color�s��#�b�.�h�h����8�s�?�s�5�z�Q���h�u�Q�R�y���'8�&9��C�5�A�A�A���8�s�?�s�5�z�Q���1�X�^�^�%�a�'�(��q����)9�!�);�(<�U�1�X�^�^�=M�a�=O�<P�Q�C��h�s�e�2�c�U�3�3�3�
�2�A�Y�%�
��
�
�4�e�<�Q�?�E�E�G�A�'*�a�x��a���f�
��#�S��V�c�\�A��
�
�2�E�:�1�=�C�C�E�A�'*�a�x��a���f�
��#�S��V�c�\�A��Q�x�3���J�J�6��>�q�A�G�G�I���J�J�8�%�@��C�I�I�K��'*�a�x��a���f�
��#�S��V�c�\�A��g�a��W�B�q��g�R��#�w�b���F�F�F��b���r�#��/�/�/r.�	cellcolorr�)r�rr�r�)zfont-weightr�r�z
font-stylez--latex)r�r�r�r�r�)rrMr%ryr�r�r�)r|r	rr��CONVERTED_ATTRIBUTESr��	attributer�r�r��latex_styles           r/r�r��s����
�0�D#�#�E�;��S����"�=� �	1���L�"��	�5��e�S�!�i�5�&8�����E�M�M�)�R�,H� I�J��,�,��C�L����E�
�?�!"�$>�u�a�$H��C��M�:�.�y�9�%��E�K��&��#�#�[�M�2�#��r.c���|jdd�jdd�jdd�jdd�jd	d
�jdd�jd
d�jdd�jdd�jdd�jdd�jdd�jdd�jdd�S)al
    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�uab2§=§8yzuab2§=§8yz uab2§=§8yz\space �&z\&rz\%�$�\$rz\#r�z\_r�z\{rz\}z~ z~\space �~z\textasciitilde z^ z^\space �^z\textasciicircum z\textbackslash )r�)r�s r/r�r�8	s���$	
�	�	�$�
�&�	���!6�	7�	���e�	�	���e�	�	���e�	�	���e�	�	���e�	�	���e�	�	���e�	�	���{�	#�	���)�	*�	���{�	#�	���*�	+�	��� 2�	3�r.c	��|jdd�}tjd�}d}|j||�}g}|ru|j	t|||j
�d��|j	|j��|j
�d}|j||�}|r�u|j	t||t|���dj|�jdd�S)al
    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
    r*�rt8§=§7wz�\$.*?\$rr�r�)
r�r��compile�searchryr��spanr�rV�join)r��pattern�pos�ps�ress     r/�_math_mode_with_dollarr8[	s���$	
�	�	�%��(�A��j�j��$�G�
�C�	����3�	�B�
�C�
��
�
�=��3�����1��!6�7�8��
�
�2�8�8�:���g�g�i��l��
�^�^�A�s�
#��	
��J�J�}�Q�s�S��V�_�-�.�
�7�7�3�<�����6�6r.c�D�|jdd�jdd�}g}tjd|�D]�}|jd�rC|j	d�r2|j|jdd�jdd���Wd|vr?d|vr;|jt
|�jdd�jdd����|jt
|�jdd�jdd	����d
j|�S)an
    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
    �\(uLEFT§=§6yzLEFTz\)uRIGHTab5§=§RIGHTuLEFT§=§6yz|ab5§=§RIGHT�LEFT�RIGHTz\textbackslash (z\textbackslash )r�)r�r�r{�
startswith�endswithryr�r3)r�r7r�s   r/�_math_mode_with_parenthesesr?|	s���$	
�	�	�%�,�-�5�5�e�=R�S�A�
�C����6��:���?�?�6�"�t�}�}�W�'=��J�J�t�|�|�F�E�2�:�:�7�E�J�K�
�t�^��4���J�J��d�#�+�+�F�E�:�B�B�7�E�R�
�
�J�J��d�#����!4�5����"5�6�
�;��7�7�3�<�r.c��|jdd�}tjd�j|d�}tjd�j|d�}g}|r"|j	|j�d�|r"|j	|j�d�t
|�dk(rt|jdd��S||ddk(rt|jdd��S||ddz
|ddzdk(rt|jdd��St|jdd��S)	a�
    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
    r*r.r/rz\(.*?\)r)r�r:)
r�r�r0r1ryr2rVr�r8r?)r��ps_d�ps_p�modes    r/r�r��	s��$	
�	�	�%��(�A�
�:�:�j�!�(�(��A�.�D�
�:�:�j�!�(�(��A�.�D�
�D�����D�I�I�K��N�#�����D�I�I�K��N�#�
�4�y�A�~��Q�Y�Y�~�u�=�>�>���a��z�T��%�a�i�i���&F�G�G���a��1��t�A�w��{�#�u�,�*�1�9�9�^�U�+K�L�L��Q�Y�Y�~�u�=�>�>r.)
r_r%r`rQr�rrrRrTr/)NNg�������?)rdrrTztuple[int, int]rF)rPrrgrRrmrRrnzSequence[int] | Noner�)r|�	CSSStylesrTrD)F)r�rrFrRr*rRrTr)r2r	r)r%r*rQrTr	)NNNr&NNN)r2zBaseFormatter | Noner(rQrFrSr)r%r*rQr"rQr+rQrTr	)r��Subset)r�r'rT�CSSList)r>rWrrrTz	list[int])rXrDrZrQrTrR)rXrDr&r%rTrQ)r�rFr�r%r�rRrTr%)FF)r�zdict[str, Any]r�r%r�r%r�rRr�rRrTr%)r�zstr | floatr�r%rTr%)r|rFrTrF)r�r%rTr%)\�
__future__r�collectionsr�collections.abcr�	functoolsrr��typingrrr	r
rrr
rUr�numpyr��pandas._configr�pandas._libsr�pandas.compat._optionalr�pandas.core.dtypes.commonrrr�pandas.core.dtypes.genericrr2rrrrrr�pandas.api.typesr�pandas.core.common�core�commonr��pandas._typingrrr�
markupsafer"r�r%�
BaseFormatterr/�ExtFormatterr�r�CSSPairrerFr'r$rDr,rEr1r�r�r�r�r�rHr�r�r�r1r-r�r<r�r�r�r�r�r�r�r�r8r?r�r-r.r/�<module>r[s��"�#�$��	������%��>���
1���*� � ���
$�H�4V�	W��,��c�8�m�$�
��]�D��h�}�.E�)E�$F�F�G��
��U�3��:�&�&�
'��
�w�-���c�7�l�#�
��i��

��M�	�	�u�h��%�	&��T�T�n.��������	�
�
�2�
��
*��
*��*�b-1�	N��N��N��N�*�	N�b)��
�2���"%��2<��
��6
�"
�'+�� �� ��!�3D�#�3D��3D��3D��	3D�
�3D�
�
3D��3D��3D�l(�V�,�%��	����Dc�c�L
� �0DI�-��-�*-�-�<@�-��-�h��4�
�4��4��4��	4�
�4�	�
4�nS�I�X �F7�B!�H!?r.

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists