
    gƍ                    :   U d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZ d dlmZ 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( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2 er&d dl3m4Z4m5Z5 d dl6mZ7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? e	d   Z@deAd<   h dZBdeAd<    G d d e
d!"      ZC G d# d$e
d!"      ZDe G d% d&             ZE	 	 	 	 d-d'ZF G d( d)      ZG	 	 	 	 	 	 d.d*ZH	 d/	 	 	 	 	 	 	 d0d+ZId/d1d,ZJy)2    )annotationsN)	dataclass)TYPE_CHECKINGAnyFinalLiteral	TypedDictcastoverload)	TypeAlias)dataframe_util)INDEX_IDENTIFIERColumnConfigMappingInputapply_data_specific_configsmarshall_column_configprocess_config_mappingupdate_column_config)AttributeDictionary)current_form_id)marshall_styler)check_widget_policies)Keycompute_and_register_element_idto_key)StreamlitAPIException)Arrow)
ForwardMsg)gather_metrics)enqueue_messageget_script_run_ctx)WidgetCallbackregister_widget)HashableIterable)typing)	DataFrame)Data)DeltaGenerator)AddRowsMetadata)
single-row	multi-rowsingle-columnmulti-columnr   SelectionMode>   r+   r*   r-   r,   zFinal[set[SelectionMode]]_SELECTION_MODESc                  &    e Zd ZU dZded<   ded<   y)DataframeSelectionStatea  
    The schema for the dataframe selection state.

    The selection state is stored in a dictionary-like object that supports both
    key and attribute notation. Selection states cannot be programmatically
    changed or set through Session State.

    .. warning::
        If a user sorts a dataframe, row selections will be reset. If your
        users need to sort and filter the dataframe to make selections, direct
        them to use the search function in the dataframe toolbar instead.

    Attributes
    ----------
    rows : list[int]
        The selected rows, identified by their integer position. The integer
        positions match the original dataframe, even if the user sorts the
        dataframe in their browser. For a ``pandas.DataFrame``, you can
        retrieve data from its interger position using methods like ``.iloc[]``
        or ``.iat[]``.
    columns : list[str]
        The selected columns, identified by their names.

    Example
    -------
    The following example has multi-row and multi-column selections enabled.
    Try selecting some rows. To select multiple columns, hold ``Ctrl`` while
    selecting columns. Hold ``Shift`` to select a range of columns.

    >>> import streamlit as st
    >>> import pandas as pd
    >>> import numpy as np
    >>>
    >>> if "df" not in st.session_state:
    >>>     st.session_state.df = pd.DataFrame(
    ...         np.random.randn(12, 5), columns=["a", "b", "c", "d", "e"]
    ...     )
    >>>
    >>> event = st.dataframe(
    ...     st.session_state.df,
    ...     key="data",
    ...     on_select="rerun",
    ...     selection_mode=["multi-row", "multi-column"],
    ... )
    >>>
    >>> event.selection

    .. output::
        https://doc-dataframe-events-selection-state.streamlit.app
        height: 600px

    z	list[int]rowsz	list[str]columnsN__name__
__module____qualname____doc____annotations__     M/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/arrow.pyr1   r1   M   s    3j Or;   r1   F)totalc                      e Zd ZU dZded<   y)DataframeStateaX  
    The schema for the dataframe event state.

    The event state is stored in a dictionary-like object that supports both
    key and attribute notation. Event states cannot be programmatically
    changed or set through Session State.

    Only selection events are supported at this time.

    Attributes
    ----------
    selection : dict
        The state of the ``on_select`` event. This attribute returns a
        dictionary-like object that supports both key and attribute notation.
        The attributes are described by the ``DataframeSelectionState``
        dictionary schema.


    r1   	selectionNr4   r:   r;   r<   r?   r?      s    ( '&r;   r?   c                  "    e Zd ZdZdddZddZy)DataframeSelectionSerdez[DataframeSelectionSerde is used to serialize and deserialize the dataframe selection state.c                    dg g di}||nt        j                  |      }d|vr|}t        t        t	        |            S )Nr@   )r2   r3   )jsonloadsr
   r?   r   )selfui_value	widget_idempty_selection_stateselection_states        r<   deserializez#DataframeSelectionSerde.deserialize   sU    1
 &.%5!4::h;O 	 o-3ON$7$HIIr;   c                8    t        j                  |t              S )N)default)rD   dumpsstr)rF   editing_states     r<   	serializez!DataframeSelectionSerde.serialize   s    zz-55r;   N) )rG   
