Ë
    ·ªgF  ã                  ó¢   — 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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ÚSeries)Ú
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    ú\/var/www/openai/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        |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)ÚpandasÚmapr   Úvaluesr   r   Ú convert_pandas_df_to_arrow_bytesr   )r   r   ÚpdÚindex_dfs       r   r   r   <   s8   € ó äÔ$ e§l¡lÓ3€EØ|‰|˜EÓ"€HÜ ×AÑAÀ(ÓK€E…Kr   c                ó–   — ddl }t        t        |j                  «      }|j	                  |«      }t        j                  |«      | _        y)a[  Marshall pandas.DataFrame columns into an ArrowTable proto.

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

    columns : Series
        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'   Ú
columns_dfs       r   r   r   P   s8   € ó äÔ&¨¯©Ó7€GØ—‘˜gÓ&€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 )zConvert 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   r%   ÚTÚtolist)r   r'   r   r   r   s        r   Úarrow_proto_to_dataframer2   s   s«   € ô ×2Ñ2°8Ô<ÜðIó
ð 	
ó
 ä×:Ñ:¸5¿:¹:ÓF€DÜ×;Ñ;¸E¿K¹KÓH€EÜ×=Ñ=¸e¿m¹mÓL€Gà<‰<Ø‰˜5Ÿ<™<Ÿ>™>×0Ñ0Ó2¸G¿N¹N×<LÑ<L×<SÑ<SÓ<Uð ó ð r   )r   r   Úreturnr   )N)r   ÚArrowTableProtor   r   r   z
str | Noner3   ÚNone)r   r4   r   r	   r3   r5   )r   r4   r   r
   r3   r5   )r   r4   r    r   r3   r5   )r   r4   r3   r   )Ú__doc__Ú
__future__r   Útypingr   r   Ú	streamlitr   Ústreamlit.elements.libr   r#   r   r	   r
   Ústreamlit.proto.Components_pb2r   r4   r   r!   r   r   r   r2   © r   r   Ú<module>r=      sl   ðñõ #ç %å $Ý 6áß/Ñ/åLó;ð CGðØðØ"%ðØ5?ðà	óó.Ló(Pó(Eôr   