
    ch                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	J
r
JrJr  SSKJrJrJrJr  SSKJrJrJr  SSKJr  SSKJrJrJrJrJrJrJrJ r   SS	K!J"r"J#r#  SS
K$J%r%J&r&J'r'J(r(  SSK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  \(       a  SSK3r4SSK5r6SSK7J8r8J9r9J:r:  SSK;J<r<  SSK=J>r>  \'R~                  " \@5      rAS\BS'   SrC\R                  " S5      rES\BS'   SrFS\BS'   SrGS\BS'   SrHS\BS'   SrIS\BS'   SrJS\BS'   SrKS\BS'   S rLS\BS!'   S"rMS\BS#'   S$rNS\BS%'   S&rOS\BS''   S(rPS\BS)'   S*rQS\BS+'   S,rRS\BS-'   S.rSS\BS/'   S0rTS\BS1'   S2rUS\BS3'   S4rVS\BS5'   S6rWS\BS7'   S8rXS\BS9'   S:rYS\BS;'   S<rZS\BS='   S>r[S\BS?'   S@r\S\BSA'   SBr]S\BSC'   SDr^S\BSE'   \" SFSGSH9r_\  " SI SJ\5      5       r` " SK SL\\_   5      ra " SM SN\5      rb " SO SP\5      rc\\\_   \a\_   \b\c4   rdSQ\BSR'   \SSSTSUSVSWSXSY\\   SZ\`\b\c\*S4   reSQ\BS['    " S\ S]\5      rfSS^ jrgSS_ jrhSS` jriSSa jrjSSb jrkSSc jrlSSd jrmSSe jrnSSf jroSSg jrpSSh jrqSSi jrrSSj jrsSSk jrtSSl jruSSm jrvSSn jrwSSo jrxSSp jrySSq jrzSSr jr{ S     SSs jjr|SSt jr}SSu jr~\CSv4       SSw jjrSSx jrSSy jrSSz jrSS{ jr\C4     SS| jjrSS} jr S     SS~ jjrSS jr S     SS jjrSS jrSS jrSS jr      SS jrg)z8A bunch of useful utilities for dealing with dataframes.    )annotationsN)ChainMapUserDictUserListdeque)	ItemsViewIterableMappingSequence)EnumEnumMetaauto)MappingProxyType)TYPE_CHECKINGAnyFinalProtocolTypeVarUnioncastruntime_checkable)	TypeAlias	TypeGuard)configerrorsloggerstring_util)	
CustomDicthas_callable_attris_custom_dictis_dataclass_instanceis_list_likeis_namedtupleis_pydantic_modelis_typeis_version_less_than)	DataFrameIndexSeries)_iLocIndexer)Stylerr   _LOGGERi'  z
^pandas.*$_PANDAS_DATA_OBJECT_TYPE_REz.dask.dataframe.dask_expr._collection.DataFrame_DASK_DATAFRAMEz+dask.dataframe.dask_expr._collection.Series_DASK_SERIESz*dask.dataframe.dask_expr._collection.Index_DASK_INDEXzdask.dataframe.core.DataFrame_DASK_DATAFRAME_LEGACYzdask.dataframe.core.Series_DASK_SERIES_LEGACYzdask.dataframe.core.Index_DASK_INDEX_LEGACYzduckdb.duckdb.DuckDBPyRelation_DUCKDB_RELATIONz modin.pandas.dataframe.DataFrame_MODIN_DF_TYPE_STRzmodin.pandas.series.Series_MODIN_SERIES_TYPE_STRzpandas.io.formats.style.Styler_PANDAS_STYLER_TYPE_STRz polars.dataframe.frame.DataFrame_POLARS_DATAFRAMEz polars.lazyframe.frame.LazyFrame_POLARS_LAZYFRAMEzpolars.series.series.Series_POLARS_SERIESzpyspark.sql.dataframe.DataFrame_PYSPARK_DF_TYPE_STRz'pyspark.sql.connect.dataframe.DataFrame_PYSPARK_CONNECT_DF_TYPE_STRzray.data.dataset.Dataset_RAY_DATASETz$ray.data.dataset.MaterializedDataset_RAY_MATERIALIZED_DATASETz3snowflake.snowpark.modin.pandas.dataframe.DataFrame_SNOWPANDAS_DF_TYPE_STRz6snowflake.snowpark.modin.plugin.extensions.index.Index_SNOWPANDAS_INDEX_TYPE_STRz-snowflake.snowpark.modin.pandas.series.Series_SNOWPANDAS_SERIES_TYPE_STRzsnowflake.snowpark.row.Row_SNOWPARK_DF_ROW_TYPE_STRz&snowflake.snowpark.dataframe.DataFrame_SNOWPARK_DF_TYPE_STRzsnowflake.snowpark.table.Table_SNOWPARK_TABLE_TYPE_STRzxarray.core.dataset.Dataset_XARRAY_DATASET_TYPE_STRzxarray.core.dataarray.DataArray_XARRAY_DATA_ARRAY_TYPE_STRV_coT)	covariantc                  H    \ rS rSrSr\  SS j5       rS	S
S jjrSS jrSr	g)DBAPICursori   aH  Protocol for DBAPI 2.0 Cursor objects (PEP 249).

This is a simplified version of the DBAPI Cursor protocol
that only contains the methods that are relevant or used for
our DB API Integration.

