
    g2                    b   d dl mZ d dlZd dlmZ d dlmZ erbd dlZej                  dk\  rd dlm	Z	 nd dl
m	Z	 d dlZd dlmZ d dlZd dlZd dlmZ d dlZd dlZd dl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"  e#dg      Z$d7dZ%d7dZ&d7dZ'd7dZ(d7dZ)d7dZ*d7dZ+d7dZ,d7dZ-d7dZ.d7dZ/d7dZ0d7dZ1d7dZ2d8dZ3d9dZ4d:dZ5d;dZ6d<dZ7d=dZ8d>d Z9d?d!Z:d@d"Z;dAd#Z<dBd$Z=dCd%Z>dDd&Z?dEd'Z@dFd(ZAdGd)ZBdHd*ZCdId+ZDdJd,ZEdKd-ZFdLd.ZGdMd/ZHdNd0ZIdOd1ZJdPd2ZKdQd3ZLdRd4ZMdSd5ZNg d6ZOy)T    )annotationsN)TYPE_CHECKING)Any)   
   )	TypeGuard	DataFrame	LazyFrameSeries)
IntoSeries	fireducksc                 B    t         j                  j                  dd      S )z;Get Polars module (if already imported - else return None).polarsNsysmodulesget     J/var/www/openai/venv/lib/python3.12/site-packages/narwhals/dependencies.py
get_polarsr   &       ;;??8T**r   c                 B    t         j                  j                  dd      S )z;Get pandas module (if already imported - else return None).pandasNr   r   r   r   
get_pandasr   +   r   r   c                 `    t         j                  j                  dd      x} | j                  S y)zAGet modin.pandas module (if already imported - else return None).modinN)r   r   r   r   )r    s    r   	get_modinr!   0   s)    $//<||r   c                 B    t         j                  j                  dd      S )z9Get cudf module (if already imported - else return None).cudfNr   r   r   r   get_cudfr$   7       ;;??64((r   c                 B    t         j                  j                  dd      S )z9Get cupy module (if already imported - else return None).cupyNr   r   r   r   get_cupyr(   <   r%   r   c                 B    t         j                  j                  dd      S )z<Get pyarrow module (if already imported - else return None).pyarrowNr   r   r   r   get_pyarrowr+   A       ;;??9d++r   c                 B    t         j                  j                  dd      S )z:Get numpy module (if already imported - else return None).numpyNr   r   r   r   	get_numpyr/   F   s    ;;??7D))r   c                 B    t         j                  j                  dd      S )z2Get dask (if already imported - else return None).daskNr   r   r   r   get_daskr2   K   r%   r   c                 B    t         j                  j                  dd      S )zCGet dask.dataframe module (if already imported - else return None).zdask.dataframeNr   r   r   r   get_dask_dataframer4   P   s    ;;??+T22r   c                 B    t         j                  j                  dd      S )z;Get duckdb module (if already imported - else return None).duckdbNr   r   r   r   
get_duckdbr7   U   r   r   c                 B    t         j                  j                  dd      S )z9Get ibis module (if already imported - else return None).ibisNr   r   r   r   get_ibisr:   Z   r%   r   c                 B    t         j                  j                  dd      S )z>Get dask_expr module (if already imported - else return None).	dask_exprNr   r   r   r   get_dask_exprr=   _   s    ;;??;--r   c                 B    t         j                  j                  dd      S )z<Get pyspark module (if already imported - else return None).pysparkNr   r   r   r   get_pysparkr@   d   r,   r   c                 B    t         j                  j                  dd      S )z@Get pyspark.sql module (if already imported - else return None).zpyspark.sqlNr   r   r   r   get_pyspark_sqlrB   i   s    ;;??=$//r   c                     t               x}duxr t         |j                        xs t         fdt        D              S )zBCheck whether `df` is a pandas DataFrame without importing pandas.Nc              3     K   | ]J  }t         j                  j                  |d       xd uxr  t        j                  j
                         L y wN)r   r   r   
isinstancer   r
   ).0module_namedfmods     r   	<genexpr>z&is_pandas_dataframe.<locals>.<genexpr>p   sS      V (K T2	24? 	1r3:://0	1'   AA)r   rF   r
   anyIMPORT_HOOKS)rI   pdrJ   s   ` @r   is_pandas_dataframerP   n   sF    <R,MB1M RU V (V S r   c                     t               x}duxr t         |j                        xs t         fdt        D              S )z@Check whether `ser` is a pandas Series without importing pandas.Nc              3     K   | ]J  }t         j                  j                  |d       xd uxr  t        j                  j
                         L y wrE   )r   r   r   rF   r   r   )rG   rH   rJ   sers     r   rK   z#is_pandas_series.<locals>.<genexpr>y   sS      T (K T2	24? 	/sCJJ--.	/'rL   )r   rF   r   rM   rN   )rS   rO   rJ   s   ` @r   is_pandas_seriesrT   w   sF    <R,KC1K PS T (T Q r   c                     t               x}duxr t         |j                        xs t         fdt        D              S )zACheck whether `index` is a pandas Index without importing pandas.Nc              3     K   | ]J  }t         j                  j                  |d       xd uxr  t        j                  j
                         L y wrE   )r   r   r   rF   r   Index)rG   rH   indexrJ   s     r   rK   z"is_pandas_index.<locals>.<genexpr>   sS      U (K T2	24? 	0ucjj../	0'rL   )r   rF   rW   rM   rN   )rX   rO   rJ   s   ` @r   is_pandas_indexrY      sF    <R,LE2881L QT U (U R r   c                N    t               x}duxr t        | |j                        S )z@Check whether `df` is a modin DataFrame without importing modin.N)r!   rF   r
   )rI   mpds     r   is_modin_dataframer\      s$    ;Ct+M