str | NonerH   rO   returnr?   )rP   r?   rT   rO   )r5   r6   r7   r8   rK   rQ   r:   r;   r<   rB   rB      s    eJ 6r;   rB   c                   t        | t              r| h}nt        |       }|j                  t              st        d|  dt               |j                  ddh      rt        d      |j                  ddh      rt        d      g }|D ]  } | dk(  r*|j                  t        j                  j                         2| dk(  r*|j                  t        j                  j                         a| dk(  r*|j                  t        j                  j                         | dk(  s|j                  t        j                  j                          t        |      S )	z2Parse and check the user provided selection modes.zInvalid selection mode: z. Valid options are: r*   r+   zJOnly one of `single-row` or `multi-row` can be selected as selection mode.r,   r-   zPOnly one of `single-column` or `multi-column` can be selected as selection mode.)
isinstancerO   setissubsetr/   r   
issupersetappend
ArrowProtor.   
SINGLE_ROW	MULTI_ROWSINGLE_COLUMNMULTI_COLUMN)selection_modeselection_mode_setparsed_selection_modess      r<   parse_selection_moderc      sJ    .#&,- !0&&'78#&~&6 7""2!35
 	

 $$lK%@A#X
 	
 $$o~%FG#^
 	
  ,\)"))**B*B*M*MN{*"))**B*B*L*LM."))**B*B*P*PQ~-"))**B*B*O*OP - %&&r;   c            
      j   e Zd Ze	 	 	 ddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed	      	 	 	 ddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Z ed      ddd       Z ed      ddd       Zedd       Z	y)
