Ë
    úmxirA  ã                  ó*  — U d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ e	rd dlZd d
lmZmZmZ d dlmZ ed   Z dZ!de"d<   dZ# G d„ de$e«      Z%e&e$e%f   Z'de"d<   e%jP                  e%jR                  ge%jT                  e%jV                  e%jX                  e%jP                  e%jZ                  e%jR                  ge%j\                  e%jP                  e%jT                  e%jR                  ge%jP                  e%j\                  e%jT                  e%jV                  e%jR                  ge%j^                  e%j`                  e%jR                  ge%jb                  e%j`                  e%jR                  ge%j`                  e%j^                  e%jb                  e%jR                  ge%jP                  e%jR                  ge%jd                  e%jP                  e%jR                  ge%jd                  e%jP                  e%jR                  gdœ
Z3de"d<   d$d„Z4d%d„Z5	 	 	 	 d&d„Z6	 	 	 	 d&d„Z7	 d'	 	 	 	 	 d(d„Z8	 	 	 	 	 	 d)d„Z9e&e e$z  e:z  ef   Z;de"d<   ee e$z  edz  e$z  f   Z<de"d<   	 d'	 	 	 d*d„Z=	 	 	 	 	 	 	 	 d+d „Z>	 	 	 	 	 	 d,d!„Z?d-d"„Z@	 	 	 	 	 	 d.d#„ZAy)/é    )ÚannotationsN)ÚMapping)ÚEnum)ÚTYPE_CHECKINGÚAnyÚFinalÚLiteralÚ	TypeAlias)Ú
DataFormat)ÚColumnConfigÚ
ColumnType)Úremove_none_values)ÚStreamlitAPIException)Ú	DataFrameÚIndexÚSeries)ÚArrowÚ_indexÚIndexIdentifierTypeÚINDEX_IDENTIFIERz_pos:c                  óP   — e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZy)ÚColumnDataKindÚintegerÚfloatÚdateÚtimeÚdatetimeÚbooleanÚstringÚ	timedeltaÚperiodÚintervalÚbytesÚdecimalÚcomplexÚlistÚdictÚemptyÚunknownN)Ú__name__Ú
__module__Ú__qualname__ÚINTEGERÚFLOATÚDATEÚTIMEÚDATETIMEÚBOOLEANÚSTRINGÚ	TIMEDELTAÚPERIODÚINTERVALÚBYTESÚDECIMALÚCOMPLEXÚLISTÚDICTÚEMPTYÚUNKNOWN© ó    úa/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/elements/lib/column_config_utils.pyr   r   .   sW   „ Ø€GØ€EØ€DØ€DØ€HØ€GØ€FØ€IØ€FØ€HØ€EØ€GØ€GØ€DØ€DØ€EØ�Gr?   r   r
   ÚDataframeSchema)
ÚtextÚnumberÚcheckboxÚ	selectboxr   r   r   Úlinkr&   Úmultiselectz-Final[dict[ColumnType, list[ColumnDataKind]]]Ú_EDITING_COMPATIBILITY_MAPPINGc                ó*   — | t         vry|t         |    v S )a.  Check if the column type is compatible with the underlying data kind.

    This check only applies to editable column types (e.g. number or text).
    Non-editable column types (e.g. bar_chart or image) can be configured for
    all data kinds (this might change in the future).

    Parameters
    ----------
    column_type : ColumnType
        The column type to check.

    data_kind : ColumnDataKind
        The data kind to check.

    Returns
    -------
    bool
        True if the column type is compatible with the data kind, False otherwise.
    T)rH   )Úcolumn_typeÚ	data_kinds     r@   Úis_type_compatiblerL   v   s!   € ð* Ô8Ñ8ØàÔ6°{ÑCÐCÐCr?   c                ó   — ddl }| j                  }|j                  j                  |«      rt        j
                  S |j                  j                  |«      rt        j                  S |j                  j                  |«      rt        j                  S |j                  j                  |«      rt        j                  S |j                  j                  |«      rt        j                  S |j                  j                  |«      rt        j                  S |j                  j!                  |«      rt        j"                  S |j                  j%                  |«      rt        j&                  S |j                  j)                  |«      rt        j*                  S |j                  j-                  |«      rt        j.                  S |j                  j1                  |«      rt        j2                  S |j                  j5                  |«      rt        j6                  S |j                  j9                  |«      rt        j:                  S t        j<                  S )al  Determine the data kind via the arrow type information.

    The column data kind refers to the shared data type of the values
    in the column (e.g. int, float, str, bool).

    Parameters
    ----------
    field : pa.Field
        The arrow field from the arrow table schema.

    Returns
    -------
    ColumnDataKind
        The data kind of the field.
    r   N)ÚpyarrowÚtypeÚtypesÚ
is_integerr   r-   Úis_floatingr.   Ú
is_booleanr2   Ú	is_stringr3   Úis_dater/   Úis_timer0   Úis_timestampr1   Úis_durationr4   Úis_listr:   Ú
is_decimalr8   Úis_nullr<   Ú	is_binaryr7   Ú	is_structr;   r=   )ÚfieldÚpaÚ
field_types      r@   Ú_determine_data_kind_via_arrowra   ‘   s¤  € ó  à—‘€JØ	‡x�x×Ñ˜:Ô&Ü×%Ñ%Ð%à	‡x�x×Ñ˜JÔ'Ü×#Ñ#Ð#à	‡x�x×Ñ˜:Ô&Ü×%Ñ%Ð%à	‡x�x×Ñ˜*Ô%Ü×$Ñ$Ð$à	‡x�x×Ñ˜
Ô#Ü×"Ñ"Ð"à	‡x�x×Ñ˜
Ô#Ü×"Ñ"Ð"à	‡x�x×Ñ˜ZÔ(Ü×&Ñ&Ð&à	‡x�x×Ñ˜JÔ'Ü×'Ñ'Ð'à	‡x�x×Ñ˜
Ô#Ü×"Ñ"Ð"à	‡x�x×Ñ˜:Ô&Ü×%Ñ%Ð%à	‡x�x×Ñ˜
Ô#Ü×#Ñ#Ð#ð 
‡x�x×Ñ˜*Ô%Ü×#Ñ#Ð#à	‡x�x×Ñ˜*Ô%Ü×"Ñ"Ð"ä×!Ñ!Ð!r?   c                ó  — ddl }| j                  }|j                  j                  j	                  |«      rt
        j                  S |j                  j                  j                  |«      rt
        j                  S |j                  j                  j                  |«      rt
        j                  S |j                  j                  j                  |«      rt
        j                  S |j                  j                  j                  |«      rt
        j                  S t        ||j                   «      rt
        j"                  S t        ||j$                  «      rt
        j&                  S |j                  j                  j)                  |«      rt
        j*                  S |j                  j                  j-                  |«      du r5|j                  j                  j/                  |«      rt
        j0                  S t
        j2                  S )a€  Determine the data kind by using the pandas dtype.

    The column data kind refers to the shared data type of the values
    in the column (e.g. int, float, str, bool).

    Parameters
    ----------
    column : pd.Series, pd.Index
        The column for which the data kind should be determined.

    Returns
    -------
    ColumnDataKind
        The data kind of the column.
    r   NF)ÚpandasÚdtypeÚapirP   Úis_bool_dtyper   r2   Úis_integer_dtyper-   Úis_float_dtyper.   Úis_datetime64_any_dtyper1   Úis_timedelta64_dtyper4   Ú
isinstanceÚPeriodDtyper5   ÚIntervalDtyper6   Úis_complex_dtyper9   Úis_object_dtypeÚis_string_dtyper3   r=   )ÚcolumnÚpdÚcolumn_dtypes      r@   Ú%_determine_data_kind_via_pandas_dtypert   Ò   sa  € ó$ à—<‘<€LØ	‡v�v‡|�|×!Ñ! ,Ô/Ü×%Ñ%Ð%à	‡v�v‡|�|×$Ñ$ \Ô2Ü×%Ñ%Ð%à	‡v�v‡|�|×"Ñ" <Ô0Ü×#Ñ#Ð#à	‡v�v‡|�|×+Ñ+¨LÔ9Ü×&Ñ&Ð&à	‡v�v‡|�|×(Ñ(¨Ô6Ü×'Ñ'Ð'ä�, §¡Ô/Ü×$Ñ$Ð$ä�, × 0Ñ 0Ô1Ü×&Ñ&Ð&à	‡v�v‡|�|×$Ñ$ \Ô2Ü×%Ñ%Ð%à	‡v�v‡|�|×#Ñ#Øóà	ñà—6‘6—<‘<×/Ñ/°Ô=ä×$Ñ$Ð$ä×!Ñ!Ð!r?   c                ó„  — ddl m}  || «      }|dk(  rt        j                  S |dk(  rt        j                  S |dv rt        j
                  S |dk(  rt        j                  S |dk(  rt        j                  S |dk(  rt        j                  S |d	k(  rt        j                  S |d
v rt        j                  S |dk(  rt        j                  S |dv rt        j                  S |dk(  rt        j                  S |dk(  rt        j                  S |dk(  rt        j                  S |dk(  rt        j                   S t        j"                  S )a�  Determine the data kind by inferring it from the underlying data.

    The column data kind refers to the shared data type of the values
    in the column (e.g. int, float, str, bool).

    Parameters
    ----------
    column : pd.Series, pd.Index
        The column to determine the data kind for.

    Returns
    -------
    ColumnDataKind
        The data kind of the column.
    r   )Úinfer_dtyper   r#   )Úfloatingzmixed-integer-floatr   r$   r%   r   )Ú
datetime64r   r   )Útimedelta64r    r   r!   r"   r(   )Úpandas.api.typesrv   r   r3   r7   r.   r-   r8   r9   r2   r1   r/   r4   r0   r5   r6   r<   r=   )rq   rv   Úinferred_types      r@   Ú&_determine_data_kind_via_inferred_typer|     s:  € õ$ -á Ó'€Mà˜Ò Ü×$Ñ$Ð$à˜ÒÜ×#Ñ#Ð#àÐ;Ñ;Ü×#Ñ#Ð#à˜	Ò!Ü×%Ñ%Ð%à˜	Ò!Ü×%Ñ%Ð%à˜	Ò!Ü×%Ñ%Ð%à˜	Ò!Ü×%Ñ%Ð%àÐ2Ñ2Ü×&Ñ&Ð&à˜ÒÜ×"Ñ"Ð"àÐ4Ñ4Ü×'Ñ'Ð'à˜ÒÜ×"Ñ"Ð"à˜Ò Ü×$Ñ$Ð$à˜
Ò"Ü×&Ñ&Ð&à˜ÒÜ×#Ñ#Ð#ô ×!Ñ!Ð!r?   c                ó*  — ddl }t        | j                  |j                  «      rt	        | j                  j
                  «      S |� t        |«      }|t        j                  k7  r|S | j                  j                  dk(  rt	        | «      S t        | «      S )a¸  Determine the data kind of a column.

    The column data kind refers to the shared data type of the values
    in the column (e.g. int, float, str, bool).

    Parameters
    ----------
    column : pd.Series, pd.Index
        The column to determine the data kind for.
    field : pa.Field, optional
        The arrow field from the arrow table schema.

    Returns
    -------
    ColumnDataKind
        The data kind of the column.
    r   NÚobject)rc   rk   rd   ÚCategoricalDtyper|   Ú
categoriesra   r   r=   Únamert   )rq   r^   rr   rK   s       r@   Ú_determine_data_kindr‚   M  s~   € ó( ä�&—,‘, × 3Ñ 3Ô4ô 6°f·l±l×6MÑ6MÓNÐNàÐÜ2°5Ó9ˆ	Øœ×.Ñ.Ò.ØÐà‡|�|×Ñ˜HÒ$ä5°fÓ=Ð=Ü0°Ó8Ð8r?   c                óæ   — i }t        | j                  «      |t        <   t        | j	                  «       «      D ]6  \  }}t        |d   «      }|d   }t        ||j                  |«      «      ||<   Œ8 |S )a¼  Determine the schema of a dataframe.

    Parameters
    ----------
    data_df : pd.DataFrame
        The dataframe to determine the schema of.
    arrow_schema : pa.Schema
        The Arrow schema of the dataframe.

    Returns
    -------
    DataframeSchema
        A mapping that contains the detected data type for the index and columns.
        The key is the column name in the underlying dataframe or ``_index`` for index columns.
    r   é   )r‚   Úindexr   Ú	enumerateÚitemsÚstrr^   )Údata_dfÚarrow_schemaÚdataframe_schemaÚirq   Úcolumn_nameÚcolumn_datas          r@   Údetermine_dataframe_schemar�   s  s   € ð& )+Ðô *>¸g¿m¹mÓ)LÐÔ%Ñ&ô ˜wŸ}™}›Ó/ò 
‰	ˆˆ6Ü˜& ™)“nˆØ˜Q‘iˆÜ(<Ø˜×+Ñ+¨AÓ.ó)
Ð˜Ò%ð
ð Ðr?   ÚColumnConfigMappingÚColumnConfigMappingInputc           	     ó,  — | €i S i }| j                  «       D ]z  \  }}|€t        d¬«      ||<   Œt        |t        «      rt        |¬«      ||<   Œ8t        |t        «      rt        j                  |«      ||<   Œat        d|› dt        |«      › d�«      ‚ |S )a?  Transforms a user-provided column config mapping into a valid column config mapping
    that can be used by the frontend.

    Parameters
    ----------
    column_config: dict or None
        The user-provided column config mapping.

    Returns
    -------
    dict
        The transformed column config mapping.
    T)Úhidden)Úlabelz"Invalid column config for column `z.`. Expected `None`, `str` or `dict`, but got `z`.)	r‡   r   rk   rˆ   r'   ÚcopyÚdeepcopyr   rO   )Úcolumn_configÚtransformed_column_configrq   Úconfigs       r@   Úprocess_config_mappingrš   ¢  s²   € ð  ÐØˆ	à57ÐØ'×-Ñ-Ó/ò ‰ˆ�Øˆ>Ü0<ÀDÔ0IÐ% fÒ-Ü˜¤Ô$Ü0<À6Ô0JÐ% fÒ-Ü˜¤Ô%ô 15·±¸fÓ0EÐ% fÒ-ä'Ø4°V°Hð =>Ü>BÀ6»l¸^È2ðOóð ðð %Ð$r?   c                ó>   — || vri | |<   | |   j                  |«       y)a§  Updates the column config value for a single column within the mapping.

    Parameters
    ----------
    column_config_mapping : ColumnConfigMapping
        The column config mapping to update.

    column : str | int
        The column to update the config value for. This can be the column name or
        the numerical position of the column.

    column_config : ColumnConfig
        The column config to update.
    N)Úupdate)Úcolumn_config_mappingrq   r—   s      r@   Úupdate_column_configrž   Ç  s+   € ð( Ð*Ñ*Ø(*Ð˜fÑ%à˜&Ñ!×(Ñ(¨Õ7r?   c                óö  — |t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  fv rt!        | t"        ddi«       yy)a~  Apply data specific configurations to the provided dataframe.

    This will apply inplace changes to the dataframe and the column configurations
    depending on the data format.

    Parameters
    ----------
    columns_config : ColumnConfigMapping
        A mapping of column names/ids to column configurations.

    data_format : DataFormat
        The format of the data.
    r“   TN)r   ÚSET_OF_VALUESÚTUPLE_OF_VALUESÚLIST_OF_VALUESÚ
NUMPY_LISTÚNUMPY_MATRIXÚLIST_OF_RECORDSÚLIST_OF_ROWSÚCOLUMN_VALUE_MAPPINGÚPANDAS_ARRAYÚPANDAS_INDEXÚPOLARS_DATAFRAMEÚPOLARS_SERIESÚPOLARS_LAZYFRAMEÚPYARROW_ARRAYÚRAY_DATASETrž   r   )Úcolumns_configÚdata_formats     r@   Úapply_data_specific_configsr±   á  s±   € ð* Ü× Ñ Ü×"Ñ"Ü×!Ñ!Ü×ÑÜ×ÑÜ×"Ñ"Ü×ÑÜ×'Ñ'ä×ÑÜ×ÑÜ×#Ñ#Ü× Ñ Ü×#Ñ#Ü× Ñ Ü×Ñð!ñ ô$ 	˜^Ô-=ÀÈ$Ð?OÕPð%r?   c           
     ó  — 	 t        j                  t        | «      j                  «       D ��ci c]"  \  }}t	        |t
        «      r
t        › |›�n||“Œ$ c}}d¬«      S c c}}w # t        $ r}t        d|› �«      |‚d }~ww xY w)NF)Ú	allow_nanz;The provided column config cannot be serialized into JSON: )	ÚjsonÚdumpsr   r‡   rk   ÚintÚ_NUMERICAL_POSITION_PREFIXÚ
ValueErrorr   )r�   ÚkÚvÚexs       r@   Ú_convert_column_config_to_jsonr¼     s—   € ðä�z‰zô 1Ð1FÓG×MÑMÓO÷á�Q˜ô :DÀAÄsÔ9KÔ.Ð/°¨uÑ5ÐQRÐUVÑVóð ô
ð 	
ùóøô ò Ü#ØIÈ"ÈÐNó
àð	ûðús(   ‚+A$ ­'A
Á	A$ ÁA$ Á$	BÁ-A<Á<Bc                ó$   — t        |«      | _        y)zçMarshall the column config into the Arrow proto.

    Parameters
    ----------
    proto : ArrowProto
        The proto to marshall into.

    column_config_mapping : ColumnConfigMapping
        The column config to marshall.
    N)r¼   Úcolumns)Úprotor�   s     r@   Úmarshall_column_configrÀ     s   € ô 3Ð3HÓI€E…Mr?   )rJ   r   rK   r   ÚreturnÚbool)r^   zpa.FieldrÁ   r   )rq   úSeries[Any] | Index[Any]rÁ   r   )N)rq   rÃ   r^   zpa.Field | NonerÁ   r   )r‰   r   rŠ   z	pa.SchemarÁ   rA   )r—   zColumnConfigMappingInput | NonerÁ   r�   )r�   r�   rq   z	str | intr—   r   rÁ   ÚNone)r¯   r�   r°   r   rÁ   rÄ   )r�   r�   rÁ   rˆ   )r¿   Ú
ArrowProtor�   r�   rÁ   rÄ   )BÚ
__future__r   r•   r´   Úcollections.abcr   Úenumr   Útypingr   r   r   r	   r
   Ústreamlit.dataframe_utilr   Ú#streamlit.elements.lib.column_typesr   r   Ú streamlit.elements.lib.dicttoolsr   Ústreamlit.errorsr   rN   r_   rc   r   r   r   Ústreamlit.proto.Arrow_pb2r   rÅ   r   r   Ú__annotations__r·   rˆ   r   r'   rA   r3   r<   r-   r.   r8   r4   r2   r/   r1   r0   r:   rH   rL   ra   rt   r|   r‚   r�   r¶   r�   r‘   rš   rž   r±   r¼   rÀ   r>   r?   r@   ú<module>rÐ      sV  ðö #ã Û Ý #Ý ß @Õ @å /ß HÝ ?Ý 2áÛß/Ñ/å=ð ˜hÑ'Ð Ø(0Ð Ð%Ó 0ð
 %Ð ô�S˜$ô ð. " # ~Ð"5Ñ6€�Ó 6ð
 ×"Ñ" N×$8Ñ$8Ð9à×ÑØ×ÑØ×ÑØ×ÑØ× Ñ Ø×Ñðð 	×ÑØ×ÑØ×ÑØ×Ñð	ð 	×ÑØ×ÑØ×ÑØ×ÑØ×Ñðð × Ñ  .×"9Ñ"9¸>×;OÑ;OÐPØ× Ñ  .×"9Ñ"9¸>×;OÑ;OÐPà×ÑØ×ÑØ×ÑØ×Ñð	ð ×"Ñ" N×$8Ñ$8Ð9à×ÑØ×ÑØ×Ñðð 	×ÑØ×ÑØ×ÑðñK*QÐ Ð Mó *óZDó6>"ðB3"Ø$ð3"àó3"ðlB"Ø$ðB"àóB"ðL @Dð#9Ø$ð#9Ø-<ð#9àó#9ðL Øð Ø&/ð àó ðH "&Ð&9¸CÑ&?À#Ñ&EÀ|Ð&SÑ!TÐ �YÓ TØ&-ð
 ˜#ÑØ�4Ñ˜#Ñðñ'Ð ˜)ó ð 6:ð"%Ø2ð"%àó"%ðJ8Ø.ð8àð8ð  ð8ð 
ó	8ð4'QØ'ð'Qàð'Qð 
ó'QóTð JØðJØ.AðJà	ôJr?   