
    phI                    @   S SK Jr  S SKrS SKJrJr  \(       ab  S SKrS SKJr	  S SK
r
S SKrS SKJr  S SKrS SKrS SKrS SKJr  S SKJr  S SKJrJr  S SKJr  S SK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+J,r,  \-" S
/5      r.SBS jr/SBS jr0SBS jr1SBS jr2SBS jr3SBS jr4SBS jr5SBS jr6SBS jr7SBS jr8SBS jr9SBS jr:SBS jr;SBS jr<SBS jr=SBS jr>SCS jr?SDS jr@SES jrASFS jrBSGS jrCSHS  jrDSIS! jrESJS" jrFSKS# jrGSLS$ jrHSMS% jrISNS& jrJSOS' jrKSPS( jrLSQS) jrMSRS* jrNSSS+ jrOSTS, jrPSUS- jrQSVS. jrRSWS/ jrSSXS0 jrTSYS1 jrUSZS2 jrVS[S3 jrWS\S4 jrXS]S5 jrYS^S6 jrZS_S7 jr[S`S8 jr\SaS9 jr]SbS: jr^ScS; jr_SdS< jr`    SeS= jra    SfS> jrbSgS? jrcSgS@ jrd/ SAQreg)h    )annotationsN)TYPE_CHECKINGAny	DataFrame)	TypeGuardTypeIs)SQLFrameDataFrame)r   	LazyFrameSeries)	IntoDataFrameTIntoLazyFrameTIntoSeriesT_1DArray_1DArrayInt_2DArray_NDArray_NumpyScalar_ShapeT	fireducksc                 B    [         R                  R                  SS5      $ )z;Get Polars module (if already imported - else return None).polarsNsysmodulesget     mC:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\narwhals/dependencies.py
get_polarsr!   ,       ;;??8T**r   c                 B    [         R                  R                  SS5      $ )z;Get pandas module (if already imported - else return None).pandasNr   r   r   r    
get_pandasr%   1   r"   r   c                 b    [         R                  R                  SS5      =n b  U R                  $ g)zAGet modin.pandas module (if already imported - else return None).modinN)r   r   r   r$   )r'   s    r    	get_modinr(   6   s)    $//<||r   c                 B    [         R                  R                  SS5      $ )z9Get cudf module (if already imported - else return None).cudfNr   r   r   r    get_cudfr+   =       ;;??64((r   c                 B    [         R                  R                  SS5      $ )z9Get cupy module (if already imported - else return None).cupyNr   r   r   r    get_cupyr/   B   r,   r   c                 B    [         R                  R                  SS5      $ )z<Get pyarrow module (if already imported - else return None).pyarrowNr   r   r   r    get_pyarrowr2   G       ;;??9d++r   c                 B    [         R                  R                  SS5      $ )z:Get numpy module (if already imported - else return None).numpyNr   r   r   r    	get_numpyr6   L   s    ;;??7D))r   c                 B    [         R                  R                  SS5      $ )z2Get dask (if already imported - else return None).daskNr   r   r   r    get_daskr9   Q   r,   r   c                 B    [         R                  R                  SS5      $ )zCGet dask.dataframe module (if already imported - else return None).zdask.dataframeNr   r   r   r    get_dask_dataframer;   V   s    ;;??+T22r   c                 B    [         R                  R                  SS5      $ )z;Get duckdb module (if already imported - else return None).duckdbNr   r   r   r    
get_duckdbr>   [   r"   r   c                 B    [         R                  R                  SS5      $ )z9Get ibis module (if already imported - else return None).ibisNr   r   r   r    get_ibisrA   `   r,   r   c                     [        5       =n b  [        U S5      (       a  U R                  $ [        R                  R                  SS5      $ )z>Get dask_expr module (if already imported - else return None).N	dask_expr)r;   hasattrrC   r   r   r   )dds    r    get_dask_exprrF   e   s;     ""/GB4L4L||;;??;--r   c                 B    [         R                  R                  SS5      $ )z<Get pyspark module (if already imported - else return None).pysparkNr   r   r   r    get_pysparkrI   l   r3   r   c                 B    [         R                  R                  SS5      $ )z@Get pyspark.sql module (if already imported - else return None).zpyspark.sqlNr   r   r   r    get_pyspark_sqlrK   q   s    ;;??=$//r   c                 B    [         R                  R                  SS5      $ )zHGet pyspark.sql.connect module (if already imported - else return None).zpyspark.sql.connectNr   r   r   r    get_pyspark_connectrM   v   s    ;;??0$77r   c                 B    [         R                  R                  SS5      $ )z=Get sqlframe module (if already imported - else return None).sqlframeNr   r   r   r    get_sqlframerP   {   s    ;;??:t,,r   c                x    [        U 5      (       d  [        U 5      (       a  S[        U 5       S3n[        U5      eg )NYou passed a `z` to `is_pandas_dataframe`.

Hint: Instead of e.g. `is_pandas_dataframe(df)`, did you mean `is_pandas_dataframe(df.to_native())`?)is_narwhals_dataframeis_narwhals_lazyframetype	TypeError)dfmsgs     r    _raise_if_narwhals_df_or_lfrY      sE    R  $9"$=$=T"XJ 'B B 	
 n %>r   c                X    [        U 5      (       a  S[        U 5       S3n[        U5      eg )NrR   zz` to `is_pandas_series`.

Hint: Instead of e.g. `is_pandas_series(ser)`, did you mean `is_pandas_series(ser.to_native())`?)is_narwhals_seriesrU   rV   )serrX   s     r    _raise_if_narwhals_seriesr]      s:    #T#YK (@ @ 	
 n r   c                   ^ ^ [        T 5        [        5       =nSL=(       a    [        T UR                  5      =(       d    [	        U U4S j[
         5       5      $ )zCheck whether `df` is a pandas DataFrame without importing pandas.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
Nc              3     >#    U  HP  n[         R                  R                  US 5      =mS L=(       a     [        TTR                  R
                  5      v   MR     g 7fN)r   r   r   
isinstancer$   r   ).0module_namerW   mods     r    	<genexpr>&is_pandas_dataframe.<locals>.<genexpr>   sR      V (K T2	24? 	1r3:://0	1'   AA)rY   r%   ra   r   anyIMPORT_HOOKS)rW   pdrd   s   ` @r    is_pandas_dataframerk      sP      #<R,MB1M RU V (V S r   c                   ^ ^ [        T 5        [        5       =nSL=(       a    [        T UR                  5      =(       d    [	        UU 4S j[
         5       5      $ )zCheck whether `ser` is a pandas Series without importing pandas.

Warning:
    This method cannot be called on Narwhals Series.
Nc              3     >#    U  HP  n[         R                  R                  US 5      =mS L=(       a     [        TTR                  R
                  5      v   MR     g 7fr`   )r   r   r   ra   r$   r   )rb   rc   rd   r\   s     r    re   #is_pandas_series.<locals>.<genexpr>   sR      T (K T2	24? 	/sCJJ--.	/'rg   )r]   r%   ra   r   rh   ri   )r\   rj   rd   s   ` @r    is_pandas_seriesro      sP     c"<R,KC1K PS T (T Q r   c                   ^ ^ [        5       =nSL=(       a    [        T UR                  5      =(       d    [        U U4S j[         5       5      $ )zACheck whether `index` is a pandas Index without importing pandas.Nc              3     >#    U  HP  n[         R                  R                  US 5      =mS L=(       a     [        TTR                  R
                  5      v   MR     g 7fr`   )r   r   r   ra   r$   Index)rb   rc   indexrd   s     r    re   "is_pandas_index.<locals>.<genexpr>   sR      U (K T2	24? 	0ucjj../	0'rg   )r%   ra   rr   rh   ri   )rs   rj   rd   s   ` @r    is_pandas_indexru      sF    <R,LE2881L QT U (U R r   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a modin DataFrame without importing modin.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
N)rY   r(   ra   r   )rW   mpds     r    is_modin_dataframerx      s,      #;Ct+M
2}}0MMr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )z~Check whether `ser` is a modin Series without importing modin.