ArrowMixinNFignorer+   )use_container_width
hide_indexcolumn_ordercolumn_configkey	on_selectr`   c                    y Nr:   rF   datawidthheightrg   rh   ri   rj   rk   rl   r`   s              r<   	dataframezArrowMixin.dataframe        r;   )rg   rh   ri   rj   rk   r`   c                    y rn   r:   ro   s              r<   rs   zArrowMixin.dataframe   rt   r;   rs   c                  ddl }|	dvrt        |	      st        d|	 d      t        |      }|	dk7  }|r8t        |	      }t	        | j
                  ||rt        t        |	      nddd|       t        |      }t               }||_
        |r||_        |r||_        |r||j                  dd t        j                  j                  |_        t#        ||j$                        rt'        j(                  |      |_        nt'        j,                  |      }t'        j.                  |      r;| j
                  j1                         }t3        t5        |            }t7        |||       t'        j8                  |d	      }t;        ||       t'        j<                  |      |_        |t?        |t@        d
|i       tC        ||       |r|jD                  jG                  tI        |
             tK        | j
                        |_&        tO               }tQ        d||jL                  |j*                  ||||j                  |jR                  |
|      |_*        tW               }tY        |jT                  t        |	      r|	nd|jZ                  |j\                  |d      }| j
                  j_                  d|       t        t`        |jb                        S | j
                  j_                  d|      S )u,  Display a dataframe as an interactive table.

        This command works with a wide variety of collection-like and
        dataframe-like object types.

        Parameters
        ----------
        data : dataframe-like, collection-like, or None
            The data to display.

            Dataframe-like objects include dataframe and series objects from
            popular libraries like Dask, Modin, Numpy, pandas, Polars, PyArrow,
            Snowpark, Xarray, and more. You can use database cursors and
            clients that comply with the
            `Python Database API Specification v2.0 (PEP 249)
            <https://peps.python.org/pep-0249/>`_. Additionally, you can use
            anything that supports the `Python dataframe interchange protocol
            <https://data-apis.org/dataframe-protocol/latest/>`_.

            For example, you can use the following:

            - ``pandas.DataFrame``, ``pandas.Series``, ``pandas.Index``,
              ``pandas.Styler``, and ``pandas.Array``
            - ``polars.DataFrame``, ``polars.LazyFrame``, and ``polars.Series``
            - ``snowflake.snowpark.dataframe.DataFrame``,
              ``snowflake.snowpark.table.Table``

            If a data type is not recognized, Streamlit will convert the object
            to a ``pandas.DataFrame`` or ``pyarrow.Table`` using a
            ``.to_pandas()`` or ``.to_arrow()`` method, respectively, if
            available.

            If ``data`` is a ``pandas.Styler``, it will be used to style its
            underlying ``pandas.DataFrame``. Streamlit supports custom cell
            values and colors. It does not support some of the more exotic
            styling options, like bar charts, hovering, and captions. For
            these styling options, use column configuration instead. Text and
            number formatting from ``column_config`` always takes precedence
            over text and number formatting from ``pandas.Styler``.

            Collection-like objects include all Python-native ``Collection``
            types, such as ``dict``, ``list``, and ``set``.

            If ``data`` is ``None``, Streamlit renders an empty table.

        width : int or None
            Desired width of the dataframe expressed in pixels. If ``width`` is
            ``None`` (default), Streamlit sets the dataframe width to fit its
            contents up to the width of the parent container. If ``width`` is
            greater than the width of the parent container, Streamlit sets the
            dataframe width to match the width of the parent container.

        height : int or None
            Desired height of the dataframe expressed in pixels. If ``height``
            is ``None`` (default), Streamlit sets the height to show at most
            ten rows. Vertical scrolling within the dataframe element is
            enabled when the height does not accomodate all rows.

        use_container_width : bool
            Whether to override ``width`` with the width of the parent
            container. If ``use_container_width`` is ``False`` (default),
            Streamlit sets the dataframe's width according to ``width``. If
            ``use_container_width`` is ``True``, Streamlit sets the width of
            the dataframe to match the width of the parent container.

        hide_index : bool or None
            Whether to hide the index column(s). If ``hide_index`` is ``None``
            (default), the visibility of index columns is automatically
            determined based on the data.

        column_order : Iterable of str or None
            The ordered list of columns to display. If ``column_order`` is
            ``None`` (default), Streamlit displays all columns in the order
            inherited from the underlying data structure. If ``column_order``
            is a list, the indicated columns will display in the order they
            appear within the list. Columns may be omitted or repeated within
            the list.

            For example, ``column_order=("col2", "col1")`` will display
            ``"col2"`` first, followed by ``"col1"``, and will hide all other
            non-index columns.

        column_config : dict or None
            Configuration to customize how columns display. If ``column_config``
            is ``None`` (default), columns are styled based on the underlying
            data type of each column.

            Column configuration can modify column names, visibility, type,
            width, or format, among other things. ``column_config`` must be a
            dictionary where each key is a column name and the associated value
            is one of the following:

            - ``None``: Streamlit hides the column.

            - A string: Streamlit changes the display label of the column to
              the given string.

            - A column type within ``st.column_config``: Streamlit applies the
              defined configuration to the column. For example, use
              ``st.column_config.NumberColumn("Dollar values”, format=”$ %d")``
              to change the displayed name of the column to "Dollar values"
              and add a "$" prefix in each cell. For more info on the
              available column types and config options, see
              `Column configuration <https://docs.streamlit.io/develop/api-reference/data/st.column_config>`_.

            To configure the index column(s), use ``_index`` as the column name.

        key : str
            An optional string to use for giving this element a stable
            identity. If ``key`` is ``None`` (default), this element's identity
            will be determined based on the values of the other parameters.

            Additionally, if selections are activated and ``key`` is provided,
            Streamlit will register the key in Session State to store the
            selection state. The selection state is read-only.

        on_select : "ignore" or "rerun" or callable
            How the dataframe should respond to user selection events. This
            controls whether or not the dataframe behaves like an input widget.
            ``on_select`` can be one of the following:

            - ``"ignore"`` (default): Streamlit will not react to any selection
              events in the dataframe. The dataframe will not behave like an
              input widget.

            - ``"rerun"``: Streamlit will rerun the app when the user selects
              rows or columns in the dataframe. In this case, ``st.dataframe``
              will return the selection data as a dictionary.

            - A ``callable``: Streamlit will rerun the app and execute the
              ``callable`` as a callback function before the rest of the app.
              In this case, ``st.dataframe`` will return the selection data
              as a dictionary.

        selection_mode : "single-row", "multi-row", "single-column",             "multi-column", or Iterable of these
            The types of selections Streamlit should allow when selections are
            enabled with ``on_select``. This can be one of the following:

            - "multi-row" (default): Multiple rows can be selected at a time.
            - "single-row": Only one row can be selected at a time.
            - "multi-column": Multiple columns can be selected at a time.
            - "single-column": Only one column can be selected at a time.
            - An ``Iterable`` of the above options: The table will allow
              selection based on the modes specified.

            When column selections are enabled, column sorting is disabled.

        Returns
        -------
        element or dict
            If ``on_select`` is ``"ignore"`` (default), this command returns an
            internal placeholder for the dataframe element that can be used
            with the ``.add_rows()`` method. Otherwise, this command returns a
            dictionary-like object that supports both key and attribute
            notation. The attributes are described by the ``DataframeState``
            dictionary schema.

        Examples
        --------

        **Example 1: Display a dataframe**

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20)))
        >>>
        >>> st.dataframe(df)  # Same as st.write(df)

        .. output::
           https://doc-dataframe.streamlit.app/
           height: 500px

        **Example 2: Use Pandas Styler**

        You can also pass a Pandas Styler object to change the style of
        the rendered DataFrame:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(np.random.randn(10, 20), columns=("col %d" % i for i in range(20)))
        >>>
        >>> st.dataframe(df.style.highlight_max(axis=0))

        .. output::
           https://doc-dataframe1.streamlit.app/
           height: 500px

        **Example 3: Use column configuration**

        You can customize a dataframe via ``column_config``, ``hide_index``, or ``column_order``.

        >>> import random
        >>> import pandas as pd
        >>> import streamlit as st
        >>>
        >>> df = pd.DataFrame(
        >>>     {
        >>>         "name": ["Roadmap", "Extras", "Issues"],
        >>>         "url": ["https://roadmap.streamlit.app", "https://extras.streamlit.app", "https://issues.streamlit.app"],
        >>>         "stars": [random.randint(0, 1000) for _ in range(3)],
        >>>         "views_history": [[random.randint(0, 5000) for _ in range(30)] for _ in range(3)],
        >>>     }
        >>> )
        >>> st.dataframe(
        >>>     df,
        >>>     column_config={
        >>>         "name": "App name",
        >>>         "stars": st.column_config.NumberColumn(
        >>>             "Github Stars",
        >>>             help="Number of stars on GitHub",
        >>>             format="%d ⭐",
        >>>         ),
        >>>         "url": st.column_config.LinkColumn("App URL"),
        >>>         "views_history": st.column_config.LineChartColumn(
        >>>             "Views (past 30 days)", y_min=0, y_max=5000
        >>>         ),
        >>>     },
        >>>     hide_index=True,
        >>> )

        .. output::
           https://doc-dataframe-config.streamlit.app/
           height: 350px

        **Example 4: Customize your index**

        You can use column configuration to format your index.

        >>> import streamlit as st
        >>> import pandas as pd
        >>> from datetime import date
        >>>
        >>> df = pd.DataFrame(
        >>>     {
        >>>         "Date": [date(2024, 1, 1), date(2024, 2, 1), date(2024, 3, 1)],
        >>>         "Total": [13429, 23564, 23452],
        >>>     }
        >>> )
        >>> df.set_index("Date", inplace=True)
        >>>
        >>> config = {
        >>>     "_index": st.column_config.DateColumn("Month", format="MMM YYYY"),
        >>>     "Total": st.column_config.NumberColumn("Total ($)"),
        >>> }
        >>>
        >>> st.dataframe(df, column_config=config)

        .. output::
           https://doc-dataframe-config-index.streamlit.app/
           height: 225px

        r   N)rf   rerunzYou have passed zH to `on_select`. But only 'ignore', 'rerun', or a callable is supported.rf   F)	on_changedefault_valuewrites_allowedenable_check_callback_rules)ensure_copyhiddenrs   )