Specification: https://peps.python.org/pep-0249/
Inspired by: https://github.com/python/typeshed/blob/main/stdlib/_typeshed/dbapi.pyi
c                    g N selfs    kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\streamlit/dataframe_util.pydescriptionDBAPICursor.descriptionu   s          c                   g rM   rN   )rP   sizes     rQ   	fetchmanyDBAPICursor.fetchmany   s    rT   c                    g rM   rN   rO   s    rQ   fetchallDBAPICursor.fetchall   s    3rT   rN   N)returnzdSequence[tuple[str, Any | None, int | None, int | None, int | None, int | None, bool | None]] | None).)rV   intr\   Sequence[Sequence[Any]])r\   r^   )
__name__
__module____qualname____firstlineno____doc__propertyrR   rW   rZ   __static_attributes__rN   rT   rQ   rJ   rJ   i   s.     	   L6rT   rJ   c                  ,    \ rS rSrSr\SS j5       rSrg)DataFrameGenericAlias   a\  Technically not a GenericAlias, but serves the same purpose in
OptionSequence below, in that it is a type which admits DataFrame,
but is generic. This allows OptionSequence to be a fully generic type,
significantly increasing its usefulness.

We can't use types.GenericAlias, as it is only available from python>=3.9,
and isn't easily back-ported.
c                    g rM   rN   rO   s    rQ   ilocDataFrameGenericAlias.iloc   s    $'rT   rN   N)r\   r*   )r_   r`   ra   rb   rc   rd   rj   re   rN   rT   rQ   rg   rg      s     ' 'rT   rg   c                  "    \ rS rSrSrSS jrSrg)PandasCompatible   zFProtocol for Pandas compatible objects that have a `to_pandas` method.c                    g rM   rN   rO   s    rQ   	to_pandasPandasCompatible.to_pandas   s    srT   rN   N)r\   zDataFrame | Series)r_   r`   ra   rb   rc   rp   re   rN   rT   rQ   rm   rm      s    P2rT   rm   c                  "    \ rS rSrSrSS jrSrg)DataframeInterchangeCompatible   z}Protocol for objects support the dataframe-interchange protocol.

https://data-apis.org/dataframe-protocol/latest/index.html
c                    g rM   rN   )rP   
allow_copys     rQ   __dataframe__,DataframeInterchangeCompatible.__dataframe__   s    crT   rN   N)rv   boolr\   r   )r_   r`   ra   rb   rc   rw   re   rN   rT   rQ   rs   rs      s    
 :rT   rs   r   OptionSequencer'   r)   r+   r(   pa.Tablezpa.Arrayznp.ndarray[Any, np.dtype[Any]]zMapping[Any, Any]Datac                     \ rS rSrSr\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r \" 5       r!\" 5       r"\" 5       r#\" 5       r$\" 5       r%\" 5       r&Sr'g)
DataFormat   z7DataFormat is used to determine the format of the data.rN   N)(r_   r`   ra   rb   rc   r   UNKNOWNEMPTYCOLUMN_INDEX_MAPPINGCOLUMN_SERIES_MAPPINGCOLUMN_VALUE_MAPPINGDASK_OBJECTDBAPI_CURSORDUCKDB_RELATIONKEY_VALUE_DICTLIST_OF_RECORDSLIST_OF_ROWSLIST_OF_VALUESMODIN_OBJECT
NUMPY_LISTNUMPY_MATRIXPANDAS_ARRAYPANDAS_DATAFRAMEPANDAS_INDEXPANDAS_SERIESPANDAS_STYLERPOLARS_DATAFRAMEPOLARS_LAZYFRAMEPOLARS_SERIESPYARROW_ARRAYPYARROW_TABLEPYSPARK_OBJECTRAY_DATASETSET_OF_VALUESSNOWPANDAS_OBJECTSNOWPARK_OBJECTTUPLE_OF_VALUESXARRAY_DATASETXARRAY_DATA_ARRAYre   rN   rT   rQ   r~   r~      s    AfGFE6 F6&K6LfOVNfO6LVN6LJ6L6Lv6LFMFMvvFMFMFMVN&KFMfOfOVNrT   r~   c                6    SSK n[        UR                  U 5      $ )zReturn True if the current Pyarrow version is less than the input version.

Parameters
----------
v : str
    Version string, e.g. "0.25.0"

Returns
-------
bool


Raises
------
InvalidVersion
    If the version strings are not valid.

r   N)pyarrowr&   __version__)vpas     rQ   is_pyarrow_version_less_thanr      s    & 22rT   c                6    SSK n[        UR                  U 5      $ )zReturn True if the current Pandas version is less than the input version.

Parameters
----------
v : str
    Version string, e.g. "0.25.0"

Returns
-------
bool


Raises
------
InvalidVersion
    If the version strings are not valid.
