Ë
    úmxi‰  ã                  óž   — d 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
mZmZ ddlmZ dd„Z	 d	 	 	 	 	 	 	 dd
„Zdd„Zdd„Zdd„Zdd„Zy	)ztData marshalling utilities for ArrowTable protobufs, which are used by
CustomComponent for dataframe serialization.
é    )Úannotations)ÚTYPE_CHECKINGÚAny)Údataframe_util)Úpandas_styler_utils)Ú	DataFrameÚIndex)Ú
ArrowTablec                ó<   — t        | t        «      rt        | «      S | S )z;Convert a tuple to a list. Leave as is if it's not a tuple.)Ú
isinstanceÚtupleÚlist)Úitems    ú^/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/components/v1/component_arrow.pyÚ_maybe_tuple_to_listr       s   € ä# D¬%Ô0Œ4�‹:Ð:°dÐ:ó    Nc                óö   — t        j                  |«      rt        j                  | ||«       t        j                  |«      }t        | |j                  «       t        | |j                  «       t        | |«       y)a:  Marshall data into an ArrowTable proto.

    Parameters
    ----------
    proto : proto.ArrowTable
        Output. The protobuf for a Streamlit ArrowTable proto.

    data : pandas.DataFrame, pandas.Styler, numpy.ndarray, Iterable, dict, or None
        Something that is or can be converted to a dataframe.

    N)
r   Úis_pandas_stylerr   Úmarshall_stylerÚconvert_anything_to_pandas_dfÚ_marshall_indexÚindexÚ_marshall_columnsÚcolumnsÚ_marshall_data)ÚprotoÚdataÚdefault_uuidÚdfs       r   Úmarshallr    %   sZ   € ô ×&Ñ& tÔ,Ü×+Ñ+¨E°4¸ÔFä	×	5Ñ	5°dÓ	;€BÜ�E˜2Ÿ8™8Ô$Ü�e˜RŸZ™ZÔ(Ü�5˜"Õr   c                ó¨   — ddl }t        t        t        |j                  «      «      }|j                  |«      }t        j                  |«      | _        y)aH  Marshall pandas.DataFrame index into an ArrowTable proto.

    Parameters
    ----------
    proto : proto.ArrowTable
        Output. The protobuf for a Streamlit ArrowTable proto.

    index : pd.Index
        Index to use for resulting frame.
        Will default to RangeIndex (0, 1, 2, ..., n) if no index is provided.

    r   N)	Úpandasr   Úmapr   Úvaluesr   r   Ú convert_pandas_df_to_arrow_bytesr   )r   r   ÚpdÚindex_valuesÚindex_dfs        r   r   r   <   s=   € ó äœÔ0°%·,±,Ó?Ó@€LØ�|‰|˜LÓ)€HÜ ×AÑAÀ(ÓK€E…Kr   c                ó¨   — ddl }t        t        t        |j                  «      «      }|j                  |«      }t        j                  |«      | _        y)aZ  Marshall pandas.DataFrame columns into an ArrowTable proto.

    Parameters
    ----------
    proto : proto.ArrowTable
        Output. The protobuf for a Streamlit ArrowTable proto.

    columns : Index
        Column labels to use for resulting frame.
        Will default to RangeIndex (0, 1, 2, ..., n) if no column labels are provided.

    r   N)	r"   r   r#   r   r$   r   r   r%   r   )r   r   r&   Úcolumn_valuesÚ
columns_dfs        r   r   r   P   s=   € ó äœÔ1°7·>±>ÓBÓC€MØ—‘˜mÓ,€JÜ"×CÑCÀJÓO€E…Mr   c                ó8   — t        j                  |«      | _        y)zõMarshall pandas.DataFrame data into an ArrowTable proto.

    Parameters
    ----------
    proto : proto.ArrowTable
        Output. The protobuf for a Streamlit ArrowTable proto.

    df : pandas.DataFrame
        A dataframe to marshall.

    N)r   r%   r   )r   r   s     r   r   r   d   s   € ô  ×@Ñ@ÀÓD€E…Jr   c                óà  — t        j                  d«      rt        d«      ‚ddl}t        j                  | j
                  «      }t        j                  | j                  «      }t        j                  | j                  «      }|j                  |j                  «       |j                  «       j                  j                  «       |j                  «       j                  j                  «       ¬«      S )z�Convert ArrowTable proto to pandas.DataFrame.

    Parameters
    ----------
    proto : proto.ArrowTable
        Output. pandas.DataFrame

    z14.0.1zThe installed pyarrow version is not compatible with this component. Please upgrade to 14.0.1 or higher: pip install -U pyarrowr   N)r   r   )r   Úis_pyarrow_version_less_thanÚRuntimeErrorr"   Ú convert_arrow_bytes_to_pandas_dfr   r   r   r   Úto_numpyÚTÚtolist)r   r&   r   r   r   s        r   Úarrow_proto_to_dataframer4   s   s¹   € ô ×2Ñ2°8Ô<ÜðIó
ð 	
ó
 ä×:Ñ:¸5¿:¹:ÓF€DÜ×;Ñ;¸E¿K¹KÓH€EÜ×=Ñ=¸e¿m¹mÓL€Gà�<‰<Ø�‰‹Ø�n‰nÓ× Ñ ×'Ñ'Ó)Ø× Ñ Ó"×$Ñ$×+Ñ+Ó-ð ó ð r   )r   r   Úreturnr   )N)r   ÚArrowTableProtor   r   r   z
str | Noner5   ÚNone)r   r6   r   ú
Index[Any]r5   r7   )r   r6   r   r8   r5   r7   )r   r6   r   r   r5   r7   )r   r6   r5   r   )Ú__doc__Ú
__future__r   Útypingr   r   Ú	streamlitr   Ústreamlit.elements.libr   r"   r   r	   Ústreamlit.proto.Components_pb2r
   r6   r   r    r   r   r   r4   © r   r   ú<module>r@      si   ðñõ #ç %å $Ý 6áß'åLó;ð CGðØðØ"%ðØ5?ðà	óó.Ló(Pó(Eôr   