user_keyform_idrp   rq   rr   rg   ri   rj   r`   is_selection_activatedstring_value)on_change_handlerdeserializer
serializerctx
value_typearrow_data_frame)2pyarrowcallabler   r   r   dgr
   r!   r   r[   rg   rq   rr   ri   EditingMode	READ_ONLYediting_moderV   Tabler   "convert_arrow_table_to_arrow_bytesrp   determine_data_formatis_pandas_styler_get_delta_path_strrO   hashr   convert_anything_to_pandas_dfr    convert_pandas_df_to_arrow_bytesr   r   r   r`   extendrc   r   r   r    r   r3   idrB   r"   rK   rQ   _enqueuer?   value)rF   rp   rq   rr   rg   rh   ri   rj   rk   rl   r`   par   is_callbackcolumn_config_mappingprotodata_format
delta_pathdefault_uuiddata_dfr   serdewidget_states                          r<   rs   zArrowMixin.dataframe   s   ` 	//8K'"9+-uv  Sk!*h!6!"9-K!=H$~y9d"$,7 !7} E$7!EK!EL$0Eq!'33==dBHH%'JJ4PEJ )>>tDK..t4 "WW88:
"4
#34t\: %BB%G ((={K'HHQEJ! %'7(J9O 	u&;<!   ''(<^(LM+DGG4EM$&C6ZZ$7"//#mm-'=EH ,-E*/7	/B)".. ??)L GG/7(:(:;;77##$6>>r;   tablec                   t        j                  |      rt        j                  |d      }| j                  j	                         }t        t        |            }t               }t        |||       | j                  j                  d|      S )a  Display a static table.

        While ``st.dataframe`` is geared towards large datasets and interactive
        data exploration, ``st.table`` is useful for displaying small, styled
        tables without sorting or scrolling. For example, ``st.table`` may be
        the preferred way to display a confusion matrix or leaderboard.
        Additionally, ``st.table`` supports Markdown.

        Parameters
        ----------
        data : Anything supported by st.dataframe
            The table data.

            All cells including the index and column headers can optionally
            contain GitHub-flavored Markdown. Syntax information can be found
            at: https://github.github.com/gfm.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        Examples
        --------
        **Example 1: Display a simple dataframe as a static table**

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df = pd.DataFrame(
        ...     np.random.randn(10, 5), columns=("col %d" % i for i in range(5))
        ... )
        >>>
        >>> st.table(df)

        .. output::
           https://doc-table.streamlit.app/
           height: 480px

        **Example 2: Display a table of Markdown strings**

        >>> import streamlit as st
        >>> import pandas as pd
        >>>
        >>> df = pd.DataFrame(
        ...     {
        ...         "Command": ["**st.table**", "*st.dataframe*"],
        ...         "Type": ["`static`", "`interactive`"],
        ...         "Docs": [
        ...             "[:rainbow[docs]](https://docs.streamlit.io/develop/api-reference/data/st.dataframe)",
        ...             "[:book:](https://docs.streamlit.io/develop/api-reference/data/st.table)",
        ...         ],
        ...     }
        ... )
        >>> st.table(df)

        .. output::
           https://doc-table-markdown.streamlit.app/
           height: 200px
        d   )max_unevaluated_rowsarrow_table)
r   is_unevaluated_data_objectr   r   r   rO   r   r[   marshallr   )rF   rp   r   r   r   s        r<   r   zArrowMixin.tablex  su    J 44T:!??3D WW002
4
+,l+wwu55r;   add_rowsc                0    t        | j                  |fi |S )aL  Concatenate a dataframe to the bottom of the current one.

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, Iterable, dict, or None
            Table to concat. Optional.

        **kwargs : pandas.DataFrame, numpy.ndarray, Iterable, dict, or None
            The named dataset to concat. Optional. You can only pass in 1
            dataset (including the one in the data parameter).

        Example
        -------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> df1 = pd.DataFrame(
        ...     np.random.randn(50, 20), columns=("col %d" % i for i in range(20))
        ... )
        >>>
        >>> my_table = st.table(df1)
        >>>
        >>> df2 = pd.DataFrame(
        ...     np.random.randn(50, 20), columns=("col %d" % i for i in range(20))
        ... )
        >>>
        >>> my_table.add_rows(df2)
        >>> # Now the table shown in the Streamlit app contains the data for
        >>> # df1 followed by the data for df2.

        You can do the same thing with plots. For example, if you want to add
        more data to a line chart:

        >>> # Assuming df1 and df2 from the example above still exist...
        >>> my_chart = st.line_chart(df1)
        >>> my_chart.add_rows(df2)
        >>> # Now the chart shown in the Streamlit app contains the data for
        >>> # df1 followed by the data for df2.

        And for plots whose datasets are named, you can pass the data with a
        keyword argument where the key is the name:

        >>> my_chart = st.vega_lite_chart(
        ...     {
        ...         "mark": "line",
        ...         "encoding": {"x": "a", "y": "b"},
        ...         "datasets": {
        ...             "some_fancy_name": df1,  # <-- named dataset
        ...         },
        ...         "data": {"name": "some_fancy_name"},
        ...     }
        ... )
        >>> my_chart.add_rows(some_fancy_name=df2)  # <-- name used as keyword

        )_arrow_add_rowsr   )rF   rp   kwargss      r<   r   zArrowMixin.add_rows  s    t tww777r;   c                    t        d|       S )zGet our DeltaGenerator.r(   )r
   )rF   s    r<   r   zArrowMixin.dg  s     $d++r;   )NNN)rp   r'   rq   
int | Nonerr   r   rg   boolrh   bool | Noneri   Iterable[str] | Nonerj   ColumnConfigMappingInput | Nonerk   
Key | Nonerl   zLiteral['ignore']r`   'SelectionMode | Iterable[SelectionMode]rT   r(   )rp   r'   rq   r   rr   r   rg   r   rh   r   ri   r   rj   r   rk   r   rl   z!Literal['rerun'] | WidgetCallbackr`   r   rT   r?   )rp   r'   rq   r   rr   r   rg   r   rh   r   ri   r   rj   r   rk   r   rl   z+Literal['ignore', 'rerun'] | WidgetCallbackr`   r   rT   zDeltaGenerator | DataframeStatern   )rp   r'   rT   r(   )rp   r'   rT   DeltaGenerator | None)rT   r(   )
r5   r6   r7   r   rs   r   r   r   propertyr   r:   r;   r<   re   re      sS     !	 %*"&-19='/BM  	 "   + 7  % @ 
    !	 %*"&-19=BM  	 "   + 7  5 @ 
  K   !	u? %*"&-19=AIBMu?u? u? 	u? "u?  u? +u? 7u? u? ?u? @u? 
)u? !u?n GQ6 Q6f J98  98v , ,r;   re   c                    |s0t        j                  |       r| d fS t        j                  |       d fS ddlm}  || |      S )Nr   )prep_chart_data_for_add_rows)r   r   r   +streamlit.elements.lib.built_in_chart_utilsr   )rp   add_rows_metadatar   s      r<   _prep_data_for_add_rowsr     sK     **40 :;;DA4GG Y'.?@@r;   c                   | j                   | j                  | S | j                  j                  st        d      |t	        |      dk(  rd}n-t	        |      dk(  r|j                         \  }}nt        d      d| j                  j                  v rs| j                  j                  d   rZ| j                  j                  d   j                  7t        | | j                  j                  d   j                        } ||fi | yt        || j                  j                  d         \  }| j                  j                  d<   t               }| j                  j                  |j                  j                  dd t        t        | j!                                     }t#        |j$                  j&                  j(                  ||       |r6||j$                  j&                  _        d|j$                  j&                  _        t/        |       | S )	a2  Concatenate a dataframe to the bottom of the current one.

    Parameters
    ----------
    data : pandas.DataFrame, pandas.Styler, numpy.ndarray, Iterable, dict, or None
        Table to concat. Optional.

    **kwargs : pandas.DataFrame, numpy.ndarray, Iterable, dict, or None
        The named dataset to concat. Optional. You can only pass in 1
        dataset (including the one in the data parameter).

    Example
    -------
    >>> import streamlit as st
    >>> import pandas as pd
    >>> import numpy as np
    >>>
    >>> df1 = pd.DataFrame(
    ...     np.random.randn(50, 20), columns=("col %d" % i for i in range(20))
    ... )
    >>> my_table = st.table(df1)
    >>>
    >>> df2 = pd.DataFrame(
    ...     np.random.randn(50, 20), columns=("col %d" % i for i in range(20))
    ... )
    >>> my_table.add_rows(df2)
    >>> # Now the table shown in the Streamlit app contains the data for
    >>> # df1 followed by the data for df2.

    You can do the same thing with plots. For example, if you want to add
    more data to a line chart:

    >>> # Assuming df1 and df2 from the example above still exist...
    >>> my_chart = st.line_chart(df1)
    >>> my_chart.add_rows(df2)
    >>> # Now the chart shown in the Streamlit app contains the data for
    >>> # df1 followed by the data for df2.

    And for plots whose datasets are named, you can pass the data with a
    keyword argument where the key is the name:

    >>> my_chart = st.vega_lite_chart(
    ...     {
    ...         "mark": "line",
    ...         "encoding": {"x": "a", "y": "b"},
    ...         "datasets": {
    ...             "some_fancy_name": df1,  # <-- named dataset
    ...         },
    ...         "data": {"name": "some_fancy_name"},
    ...     }
    ... )
    >>> my_chart.add_rows(some_fancy_name=df2)  # <-- name used as keyword

    Nz&Only existing elements can `add_rows`.r   rR      zLWrong number of arguments to add_rows().Command requires exactly one datasetr   T)_root_container_cursor	is_lockedr   lenpopitemprops
