o
    ,&]i$                     @  s   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ er<d dlmZ d dlmZ d d	lmZ d d
lmZ d0ddZd0ddZd1ddZd2ddZe	deeef dZd3d d!Z	"d4d5d'd(Zd6d+d,Zd7d-d.Z d/S )8    )annotations)defaultdict)Mapping)TYPE_CHECKINGAnyTypeVar)dataframe_util)StreamlitAPIException)	DataFrame)Styler)Arrow)Enumproto
ArrowProtostylerr   default_uuidstrreturnNonec                 C  s   ddl }|j}|jt|jjjjkr&td|j d|jjjj d|j dt	| || |
  |dd}t| | t| || t| || dS )ao  Marshall pandas.Styler into an Arrow proto.

    Parameters
    ----------
    proto : proto.Arrow
        Output. The protobuf for Streamlit Arrow proto.

    styler : pandas.Styler
        Helps style a DataFrame or Series according to the data with HTML and CSS.

    default_uuid : str
        If pandas.Styler uuid is not provided, this value will be used.

    r   NzThe dataframe has `zc` cells, but the maximum number of cells allowed to be rendered by Pandas Styler is configured to `z`. To allow more cells to be styled, you can change the `"styler.render.max_elements"` config. For example: `pd.set_option("styler.render.max_elements", z)`F)pandasdatasizeintoptionsr   rendermax_elementsr	   _marshall_uuid_compute
_translate_marshall_caption_marshall_styles_marshall_display_values)r   r   r   pdstyler_data_dfpandas_styles r%   h/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/elements/lib/pandas_styler_utils.pymarshall_styler!   s    

	
r'   c                 C  s&   |j du r
|| t|j | j_ dS )at  Marshall pandas.Styler uuid into an Arrow proto.

    Parameters
    ----------
    proto : proto.Arrow
        Output. The protobuf for Streamlit Arrow proto.

    styler : pandas.Styler
        Helps style a DataFrame or Series according to the data with HTML and CSS.

    default_uuid : str
        If pandas.Styler uuid is not provided, this value will be used.

    N)uuidset_uuidr   r   )r   r   r   r%   r%   r&   r   J   s   

r   c                 C  s   |j dur|j | j_ dS dS )a  Marshall pandas.Styler caption into an Arrow proto.

    Parameters
    ----------
    proto : proto.Arrow
        Output. The protobuf for Streamlit Arrow proto.

    styler : pandas.Styler
        Helps style a DataFrame or Series according to the data with HTML and CSS.

    N)captionr   )r   r   r%   r%   r&   r   _   s   
r   stylesMapping[str, Any]c                 C  s   g }d|v r!|d }t |}|D ]}td||jdd}|| qd|v r@|d }t |}|D ]}td||jdd}|| q/t|dkrOd|| j_d	S d	S )
aR  Marshall pandas.Styler styles into an Arrow proto.

    Parameters
    ----------
    proto : proto.Arrow
        Output. The protobuf for Streamlit Arrow proto.

    styler : pandas.Styler
        Helps style a DataFrame or Series according to the data with HTML and CSS.

    styles : dict
        pandas.Styler translated styles.

    table_styles )	separator	cellstyle
cell_style_r   
N)_trim_pandas_styles_pandas_style_to_cssr(   appendlenjoinr   r+   )r   r   r+   	css_rulesr-   styleruler0   r%   r%   r&   r    o   s4   r    M)boundlist[M]c                 C  s   dd | D S )zFilter out empty styles.

    Every cell will have a class, but the list of props
    may just be [['', '']].

    Parameters
    ----------
    styles : list
        pandas.Styler translated styles.

    c                 S  s&   g | ]}t d d |d D r|qS )c                 s  s    | ]}t |V  qd S )Nany).0yr%   r%   r&   	<genexpr>   s    z1_trim_pandas_styles.<locals>.<listcomp>.<genexpr>propsr?   )rA   xr%   r%   r&   
<listcomp>   s   & z'_trim_pandas_styles.<locals>.<listcomp>r%   )r+   r%   r%   r&   r4      s   r4   r2   
style_typer:   r(   r/   c                   s   g }|d D ]\}}t | d t |  }|| qd| | dkr,|d gn|d } fdd|D }	d	|	}
d
|}|
d | d S )aT  Convert pandas.Styler translated style to CSS.

    Parameters
    ----------
    style_type : str
        Either "table_styles" or "cell_style".

    style : dict
        pandas.Styler translated style.

    uuid : str
        pandas.Styler uuid.

    separator : str
        A string separator used between table and cell selectors.

    rD   z: z#T_r-   selector	selectorsc                   s   g | ]}  | qS r%   r%   )rA   cell_selectorr/   table_selectorr%   r&   rF      s    z(_pandas_style_to_css.<locals>.<listcomp>z, z; z { z })r   stripr6   r8   )rG   r:   r(   r/   declarationscss_property	css_valuedeclarationcell_selectorsrI   rH   declaration_blockr%   rK   r&   r5      s   


r5   dfr
   c                 C  s   t ||}t|| j_dS )a0  Marshall pandas.Styler display values into an Arrow proto.

    Parameters
    ----------
    proto : proto.Arrow
        Output. The protobuf for Streamlit Arrow proto.

    df : pandas.DataFrame
        A dataframe with original values.

    styles : dict
        pandas.Styler translated styles.

    N)_use_display_valuesr    convert_pandas_df_to_arrow_bytesr   display_values)r   rT   r+   new_dfr%   r%   r&   r!      s   
r!   c                 C  s   ddl }| t}|d}tt}|dg D ]9}|D ]4}|d}|s&q||}	|	s.qtt	|	
 \}
}|d}t|trFt|jnt|}||| |
< qq| D ]\}}t| }t| }||j||f< qV|S )zCreate a new pandas.DataFrame where display values are used instead of original ones.

    Parameters
    ----------
    df : pandas.DataFrame
        A dataframe with original values.

    styles : dict
        pandas.Styler translated styles.

    r   Nzrow(\d+)_col(\d+)bodyiddisplay_value)reastyper   compiler   dictgetmatchmapr   groups
isinstancer   valueitemslistkeysvaluesiloc)rT   r+   r\   rX   cell_selector_regexupdates_by_colrowcellcell_idra   row_idxcol_idxr[   	str_valuevalues_by_rowrow_indicesri   r%   r%   r&   rU      s2   




rU   N)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r+   r,   r   r   )r+   r>   r   r>   )r2   )
rG   r   r:   r,   r(   r   r/   r   r   r   )r   r   rT   r
   r+   r,   r   r   )rT   r
   r+   r,   r   r
   )!
__future__r   collectionsr   collections.abcr   typingr   r   r   	streamlitr   streamlit.errorsr	   r   r
   pandas.io.formats.styler   streamlit.proto.Arrow_pb2r   r   enumr   r'   r   r   r    r   r<   r4   r5   r!   rU   r%   r%   r%   r&   <module>   s*   

)

1

4