2s}}0MMr   c                N    t               x}duxr t        | |j                        S )z>Check whether `ser` is a modin Series without importing modin.N)r!   rF   r   )rS   r[   s     r   is_modin_seriesr^      s$    ;Ct+K
3

0KKr   c                N    t               x}duxr t        | |j                        S )z?Check whether `index` is a modin Index without importing modin.N)r!   rF   rW   )rX   r[   s     r   is_modin_indexr`      s+    ;Ct+ 
syy1 r   c                N    t               x}duxr t        | |j                        S )z>Check whether `df` is a cudf DataFrame without importing cudf.N)r$   rF   r
   )rI   r#   s     r   is_cudf_dataframerb      s$    JDt+N
2t~~0NNr   c                N    t               x}duxr t        | |j                        S )z<Check whether `ser` is a cudf Series without importing cudf.N)r$   rF   r   )rS   r#   s     r   is_cudf_seriesrd      s$    JDt+L
30LLr   c                N    t               x}duxr t        | |j                        S )z=Check whether `index` is a cudf Index without importing cudf.N)r$   rF   rW   )rX   r#   s     r   is_cudf_indexrf      s+    JDt+ 
tzz1 r   c                N    t               x}duxr t        | |j                        S )z>Check whether `df` is a Dask DataFrame without importing Dask.N)r4   rF   r
   )rI   dds     r   is_dask_dataframeri      s%    $&&Bt3T
2r||8TTr   c                N    t               x}duxr t        | |j                        S )zACheck whether `df` is a DuckDB Relation without importing DuckDB.N)r7   rF   DuckDBPyRelation)rI   r6   s     r   is_duckdb_relationrl      s-     l"F4/ J
F##5 r   c                v    t               x}duxr* t        | |j                  j                  j                        S )z:Check whether `df` is a Ibis Table without importing Ibis.N)r:   rF   exprtypesTable)rI   r9   s     r   is_ibis_tablerq      s.    JDt+U
2tyy?T?T0UUr   c                N    t               x}duxr t        | |j                        S )zBCheck whether `df` is a Polars DataFrame without importing Polars.N)r   rF   r
   rI   pls     r   is_polars_dataframeru      $    ,Bt+L
2r||0LLr   c                N    t               x}duxr t        | |j                        S )zBCheck whether `df` is a Polars LazyFrame without importing Polars.N)r   rF   r   rs   s     r   is_polars_lazyframerx      rv   r   c                N    t               x}duxr t        | |j                        S )z@Check whether `ser` is a Polars Series without importing Polars.N)r   rF   r   )rS   rt   s     r   is_polars_seriesrz      s$    ,Bt+J
3		0JJr   c                N    t               x}duxr t        | |j                        S )zHCheck whether `ser` is a PyArrow ChunkedArray without importing PyArrow.N)r+   rF   ChunkedArray)rS   pas     r   is_pyarrow_chunked_arrayr~      s$    -B,QC1QQr   c                N    t               x}duxr t        | |j                        S )z@Check whether `df` is a PyArrow Table without importing PyArrow.N)r+   rF   rp   )rI   r}   s     r   is_pyarrow_tabler      s$    -B,IB1IIr   c                `    t        t               x}duxr t        | |j                              S )zDCheck whether `df` is a PySpark DataFrame without importing PySpark.N)boolrB   rF   r
   )rI   pyspark_sqls     r   is_pyspark_dataframer      s4    ')	)$6 	2r;001 r   c                N    t               x}duxr t        | |j                        S )z=Check whether `arr` is a NumPy Array without importing NumPy.N)r/   rF   ndarray)arrnps     r   is_numpy_arrayr      s$    +Bd*Jz#rzz/JJr   c                F    t               x}duxr  |j                  |       S )zACheck whether `scalar` is a NumPy Scalar without importing NumPy.N)r/   isscalar)scalarr   s     r   is_numpy_scalarr      s$    +Bd*B{r{{6/BBr   c                L    t        |       xs t        |       xs t        |       S )zCheck whether `df` is a pandas-like DataFrame without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rP   r\   rb   )rI   s    r   is_pandas_like_dataframer      s&    
 r"U&8&<U@QRT@UUr   c                L    t        |       xs t        |       xs t        |       S )zCheck whether `ser` is a pandas-like Series without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rT   r^   rd   )rS   s    r   is_pandas_like_seriesr      s#    
 C OOC$8ON3<OOr   c                L    t        |       xs t        |       xs t        |       S )zCheck whether `index` is a pandas-like Index without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rY   r`   rf   )rX   s    r   is_pandas_like_indexr      s%     	O."7O=;Or   c                    ddl m} t        | |      xs3 t        | d      xs% t	        |       xs t        |       xs t        |       S )a  Check whether `native_series` can be converted to a Narwhals Series.

    Arguments:
        native_series: The object to check.

    Returns:
        `True` if `native_series` can be converted to a Narwhals Series, `False` otherwise.

    Examples:
        >>> import pandas as pd
        >>> import polars as pl
        >>> import numpy as np
        >>> import narwhals as nw

        >>> s_pd = pd.Series([1, 2, 3])
        >>> s_pl = pl.Series([1, 2, 3])
        >>> np_arr = np.array([1, 2, 3])

        >>> nw.dependencies.is_into_series(s_pd)
        True
        >>> nw.dependencies.is_into_series(s_pl)
        True
        >>> nw.dependencies.is_into_series(np_arr)
        False
    r   r   __narwhals_series__)narwhals.seriesr   rF   hasattrrz   r~   r   )native_seriesr   s     r   is_into_seriesr     sS    4 ' 	=&) 	0="78	0M*	0 $M2	0 !/r   c                    ddl m} t        | |      xs3 t        | d      xs% t	        |       xs t        |       xs t        |       S )a  Check whether `native_dataframe` can be converted to a Narwhals DataFrame.

    Arguments:
        native_dataframe: The object to check.

    Returns:
        `True` if `native_dataframe` can be converted to a Narwhals DataFrame, `False` otherwise.

    Examples:
        >>> import pandas as pd
        >>> import polars as pl
        >>> import numpy as np
        >>> from narwhals.dependencies import is_into_dataframe

        >>> df_pd = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
        >>> df_pl = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
        >>> np_arr = np.array([[1, 4], [2, 5], [3, 6]])

        >>> is_into_dataframe(df_pd)
        True
        >>> is_into_dataframe(df_pl)
        True
        >>> is_into_dataframe(np_arr)
        False
    r   r	   __narwhals_dataframe__)narwhals.dataframer
   rF   r   ru   r   r   )native_dataframer
   s     r   is_into_dataframer   &  sX    4 - 	#Y/ 	6#%=>	6/0	6 ,-	6 $$45r   c                &    ddl m} t        | |      S )zCheck whether `df` is a Narwhals DataFrame.

    This is useful if you expect a user to pass in a Narwhals
    DataFrame directly, and you want to catch both ``narwhals.DataFrame``
    and ``narwhals.stable.v1.DataFrame`.
    r   r	   )r   r
   rF   )rI   r
   s     r   is_narwhals_dataframer   K       -b)$$r   c                &    ddl m} t        | |      S )zCheck whether `lf` is a Narwhals LazyFrame.

    This is useful if you expect a user to pass in a Narwhals
    LazyFrame directly, and you want to catch both ``narwhals.LazyFrame``
    and ``narwhals.stable.v1.LazyFrame`.
    r   r   )r   r   rF   )lfr   s     r   is_narwhals_lazyframer   W  r   r   c                &    ddl m} t        | |      S )zCheck whether `ser` is a Narwhals Series.

    This is useful if you expect a user to pass in a Narwhals
    Series directly, and you want to catch both ``narwhals.Series``
    and ``narwhals.stable.v1.Series`.
    r   r   )r   r   rF   )rS   r   s     r   is_narwhals_seriesr   c  s     'c6""r   )r$   r:   r!   r/   r   r   r+   rb   rd   ri   rq   r   r   r\   r^   r   r   r   r   rP   rY   r   r   rT   ru   rx   rz   r~   r   )returnr   )rI   r   r   zTypeGuard[pd.DataFrame])rS   r   r   zTypeGuard[pd.Series[Any]])rX   r   r   zTypeGuard[pd.Index])rI   r   r   zTypeGuard[mpd.DataFrame])rS   r   r   zTypeGuard[mpd.Series])rX   r   r   zTypeGuard[mpd.Index])rI   r   r   zTypeGuard[cudf.DataFrame])rS   r   r   zTypeGuard[cudf.Series[Any]])rX   r   r   zTypeGuard[cudf.Index])rI   r   r   zTypeGuard[dd.DataFrame])rI   r   r   z"TypeGuard[duckdb.DuckDBPyRelation])rI   r   r   zTypeGuard[ibis.Table])rI   r   r   zTypeGuard[pl.DataFrame])rI   r   r   zTypeGuard[pl.LazyFrame])rS   r   r   zTypeGuard[pl.Series])rS   r   r   zTypeGuard[pa.ChunkedArray])rI   r   r   zTypeGuard[pa.Table])rI   r   r   z TypeGuard[pyspark_sql.DataFrame])r   r   r   zTypeGuard[np.ndarray])r   r   r   zTypeGuard[np.generic])rI   r   r   r   )rS   r   r   r   )rX   r   r   r   )r   r   r   r   )r   r   r   r   )rI   r   r   zTypeGuard[DataFrame[Any]])r   r   r   zTypeGuard[LazyFrame[Any]])rS   r   r   zTypeGuard[Series[Any]])P
__future__r   r   typingr   r   r.   r   version_infor   typing_extensionsr#   dask.dataframe	dataframerh   r6   r9   modin.pandasr   r[   rO   r   rt   r*   r}   pyspark.sqlsqlr   r   r
   r   r   r   narwhals.typingr   	frozensetrN   r   r   r!   r$   r(   r+   r/   r2   r4   r7   r:   r=   r@   rB   rP   rT   rY   r\   r^   r`   rb   rd   rf   ri   rl   rq   ru   rx   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   __all__r   r   r   <module>r      sL   # 
   
7"$/%,,&*
 +'+
+
)
)
,
*
)
3
+
)
.
,
0
N
L
O
M
U
V
M
M
K
R
J
K
C
VP"J"J	%	%	#r   