r   N)pandasr&   r   )r   pds     rQ   is_pandas_version_less_thanr     s    $ 22rT   c                "   U b4  [        U [        [        [        [        [
        [        [        45      (       a  g[        U 5      [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  [        R                   [        R"                  [        R$                  [        R&                  [        R(                  [        R*                  [        R,                  [        R.                  [        R0                  [        R2                  [        R4                  [        R6                  [        R8                  [        R:                  [        R<                  [        R>                  1;   $ )zzTrue if the object is a dataframe-like object.

This does not include basic collection types like list, dict, tuple, etc.
F) 
isinstancetuplesetstrbytesr]   floatry   determine_data_formatr~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   objs    rQ   is_dataframe_liker     s    {juc3sE4&PQQ  %((##    ####      !!$$""!!$$-*  rT   c                r   [        U 5      =(       d    [        U 5      =(       d    [        U 5      =(       d    [        U 5      =(       dp    [	        U 5      =(       d^    [        U 5      =(       dL    [        U 5      =(       d:    [        U 5      =(       d(    [        U 5      =(       d    [        R                  " U 5      $ )aR  True if the object is one of the supported unevaluated data objects.

Currently supported objects are:
- Snowpark DataFrame / Table
- PySpark DataFrame
- Modin DataFrame / Series
- Snowpandas DataFrame / Series / Index
- Dask DataFrame / Series / Index
- Ray Dataset
- Polars LazyFrame
- Generator functions
- DB API 2.0 Cursor (PEP 249)
- DuckDB Relation (Relational API)

Unevaluated means that the data is not yet in the local memory.
Unevaluated data objects are treated differently from other data objects by only
requesting a subset of the data instead of loading all data into th memory
)is_snowpark_data_objectis_pyspark_data_objectis_snowpandas_data_objectis_modin_data_objectis_ray_datasetis_polars_lazyframeis_dask_objectis_duckdb_relationis_dbapi_cursorinspectisgeneratorfunctionr   s    rQ   is_unevaluated_data_objectr   @  s    ( 	 $ 		,!#&		,$S)		,  $		, #			,
 s#		, #		, c"		, 3		, &&s+rT   c                "    [        U [        5      $ )zLTrue if obj is a Pandas object (e.g. DataFrame, Series, Index, Styler, ...).)r%   r-   r   s    rQ   is_pandas_data_objectr   a      3344rT   c                P    [        U [        5      =(       d    [        U [        5      $ )z-True if obj is a Snowpark DataFrame or Table.)r%   rD   rC   r   s    rQ   r   r   f  s    301XWSBW5XXrT   c                    [        U [        5      =(       a>    [        U 5      S:  =(       a)    [        U S   [        5      =(       a    [        U S   S5      $ )z4True if obj is a list of snowflake.snowpark.row.Row.r   as_dict)r   listlenr%   rB   r   r   s    rQ   is_snowpark_row_listr   k  sL     	3 	1HqL	1CF56	1 c!fi0	rT   c                v    [        U [        5      =(       d    [        U [        5      =(       a    [        U S5      $ )z6True if obj is a PySpark or PySpark Connect dataframe.toPandas)r%   r;   r<   r   r   s    rQ   r   r   u  s0     	)*Xgc;W.X-
C
,-rT   c                   [        U [        5      =(       dl    [        U [        5      =(       dU    [        U [        5      =(       d>    [        U [        5      =(       d'    [        U [
        5      =(       d    [        U [        5      $ )z2True if obj is a Dask DataFrame, Series, or Index.)r%   r.   r1   r/   r2   r0   r3   r   s    rQ   r   r   |  sg     	_% 	,3./	,3%	, 3+,	, 3$		,
 3*+rT   c                P    [        U [        5      =(       d    [        U [        5      $ )z,True if obj is of Modin Dataframe or Series.)r%   r5   r6   r   s    rQ   r   r     s    3*+Sws<R/SSrT   c                ~    [        U [        5      =(       d'    [        U [        5      =(       d    [        U [        5      $ )z5True if obj is a Snowpark Pandas DataFrame or Series.)r%   r?   rA   r@   r   s    rQ   r   r     s4     	,- 	4334	4323rT   c                "    [        U [        5      $ )z"True if obj is a Polars Dataframe.)r%   r8   r   s    rQ   is_polars_dataframer         3)**rT   c                "    [        U [        5      $ )z True if obj is a Xarray Dataset.)r%   rE   r   s    rQ   is_xarray_datasetr     s    3011rT   c                "    [        U [        5      $ )z"True if obj is a Xarray DataArray.)r%   rF   r   s    rQ   is_xarray_data_arrayr     r   rT   c                "    [        U [        5      $ )zTrue if obj is a Polars Series.)r%   r:   r   s    rQ   is_polars_seriesr     s    3''rT   c                "    [        U [        5      $ )z"True if obj is a Polars Lazyframe.)r%   r9   r   s    rQ   r   r     r   rT   c                P    [        U [        5      =(       d    [        U [        5      $ )zTrue if obj is a Ray Dataset.)r%   r=   r>   r   s    rQ   r   r     s    3%P6O)PPrT   c                "    [        U [        5      $ )zTrue if obj is a pandas Styler.)r%   r7   r   s    rQ   is_pandas_stylerr     s    3/00rT   c                "    [        U [        5      $ )zOTrue if obj looks like a DB API 2.0 Cursor.

https://peps.python.org/pep-0249/
)r   rJ   r   s    rQ   r   r     s    
 c;''rT   c                "    [        U [        5      $ )zUTrue if obj is a DuckDB relation.

https://duckdb.org/docs/api/python/relational_api
)r%   r4   r   s    rQ   r   r     s     3())rT   c                "    SSK Jn  U" U SS9S;  $ )z.Check if the list only contains scalar values.r   )infer_dtypeTskipna)mixedzunknown-array)pandas.api.typesr   )datar   s     rQ   _is_list_of_scalarsr     s    , tD)1KKKrT   c                    Uc  [        U 5      $ / n[        U 5       H  u  p4X1:  a    U$ UR                  U5        M      U$ )a  Convert an iterable to a list.

Parameters
----------
iterable : Iterable
    The iterable to convert to a list.

max_iterations : int or None
    The maximum number of iterations to perform. If None, all iterations are performed.

Returns
-------
list
    The converted list.
)r   	enumerateappend)iterablemax_iterationsresultiitems        rQ   _iterable_to_listr     sM    $ H~FX&M 	d ' MrT   c                    [        U R                  5      S:X  a$  U R                  S   S:X  a  U R                  SS0S9n U $ )zRename the first column to "value" if it is not named
and if there is only one column in the dataframe.

The default name of the first column is 0 if it is not named
which is not very descriptive.
   r   valuecolumns)r   r   rename)data_dfs    rQ   _fix_column_namingr     s@     7??q W__Q%71%< ..!W.6NrT   c                P    SSK n[        UR                  R                  U SS95      $ )zConvert a key-value dict to a Pandas DataFrame.

Parameters
----------
data : dict
    The dict to convert to a Pandas DataFrame.

Returns
-------
pandas.DataFrame
    The converted Pandas DataFrame.
r   Nindexorient)r   r   r'   	from_dict)r   r   s     rQ   _dict_to_pandas_dfr      s&     bll44T'4JKKrT   Fc           	        SSK nSSKnSSKn[        XR                  5      (       a#  U(       a  U R                  5       $ [        SU 5      $ [        XR                  UR                  UR                  R                  R                  45      (       a  UR	                  U 5      $ [        U 5      (       a;  [        SU(       a  U R                  R                  5       5      $ U R                  5      $ [        XR                  5      (       aD  [        U R                   5      S:X  a  UR	                  / 5      $ [#        UR	                  U 5      5      $ [%        U 5      (       a)  U(       a  U R'                  5       OU n U R)                  5       $ [+        U 5      (       a7  U(       a  U R'                  5       OU n U R)                  5       R-                  5       $ [/        U 5      (       ao  U R1                  U5      R3                  5       R)                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        [        SU 5      $ [;        U 5      (       a&  U(       a  U R                  SS9n U R=                  5       $ [?        U 5      (       a4  U(       a  U R                  SS9n U RA                  5       R-                  5       $ [C        U 5      (       a  U RE                  USS9n [        XR                  UR                  45      (       a  U R-                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S	35        [        SU 5      $ [G        U 5      (       aa  U R1                  U5      R)                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S
35        [        SU 5      $ [I        U 5      (       a  U RE                  U5      RK                  5       n [        XR                  UR                  45      (       a  U R-                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        [        SU 5      $ [M        U 5      (       aa  U R1                  U5      RO                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        [        SU 5      $ [Q        U 5      (       a  U SU R)                  5       n [        XR                  UR                  45      (       a  U R-                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        [        SU 5      $ [S        U 5      (       aa  U R1                  U5      R)                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        [        SU 5      $ [U        U 5      (       aW  U R1                  U5      RW                  5       n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        U $ [Y        U 5      (       a  U RZ                  (       a(  U RZ                   Vs/ s H  of(       a  US   OSPM     snOSnUR	                  U R]                  U5      US9n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        U $ [_        U 5      (       a/  UR	                  U  Vs/ s H  oRa                  5       PM     sn5      $ [c        U S5      (       a  UR	                  U R)                  5       5      $ [c        U S5      (       aL  [e        S5      SL a>  UR                  Rf                  Ri                  U 5      n	U(       a  U	R                  5       $ U	$ [j        Rl                  " U 5      (       a_  [#        UR	                  [o        U " 5       US95      5      n U R                   S   U:X  a#  [5        S[6        R8                  " U5       S35        U $ [        U [p        5      (       a4  [#        UR	                  U  V
s/ s H  oRr                  PM     sn
5      5      $ [        U [t        [v        URx                  [z        45      (       a#  [#        UR	                  [}        U 5      5      5      $ [        U 5      (       a  [        U R                  5       5      $ [        U 5      (       a  [        U R                  5       5      $ [        U 5      (       a  [        [        R                  " U 5      5      $ [        U [        [        [        45      (       d  [        U 5      (       a  [        [        U 5      5      $  [#        UR	                  U 5      5      $ s  snf s  snf s  sn
f ! [         a  n[        U [        5      (       aE  [        R                  " [        5         [        U 5      sSSS5        s SnA$ ! , (       d  f       O= f[        R                  " S[        U 5       SU  S35      UeSnAff = f)a  Try to convert different formats to a Pandas Dataframe.

Parameters
----------
data : dataframe-, array-, or collections-like object
    The data to convert to a Pandas DataFrame.

max_unevaluated_rows: int
    If unevaluated data is detected this func will evaluate it,
    taking max_unevaluated_rows, defaults to 10k.

ensure_copy: bool
    If True, make sure to always return a copy of the data. If False, it depends on
    the type of the data. For example, a Pandas DataFrame will be returned as-is.

Returns
-------
pandas.DataFrame

r   Nzpd.DataFrameu   ⚠️ Showing only z6 rows. Call `collect()` on the dataframe to show more.T)deep)computez8 rows. Call `compute()` on the data object to show more.z6 rows. Call `to_pandas()` on the dataset to show more.z; rows. Call `_to_pandas()` on the data object to show more.z9 rows. Call `toPandas()` on the data object to show more.z: rows. Call `to_pandas()` on the data object to show more.z0 rows. Call `df()` on the relation to show more. r   z4 rows. Call `fetchall()` on the Cursor to show more.rp   rw   z1.5.0F)r   z/ rows. Convert the data to a list to show more.z#
Unable to convert object of type `z1` to `pandas.DataFrame`.
Offending object:
```py
z
```)Rarraynumpyr   r   r'   copyr   r)   r(   api
extensionsExtensionArrayr   r   ndarrayr   shaper   r   clonerp   r   to_framer   limitcollect_show_data_informationr   simplify_numberr   to_dataframer   	to_seriesr   headr   r   
_to_pandasr   r   r   r   r   dfr   rR   rW   r   r   r   r   interchangefrom_dataframer   r   r   r   r   r   map	ArrayTyper   r   r    r   to_dictr#   _asdictr!   dataclassesasdictr   r   r   r$   dict
ValueError
contextlibsuppressr   StreamlitAPIExceptiontype)r   max_unevaluated_rowsensure_copyr  npr   dr   rowr   cexs               rQ   convert_anything_to_pandas_dfr+    s   2 $%%)tyy{ItND/II$BHHbff.?.?.N.NOPP||D!!NDIINN$4SSSS$

## 4::!# LL	
 $BLL$67	
 4  *tzz|~~*tzz|~~((**4  zz./779CCE::a=00"&{'B'BCW'X&Y ZH H ND))99$9'D  ""D!!99$9'D~~((**dyy-ty< dYY122==?D::a=00"&{'B'BCW'X&Y ZJ J ND))dzz./99;::a=00"&{'B'BCW'X&Y ZH H ND))D!!yy-.99;dYY122==?D::a=00"&{'B'BCW'X&Y ZM M ND))d##zz./88:::a=00"&{'B'BCW'X&Y ZK K ND)) &&))*446dYY122==?D::a=00"&{'B'BCW'X&Y ZL L ND))t$$zz./99;::a=00"&{'B'BCW'X&Y ZL L ND))$zz./224::a=00"&{'B'BCW'X&Y ZB B t >B=M=M(8(89(81QQqTB(89SW 	 ||DNN+?@'|R::a=00"&{'B'BCW'X&Y ZF F D!!||d;ds[[]d;<<{++||DNN,-- 	$00'0E9&&$$33D9!,w||~9'9 ""4((!LL*46BVWX
 ::a=00"&{'B'BCW'X&Y ZA A $!!!",,/FA/F"GHH $U__h?@@!",,tDz":;; d!$,,.11 T!$,,.11 T""!+"4"4T":;; $#3X>??CTD D "$t*--!",,t"455I : << 0G8  dD!!$$Z0)$/ 1000 **##':, /  	
 	sH   f5f:'f?g 
i/i=h	ii
h%	!.iic                d    [        U 5      n SSKnUR
                  " 5       nUR                  " X0R                  5      nUR                  U 5        UR                  5         [        SUR                  5       R                  5       5      $ ! [         a  n[        R                  SUS9   SnANSnAff = f)zSerialize pyarrow.Table to Arrow IPC bytes.

Parameters
----------
table : pyarrow.Table
    A table to convert.

Returns
-------
bytes
    The serialized Arrow IPC bytes.
zMRecursion error while truncating Arrow table. This is not supposed to happen.exc_infoNr   r   )_maybe_truncate_tableRecursionErrorr,   warningr   BufferOutputStreamRecordBatchStreamWriterschemawrite_tablecloser   getvalue
to_pybytes)tableerrr   sinkwriters        rQ   "convert_arrow_table_to_arrow_bytesr=    s    
%e,    "D''ll;F
u
LLN33566%  	

 	" 	 	
	
s   B 
B/B**B/c                4   SSK n UR                  R                  U 5      n[        U5      $ ! UR                  UR                  UR
                  4 aD  n[        R                  SUS9  [        U 5      n UR                  R                  U 5      n SnANqSnAff = f)zSerialize pandas.DataFrame to Arrow IPC bytes.

Parameters
----------
df : pandas.DataFrame
    A dataframe to convert.

Returns
-------
bytes
    The serialized Arrow IPC bytes.
r   NzSerialization of dataframe to Arrow table was unsuccessful. Applying automatic fixes for column types to make the dataframe Arrow-compatible.r-  )
r   Tablefrom_pandasArrowTypeErrorArrowInvalidArrowNotImplementedErrorr,   info#fix_arrow_incompatible_column_typesr=  )r  r   r9  r*  s       rQ    convert_pandas_df_to_arrow_bytesrF  %  s     
)$$R( .e44 r0K0KL )  	 	 	
 14$$R()s   , 'B:BBc                N    SSK nUR                  " U 5      nUR                  5       $ )aV  Convert Arrow bytes (IPC format) to pandas.DataFrame.

Using this function in production needs to make sure that
the pyarrow version >= 14.0.1, because of a critical
security vulnerability in pyarrow < 14.0.1.

Parameters
----------
source : bytes
    A bytes object to convert.

Returns
-------
pandas.DataFrame
    The converted dataframe.
r   N)r   RecordBatchStreamReaderread_pandas)sourcer   readers      rQ    convert_arrow_bytes_to_pandas_dfrL  B  s&    " ''/FrT   c                P    SSK Jn  U" 5       R                  R                  U 5        g)zSShow a message to the user with important information
about the processed dataset.
r   )get_dg_singleton_instanceN)$streamlit.delta_generator_singletonsrN  main_dgcaption)msgrN  s     rQ   r  r  Y  s     O''//4rT   c                    SSK n[        XR                  5      (       a  [        U 5      $ [	        X5      n[        U5      $ )a(  Try to convert different formats to Arrow IPC format (bytes).

This method tries to directly convert the input data to Arrow bytes
for some supported formats, but falls back to conversion to a Pandas
DataFrame and then to Arrow bytes.

Parameters
----------
data : dataframe-, array-, or collections-like object
    The data to convert to Arrow bytes.

max_unevaluated_rows: int
    If unevaluated data is detected this func will evaluate it,
    taking max_unevaluated_rows, defaults to 10k.

Returns
-------
bytes
    The serialized Arrow IPC bytes.
r   N)r   r   r?  r=  r+  rF  )r   r$  r   r  s       rQ   convert_anything_to_arrow_bytesrT  b  s8    2 $!!1$77 
't	BB+B//rT   c                   U c  / $ [        U [        [        [        [        45      (       a  U /$ [        U [
        5      (       a4  U  Vs/ s H&  n[        U[        5      (       a  UR                  OUPM(     sn$ [        U [        5      (       a  [        U R                  5       5      $ [        U 5      (       a  [        U 5      (       d  [        U 5      $  [        U SS9nUR                  (       a  / $ [        S[        UR                  SS2S4   R!                  5       5      5      $ s  snf ! ["        R$                   a    U /s $ f = f)at  Try to convert different formats to a list.

If the input is a dataframe-like object, we just select the first
column to iterate over. Non sequence-like objects and scalar types,
will just be wrapped into a list.

Parameters
----------
obj : dataframe-, array-, or collections-like object
    The object to convert to a list.

Returns
-------
list
    The converted list.
NT)r%  
list[V_co]r   )r   r   r]   r   ry   r   r   r
   r   keysr"   r   r+  emptyr   rj   to_listr   r"  )r   memberr   s      rQ   convert_anything_to_listr[    s   " {	#S%.//u#x   SVVRU
63 7 7VCRUVV#wCHHJC!5c!:!: Cy 0F }} 	
 lDad);)C)C)E$FG	
' W0 '' us   -D"D' .3D' 'E Ec                &   [         R                  " S5      (       Gat  [        [         R                  " S5      S-  5      n[        U R                  S-   5      nU R                  nUS:  a  X2:  a  [
        R                  " XBU-  -  5      n[
        R                  " [        [        U[
        R                  " XE-
  S-  5      -
  XDS-  -
  US-
  5      S5      5      nU R                  SU5      n[        Xa=(       d    SXE-
  -   5      $ U(       a  [        R                  " U R                  5      n[        R                  " U R                  U-   5      nXx:X  a-  [        U R                  5      n[        U R                  U-   5      n[        S	U S
U S35        U $ )a  Experimental feature to automatically truncate tables that
are larger than the maximum allowed message size. It needs to be enabled
via the server.enableArrowTruncation config option.

Parameters
----------
table : pyarrow.Table
    A table to truncate.

truncated_rows : int or None
    The number of rows that have been truncated so far. This is used by
    the recursion logic to keep track of the total number of truncated
    rows.

zserver.enableArrowTruncationzserver.maxMessageSizeg    .Ar   g?g{Gz?   r   u   ⚠️ Showing z out of z# rows due to data size limitations.)r   
get_optionr]   nbytesnum_rowsmathceilfloormaxminslicer/  r   r  r   r  )	r9  truncated_rowsmax_message_size
table_size
table_rowstargeted_rowssliced_tabledisplayed_rows
total_rowss	            rQ   r/  r/    s{   & 788 v001HICOP /0
^^
>j; !IIjz4Q&RSM !JJ &

J4NRV3V(WW"4&78"Q M !;;q-8L(2z7QR  (88HN$44U^^n5TUJ+ "%U^^!4 .!@A
"!.!1* F5 5
 LrT   c                   SSK JnJnJn  U R                  R
                  S;   a  g[        U R                  5      S;   a  gU R                  S:X  a  U" U SS9nUS;   a  gUS	:X  ak  [        U 5      S:X  d  [        U S
5      (       d  g[        SU 5      R                  S   nU" U5      (       a"  U" U5      (       d  [        U[        5      (       a  ggg)zQReturn True if the column type is known to cause issues during
Arrow conversion.
r   )r   is_dict_liker"   )r)  T>   geometry	period[B]	period[N]	period[U]
period[ns]
period[us]objectr   )zmixed-integercomplexr   rj   zDataFrameGenericAlias[Any]F)r   r   rp  r"   dtypekindr   r   hasattrr   rj   r   	frozenset)columnr   rp  r"   inferred_typefirst_values         rQ    is_colum_type_arrow_incompatibler    s     IH||   
6<< 	 	 ||x $F48 
 
 G# 6{awvv'>'>  ;VDII!LK !--  ,,k955 rT   c                   SSK nSnU=(       d    U R                   H?  n[        X   5      (       d  M  Uc  U R                  5       nX   R	                  S5      X4'   MA     U(       dr  [        U R                  UR                  5      (       dM  [        U R                  5      (       a3  Uc  U R                  5       nU R                  R	                  S5      Ul        Ub  U$ U $ )aD  Fix column types that are not supported by Arrow table.

This includes mixed types (e.g. mix of integers and strings)
as well as complex numbers (complex128 type). These types will cause
errors during conversion of the dataframe to an Arrow table.
It is fixed by converting all values of the column to strings
This is sufficient for displaying the data on the frontend.

Parameters
----------
df : pandas.DataFrame
    A dataframe to fix.

selected_columns: List[str] or None
    A list of columns to fix. If None, all columns are evaluated.

Returns
-------
The fixed dataframe.
r   Nstring)r   r   r  r  astyper   r   
MultiIndex)r  selected_columnsr   df_copycols        rQ   rE  rE  H  s    .  !%G-2::-+BG44'')7>>(3GL	 . HHMM
 
 -RXX66?ggiG1)71r1rT   c                `   SSK nSSKnSSKnU c  [        R                  $ [        XR                  5      (       a  [        R                  $ [        XR                  5      (       a9  [        U R                  5      S:X  a  [        R                  $ [        R                  $ [        XR                  5      (       a  [        R                  $ [        XR                  5      (       a  [        R                   $ [        XR"                  5      (       a  [        R$                  $ [        XR&                  5      (       a  [        R(                  $ [+        U 5      (       a  [        R,                  $ [        XR.                  R0                  R2                  5      (       a  [        R4                  $ [7        U 5      (       a  [        R8                  $ [;        U 5      (       a  [        R<                  $ [?        U 5      (       a  [        R@                  $ [C        U 5      (       a  [        RD                  $ [G        U 5      (       a  [        RH                  $ [K        U 5      (       a  [        RL                  $ [O        U 5      (       a  [        RP                  $ [S        U 5      (       a  [        RT                  $ [W        U 5      (       a  [        RX                  $ [[        U 5      (       a  [        R\                  $ [_        U 5      (       d  [a        U 5      (       a  [        Rb                  $ [e        U 5      (       a  [        Rf                  $ [i        U 5      (       a  [        Rj                  $ [        U [l        [n        [p        45      (       d@  [s        U 5      (       d0  [u        U 5      (       d   [w        U 5      (       d  [y        U 5      (       a  [        Rz                  $ [        U [|        [~        45      (       a  [        R                  $ [        U [        [        [        [        45      (       a  [        U 5      (       a`  [        U [        5      (       a  [        R                  $ [        U [        [        45      (       a  [        R                  $ [        R                  $ [        [        U 5      5      n[        U[        5      (       a  [        R                  $ [        U[        [        [        [        45      (       a  [        R                  $  [        R                  $ [        U [        [        45      (       a  U (       d  [        Rz                  $ [        U 5      S:  a  [        [        U R                  5       5      5      n[        U[        5      (       a  [        R                  $ [        U[        [        45      (       a  [        R                  $ [        XRR"                  5      (       a  [        R                  $ [        Rz                  $  [        R                  $ [        U 5      (       a  [        R                  $ [        R                  $ )zDetermine the data format of the input data.

Parameters
----------
input_data : Any
    The input data to determine the data format of.

Returns
-------
DataFormat
    The data format of the input data.
r   Nr   )Tr  r   r   r~   r   r   r'   r   r	  r   r
  r   r   r?  r   Arrayr   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   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|  r   r   r   r   nextiterr  r   r
   valuesr   r   r   r"   r   )
input_datar&  r   r   first_elementr  s         rQ   r   r   z  sj    *ll++****jj))z A% (((&&&*hh'''''*hh'''''*ii(('''*hh''&&&
##'''*ff//>>??&&&
##''':&&***:&&***J''&&& ,,+++j))((($$(((J''+++j!!%%%j!!%%%z**.B:.N.N)))*%%)))z""&&&x!12	
 	
 !,,$$*%%Z(((((*y)455&&&*tUC;<<z***e,,!111*sI&677!///,,, T*-.mT**---mdE3	%BCC*** D( % 
Jw	0	0,,,z?QtJ$5$5$789K+t,,!666+e}55!666+yy11!777 ,,,   
j	!	!(((rT   c                    SSK nSSKnU R                  UR                  UR                  UR
                  /S5      R                  5       $ )a  Unify all missing values in a DataFrame to None.

Pandas uses a variety of values to represent missing values, including np.nan,
NaT, None, and pd.NA. This function replaces all of these values with None,
which is the only missing value type that is supported by all data
r   N)r  r   replaceNANaTnaninfer_objects)r  r&  r   s      rQ   _unify_missing_valuesr    s9      ::ruubffbff-t4BBDDrT   c                    [        U R                  5      S:w  a"  [        S[        U R                  5       S35      eX R                  S      $ )zConvert a Pandas DataFrame to a Pandas Series by selecting the first column.

Raises
------
ValueError
    If the DataFrame has more than one column.
r   6DataFrame is expected to have a single column but has .r   )r   r   r  )r  s    rQ   _pandas_df_to_seriesr    sJ     2::!DS_DUUVW
 	
 jjmrT   c                $
   U[         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  1;   a  U $ U[         R                  :X  aH  SSKnU R                   (       a  UR"                  " S5      $ U R$                  SS2S4   R'                  5       $ U[         R(                  :X  a7  SSKnU R                   (       a  UR"                  " S5      $ U R'                  5       $ U[         R*                  :X  a  SSKnUR.                  R1                  U 5      $ U[         R2                  :X  a(  SSKnUR4                  R1                  [7        U 5      5      $ U[         R8                  :X  a  [7        U 5      $ U[         R:                  [         R<                  1;   a  SSKnUR1                  U 5      $ U[         R@                  :X  a  SSKnUR1                  [7        U 5      5      $ U[         RB                  :X  a  SSK"nURF                  RI                  U 5      $ U[         RJ                  :X  a(  SSK"nURL                  RO                  [7        U 5      5      $ U[         RP                  :X  a  [S        U 5      RU                  SS9$ U[         RV                  :X  a'  [S        U 5      R'                  5       RY                  5       $ U[         RZ                  :X  a  [S        U 5      RU                  SS9$ U[         R\                  :X  a  [S        U 5      RU                  SS9$ U[         R^                  :X  a  U RU                  SS9$ U[         R`                  [         Rb                  [         Rd                  4;   a  [S        U 5      n / n[g        U Rh                  5      S:X  a   X Rh                  S      RY                  5       nO;[g        U Rh                  5      S:  a"  [k        S	[g        U Rh                  5       S
35      eU[         Rb                  :X  a  [m        U5      $ U[         Rd                  :X  a  [o        U5      $ U$ U[         Rp                  :X  a?  [S        U 5      n U R                   (       a  0 $ U R$                  SS2S4   RU                  5       $ [k        SU 35      e)a}  Convert a Pandas DataFrame to the specified data format.

Parameters
----------
df : pd.DataFrame
    The dataframe to convert.

data_format : DataFormat
    The data format to convert to.

Returns
-------
pd.DataFrame, pd.Series, pyarrow.Table, np.ndarray, xarray.Dataset,
xarray.DataArray, polars.Dataframe, polars.Series, list, set, tuple, or dict.
    The converted dataframe.
r   Nrecordsr   r  r   seriesr   r  r  zUnsupported input data format: )9r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rX  r	  rj   to_numpyr   r   r   r?  r@  r   r  r  r   r   r   polarsr   r   xarrayDatasetr  r   	DataArrayfrom_seriesr   r  r  r   tolistr   r   r   r   r   r   r   r   r  r   r   r   )r  data_formatr&  r   plxrreturn_lists          rQ    convert_pandas_df_to_data_formatr    s   < ""##  !!$$""  	j+++ !#rzz!}Fbggadm.D.D.FFj--- "rzz!};bkkm;j...xx##B''j...xx##$8$<==j...#B''z22J4O4OPP~~b!!j...~~22677j///zz((,,j222||''(<R(@AAj000$R(00	0BBj---$R(113::<<j555$R(000??j555$R(000??j666zzz**!!""   
 #2&rzz?aZZ]+224K_!2::'q*  *444%%*222{##j///"2& XXr:2771a4=#8#8#::
6{mD
EErT   )r   r   r\   ry   )r   rw  r\   ry   )r   rw  r\   zTypeGuard[Styler])r   rw  r\   zTypeGuard[DBAPICursor])r   Iterable[Any]r\   ry   rM   )r   r  r   
int | Noner\   z	list[Any])r   r'   r\   r'   )r   zdict[Any, Any]r\   r'   )r   r   r$  r]   r%  ry   r\   r'   )r9  r{   r\   r   )r  r'   r\   r   )rJ  r   r\   r'   )rR  r   r\   None)r   r   r$  r]   r\   r   )r   zOptionSequence[V_co]r\   rV  )r9  r{   rg  r  r\   r{   )r}  zSeries[Any] | Indexr\   ry   )r  r'   r  zlist[str] | Noner\   r'   )r  r   r\   r~   )r  r'   r\   r'   )r  r'   r\   zSeries[Any])r  r'   r  r~   r\   zDataFrame | Series[Any] | pa.Table | pa.Array | np.ndarray[Any, np.dtype[Any]] | tuple[Any] | list[Any] | set[Any] | dict[str, Any])rc   
__future__r   r   r  r   ra  recollectionsr   r   r   r   collections.abcr   r	   r
   r   enumr   r   r   typesr   typingr   r   r   r   r   r   r   r   typing_extensionsr   r   	streamlitr   r   r   r   streamlit.type_utilr   r   r    r!   r"   r#   r$   r%   r&   r  r&  r   r   r   r'   r(   r)   pandas.core.indexingr*   pandas.io.formats.styler+   
get_loggerr_   r,   __annotations___MAX_UNEVALUATED_DF_ROWScompiler-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rJ   rg   rm   rs   rz   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   r+  r=  rF  rL  r  rT  r[  r/  r  rE  r   r  r  r  rN   rT   rQ   <module>r     s*   ? "     	 ; ; B B % % "	 	 	 3 9 9
 
 
 //1.""8, , ! %'ZZ%> U >I ICe CAU A !@  ?9 U 97 E 7: % :> E > <  <!A  A= 5 == 5 =5 5? e ?&O e O0e 0#I 5 I!V  V< E  &U U T#? 5 ?G u G"B % B"? % ?%F U F
 7( 7 7@(HTN (3x 3:X : "TN$"$	  $SM"
i $$ $N303.$NB5
Y
-	T
+
2
5
(
+
Q
1
(*L ;?-7: L( !9l
ll l 	l^!7H5: .5 !9#0
#0#0 #0L5r 37HH%/HHV:| 9=/2/2%5/2/2dqhE" yFyF *yFyFrT   