Warning:
    This method cannot be called on Narwhals Series.
N)r]   r(   ra   r   )r\   rw   s     r    is_modin_seriesrz      s,     c";Ct+K
3

0KKr   c                V    [        5       =nSL=(       a    [        XR                  5      $ )z?Check whether `index` is a modin Index without importing modin.N)r(   ra   rr   )rs   rw   s     r    is_modin_indexr|      s"    ;Ct+L
5))0LLr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a cudf DataFrame without importing cudf.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
N)rY   r+   ra   r   )rW   r*   s     r    is_cudf_dataframer~      s,      #JDt+N
2~~0NNr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )z|Check whether `ser` is a cudf Series without importing cudf.

Warning:
    This method cannot be called on Narwhals Series.
N)r]   r+   ra   r   )r\   r*   s     r    is_cudf_seriesr      s,     c"JDt+L
30LLr   c                V    [        5       =nSL=(       a    [        XR                  5      $ )z=Check whether `index` is a cudf Index without importing cudf.N)r+   ra   rr   )rs   r*   s     r    is_cudf_indexr      s)    JDt+ 
zz1 r   c                    [        5       =nS L=(       a+    [        XR                  5      =(       a    U R                  S:H  $ )N   )r/   ra   ndarraysize)objr.   s     r    is_cupy_scalarr      s7    	D( 	sLL)	HHMr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a Dask DataFrame without importing Dask.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
N)rY   r;   ra   r   )rW   rE   s     r    is_dask_dataframer      s-      #$&&Bt3T
2||8TTr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a DuckDB Relation without importing DuckDB.