last_indexgetattrchart_commandr   r   r   metadatarO   r   r   r   deltaarrow_add_rowsrp   namehas_namer   )r   rp   r   r   	st_methodnew_datamsgr   s           r<   r   r   $  s   z 
!RZZ%7	::#$LMM CK1,	V	^^%
d $3
 	
 	rzz///JJ01JJ01<<DB

 0 01D E S ST	$!&!6M


,-73Hbjj23
 ,C!#!6!6CLLAtB22456LSYY%%**HlC(,		  %,0		  )CIr;   c                    t        j                  |      r$t        |t              sJ d       t	        | ||       t        j
                  |      | _        y)aX  Marshall pandas.DataFrame into an Arrow proto.

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

    data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.DataFrame, Iterable, dict, or None
        Something that is or can be converted to a dataframe.

    default_uuid : str | None
        If pandas.Styler UUID is not provided, this value will be used.
        This attribute is optional and only used for pandas.Styler, other elements
        (e.g. charts) can ignore it.

    z.Default UUID must be a string for Styler data.N)r   r   rV   rO   r   convert_anything_to_arrow_bytesrp   )r   rp   r   s      r<   r   r     sN    $ &&t, ,, 	
<	
, 	t\2??EEJr;   )r`   r   rT   z'set[ArrowProto.SelectionMode.ValueType])rp   r'   r   zAddRowsMetadata | NonerT   z#tuple[Data, AddRowsMetadata | None]rn   )r   r(   rp   r'   r   zIDataFrame | npt.NDArray[Any] | Iterable[Any] | dict[Hashable, Any] | NonerT   r   )r   r[   rp   r'   r   rS   rT   None)K
__future__r   rD   dataclassesr   r%   r   r   r   r   r	   r
   r   typing_extensionsr   	streamlitr   *streamlit.elements.lib.column_config_utilsr   r   r   r   r   r   "streamlit.elements.lib.event_utilsr   !streamlit.elements.lib.form_utilsr   *streamlit.elements.lib.pandas_styler_utilsr   streamlit.elements.lib.policiesr   streamlit.elements.lib.utilsr   r   r   streamlit.errorsr   streamlit.proto.Arrow_pb2r   r[   streamlit.proto.ForwardMsg_pb2r   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r    streamlit.runtime.stater!   r"   collections.abcr#   r$   numpynptpandasr&   streamlit.dataframe_utilr'   streamlit.delta_generatorr(   r   r)   r.   r9   r/   r1   r?   rB   rc   re   r   r   r   r:   r;   r<   <module>r      sO   #  !   ( $  C = F A U U 2 9 5 9 D2# -8K #>y / + 7iu 7t'Ye '0 6 6 6.%';%',%'Pl, l,^A
A-A )A0 mm
m 	R	m m`Fr;   