o
    h                     @  s   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r6d dlmZ d dlmZ d dlmZ d.ddZd.ddZd/ddZd0ddZedeeef dZd1ddZ	 d2d3d%d&Zd4d)d*Zd5d+d,Zd-S )6    )annotations)Mapping)TYPE_CHECKINGAnyTypeVar)dataframe_util)StreamlitAPIException)	DataFrame)Styler)Arrow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#   ^/var/www/vscode/kcb/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   G   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ruler.   r#   r#   r$   r   l   s$   
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=   )r?   xr#   r#   r$   
<listcomp>   s   & z'_trim_pandas_styles.<locals>.<listcomp>r#   )r)   r#   r#   r$   r2      s   r2   r0   
style_typer8   r&   r-   c                 C  s   g }|d D ]\}}t | d t |  }|| qd| }| dkr-|d g}	n|d }	g }
|	D ]}|
|| |  q5d|
}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.

    rB   z: z#T_r+   selector	selectorsz, z; z { z })r   stripr4   r6   )rE   r8   r&   r-   declarationscss_property	css_valuedeclarationtable_selectorcell_selectorsrG   cell_selectorrF   declaration_blockrule_setr#   r#   r$   r3      s   


r3   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   rR   r)   new_dfr#   r#   r$   r      s   
r   c                 C  s   ddl }| t}|d}d|v rA|d }|D ](}|D ]#}d|v r?||d  }r?tt| \}	}
t|d |j|	|
f< qq|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   compilematchmapr   groupsiloc)rR   r)   rZ   rV   cell_selector_regexrowsrowcellr]   rcr#   r#   r$   rS      s   

rS   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<   )r0   )
rE   r   r8   r*   r&   r   r-   r   r   r   )r   r   rR   r	   r)   r*   r   r   )rR   r	   r)   r*   r   r	   )
__future__r   collections.abcr   typingr   r   r   	streamlitr   streamlit.errorsr   r   r	   pandas.io.formats.styler
   streamlit.proto.Arrow_pb2r   r   r%   r   r   r   r   r:   r2   r3   r   rS   r#   r#   r#   r$   <module>   s&   

)

)

7