Warning:
    This method cannot be called on Narwhals DataFrame/LazyFrame.
N)rY   r>   ra   DuckDBPyRelation)rW   r=   s     r    is_duckdb_relationr      s5      # l"F4/ J
##5 r   c                    [        U 5        [        5       =nSL=(       a)    [        XR                  R                  R
                  5      $ )zCheck whether `df` is a Ibis Table without importing Ibis.

Warning:
    This method cannot be called on Narwhals DataFrame/LazyFrame.
N)rY   rA   ra   exprtypesTable)rW   r@   s     r    is_ibis_tabler     s6      #JDt+U
2yy?T?T0UUr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a Polars DataFrame without importing Polars.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
N)rY   r!   ra   r   rW   pls     r    is_polars_dataframer     ,      #,Bt+L
2||0LLr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a Polars LazyFrame without importing Polars.

Warning:
    This method cannot be called on Narwhals DataFrame/LazyFrame.
N)rY   r!   ra   r   r   s     r    is_polars_lazyframer     r   r   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `ser` is a Polars Series without importing Polars.

Warning:
    This method cannot be called on Narwhals Series.
N)r]   r!   ra   r   )r\   r   s     r    is_polars_seriesr   )  s,     c",Bt+J
3		0JJr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `ser` is a PyArrow ChunkedArray without importing PyArrow.

Warning:
    This method cannot be called on Narwhals Series.
N)r]   r2   ra   ChunkedArray)r\   pas     r    is_pyarrow_chunked_arrayr   3  s,     c"-B,QC1QQr   c                l    [        U 5        [        5       =nSL=(       a    [        XR                  5      $ )zCheck whether `df` is a PyArrow Table without importing PyArrow.

Warning:
    This method cannot be called on Narwhals DataFrame/LazyFrame.
N)rY   r2   ra   r   )rW   r   s     r    is_pyarrow_tabler   =  s,      #-B,IB1IIr   c                V    [        5       =nS L=(       a    [        XR                  5      $ r`   )r2   ra   Scalar)r   r   s     r    is_pyarrow_scalarr   G  s"    -B,KC1KKr   c                ~    [        U 5        [        [        5       =nSL=(       a    [        XR                  5      5      $ )zCheck whether `df` is a PySpark DataFrame without importing PySpark.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
N)rY   boolrK   ra   r   )rW   pyspark_sqls     r    is_pyspark_dataframer   K  s<      #')	)$6 	2r001 r   c                t    [        U 5        [        5       b   SSKJn  [        X5      $ g! [         a     gf = f)zCheck whether `df` is a PySpark Connect DataFrame without importing PySpark.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
r   r   F)rY   rM   pyspark.sql.connect.dataframer   ImportErrorra   rW   r   s     r    is_pyspark_connect_dataframer   X  sA      #(	? "((  		s   * 
77c                R    [        U 5        [        5       b  SSKJn  [	        X5      $ g)zCheck whether `df` is a SQLFrame DataFrame without importing SQLFrame.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
r   )BaseDataFrameF)rY   rP   sqlframe.base.dataframer   ra   )rW   r   s     r    is_sqlframe_dataframer   h  s%      #~!9",,r   c                V    [        5       =nSL=(       a    [        XR                  5      $ )z=Check whether `arr` is a NumPy Array without importing NumPy.N)r6   ra   r   arrnps     r    is_numpy_arrayr   v  s"    +Bd*Jz#zz/JJr   c                D    [        U 5      =(       a    U R                  S:H  $ )z@Check whether `arr` is a 1D NumPy Array without importing NumPy.r   r   ndimr   s    r    is_numpy_array_1dr   {      #0388q=0r   c                    [        5       =n=(       a8    [        U 5      =(       a&    UR                  U R                  UR                  5      $ r`   )r6   r   
issubdtypedtypeintegerr   s     r    is_numpy_array_1d_intr     s9    {	 	1c"	1MM#))RZZ0r   c                D    [        U 5      =(       a    U R                  S:H  $ )z@Check whether `arr` is a 2D NumPy Array without importing NumPy.   r   r   s    r    is_numpy_array_2dr     r   r   c                V    [        5       =nSL=(       a    [        XR                  5      $ )zACheck whether `scalar` is a NumPy Scalar without importing NumPy.N)r6   ra   generic)scalarr   s     r    is_numpy_scalarr     s$    
 +Bd*Mz&**/MMr   c                v    [        U 5        [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ )zCheck whether `df` is a pandas-like DataFrame without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.

Warning:
    This method cannot be called on a Narwhals DataFrame/LazyFrame.
)rY   rk   rx   r~   )rW   s    r    is_pandas_like_dataframer     s.      #r"U&8&<U@QRT@UUr   c                v    [        U 5        [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ )zCheck whether `ser` is a pandas-like Series without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.

Warning:
    This method cannot be called on Narwhals Series.
)r]   ro   rz   r   r\   s    r    is_pandas_like_seriesr     s+     c"C OOC$8ON3<OOr   c                `    [        U 5      =(       d    [        U 5      =(       d    [        U 5      $ )zyCheck whether `index` is a pandas-like Index without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.
)ru   r|   r   )rs   s    r    is_pandas_like_indexr     s%     	O."7O=;Or   c                    SSK Jn  [        X5      =(       dB    [        U S5      =(       d/    [	        U 5      =(       d    [        U 5      =(       d    [        U 5      $ )ak  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   ra   rD   r   r   r   )native_seriesr   s     r    is_into_seriesr     sQ    4 ' 	=) 	0="78	0M*	0 $M2	0 !/r   c                    SSK Jn  [        X5      =(       dB    [        U S5      =(       d/    [	        U 5      =(       d    [        U 5      =(       d    [        U 5      $ )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   ra   rD   r   r   r   )native_dataframer   s     r    is_into_dataframer     sV    4 - 	#/ 	6#%=>	6/0	6 ,-	6 $$45r   c                $    SSK Jn  [        X5      $ )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   ra   r   s     r    rS   rS          -b$$r   c                $    SSK Jn  [        X5      $ )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   ra   )lfr   s     r    rT   rT     r   r   c                $    SSK Jn  [        X5      $ )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   ra   )r\   r   s     r    r[   r[     s     'c""r   c                Z    [        U 5      =(       a    U R                  R                  5       $ r`   )r[   r   
is_integerr   s    r    is_narwhals_series_intr   )  s    c"=syy';';'==r   )r+   rA   r(   r6   r%   r!   r2   r~   r   r   r   r   r   rx   rz   rS   rT   r[   r   rk   ru   r   r   ro   r   r   r   r   r   )returnr   )rW   r   r   None)r\   r   r   r   )rW   r   r   zTypeIs[pd.DataFrame])r\   r   r   zTypeIs[pd.Series[Any]])rs   r   r   zTypeIs[pd.Index[Any]])rW   r   r   zTypeIs[mpd.DataFrame])r\   r   r   zTypeIs[mpd.Series])rs   r   r   zTypeIs[mpd.Index[Any]])rW   r   r   zTypeIs[cudf.DataFrame])r\   r   r   zTypeIs[cudf.Series[Any]])rs   r   r   zTypeIs[cudf.Index])r   r   r   r   )rW   r   r   zTypeIs[dd.DataFrame])rW   r   r   zTypeIs[duckdb.DuckDBPyRelation])rW   r   r   zTypeIs[ibis.Table])rW   r   r   zTypeIs[pl.DataFrame])rW   r   r   zTypeIs[pl.LazyFrame])r\   r   r   zTypeIs[pl.Series])r\   r   r   zTypeIs[pa.ChunkedArray[Any]])rW   r   r   zTypeIs[pa.Table])r   r   r   zTypeIs[pa.Scalar[Any]])rW   r   r   zTypeIs[pyspark_sql.DataFrame])rW   r   r   zTypeIs[PySparkConnectDataFrame])rW   r   r   zTypeIs[SQLFrameDataFrame])r   zAny | _NDArray[_ShapeT]r   zTypeIs[_NDArray[_ShapeT]])r   r   r   zTypeIs[_1DArray])r   r   r   zTypeIs[_1DArrayInt])r   r   r   zTypeIs[_2DArray])r   r   r   zTypeGuard[_NumpyScalar])rW   r   r   r   )r\   r   r   r   )rs   r   r   r   )r   zAny | IntoSeriesTr   zTypeIs[IntoSeriesT])r   zAny | IntoDataFrameTr   zTypeIs[IntoDataFrameT])rW   zDataFrame[IntoDataFrameT] | Anyr   z!TypeIs[DataFrame[IntoDataFrameT]])r   zAny | LazyFrame[IntoLazyFrameT]r   z!TypeIs[LazyFrame[IntoLazyFrameT]])r\   zAny | Series[IntoSeriesT]r   zTypeIs[Series[IntoSeriesT]])f
__future__r   r   typingr   r   r*   dask.dataframe	dataframerE   r=   r@   modin.pandasr$   rw   rj   r   r   r1   r   pyspark.sqlsqlr   r   r   PySparkConnectDataFrametyping_extensionsr   r	   narwhals._spark_like.dataframer
   r   r   r   r   narwhals.typingr   r   r   r   r   r   r   r   r   	frozensetri   r!   r%   r(   r+   r/   r2   r6   r9   r;   r>   rA   rF   rI   rK   rM   rP   rY   r]   rk   ro   ru   rx   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   rS   rT   r[   r   __all__r   r   r    <module>r      s   # 
 %%R3@7&
 
 
  +'+
+
)
)
,
*
)
3
+
)
.,
0
8
-
NLM
OMU	VMMKRJL
 K
1
1
N	V	P"J"J%'%&%%'%&%	#>r   