o
    h8                     @  s  d dl mZ d dlZd dlmZ d dlmZ erd 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 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% 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* d dl#m+Z+ e,dgZ-dddZ.dddZ/dddZ0dddZ1ddd Z2dd!d"Z3dd#d$Z4dd%d&Z5dd'd(Z6dd)d*Z7dd+d,Z8dd-d.Z9dd/d0Z:dd1d2Z;dd3d4Z<dd7d8Z=dd;d<Z>dd?d@Z?ddBdCZ@ddEdFZAddHdIZBddKdLZCddNdOZDddQdRZEddTdUZFddWdXZGddZd[ZHdd]d^ZIdd`daZJddcddZKddgdhZLddjdkZMddmdnZNddpdqZOddudvZPddxdyZQdd{d|ZRdddZSdddZTdddZUdddZVdddZWdddZXdddZYdddZZdddZ[g dZ\dS )    )annotationsN)TYPE_CHECKING)Any)	TypeGuard)TypeIs)ArrowChunkedArray)SQLFrameDataFrame	DataFrame	LazyFrameSeries)FrameT)IntoDataFrameT)IntoSeriesT)_1DArray)_2DArray)_NDArray)_NumpyScalar)_ShapeT	fireducksreturnr   c                   C     t jddS )z;Get Polars module (if already imported - else return None).polarsNsysmodulesget r   r   I/var/www/vscode/kcb/lib/python3.10/site-packages/narwhals/dependencies.py
get_polars+      r!   c                   C  r   )z;Get pandas module (if already imported - else return None).pandasNr   r   r   r   r    
get_pandas0   r"   r$   c                  C  s    t jdd } dur| jS dS )zAGet modin.pandas module (if already imported - else return None).modinN)r   r   r   r#   )r%   r   r   r    	get_modin5   s   r&   c                   C  r   )z9Get cudf module (if already imported - else return None).cudfNr   r   r   r   r    get_cudf<   r"   r(   c                   C  r   )z9Get cupy module (if already imported - else return None).cupyNr   r   r   r   r    get_cupyA   r"   r*   c                   C  r   )z<Get pyarrow module (if already imported - else return None).pyarrowNr   r   r   r   r    get_pyarrowF   r"   r,   c                   C  r   )z:Get numpy module (if already imported - else return None).numpyNr   r   r   r   r    	get_numpyK   r"   r.   c                   C  r   )z2Get dask (if already imported - else return None).daskNr   r   r   r   r    get_daskP   r"   r0   c                   C  r   )zCGet dask.dataframe module (if already imported - else return None).zdask.dataframeNr   r   r   r   r    get_dask_dataframeU   r"   r1   c                   C  r   )z;Get duckdb module (if already imported - else return None).duckdbNr   r   r   r   r    
get_duckdbZ   r"   r3   c                   C  r   )z9Get ibis module (if already imported - else return None).ibisNr   r   r   r   r    get_ibis_   r"   r5   c                   C  r   )z>Get dask_expr module (if already imported - else return None).	dask_exprNr   r   r   r   r    get_dask_exprd   r"   r7   c                   C  r   )z<Get pyspark module (if already imported - else return None).pysparkNr   r   r   r   r    get_pysparki   r"   r9   c                   C  r   )z@Get pyspark.sql module (if already imported - else return None).zpyspark.sqlNr   r   r   r   r    get_pyspark_sqln   r"   r:   c                   C  r   )z=Get sqlframe module (if already imported - else return None).sqlframeNr   r   r   r   r    get_sqlframes   r"   r<   dfTypeIs[pd.DataFrame]c                   2   t   }durt |jpt fddtD S )zBCheck whether `df` is a pandas DataFrame without importing pandas.Nc                 3  4    | ]}t j|d  d uot jjV  qd S N)r   r   r   
isinstancer#   r
   .0module_namer=   modr   r    	<genexpr>z       
z&is_pandas_dataframe.<locals>.<genexpr>)r$   rB   r
   anyIMPORT_HOOKS)r=   pdr   rF   r    is_pandas_dataframex      (rM   serTypeIs[pd.Series[Any]]c                   s2   t   }durt|jpt fddtD S )z@Check whether `ser` is a pandas Series without importing pandas.Nc                 3  s4    | ]}t j|d   d uot jjV  qd S rA   )r   r   r   rB   r#   r   rC   rG   rO   r   r    rH      rI   z#is_pandas_series.<locals>.<genexpr>)r$   rB   r   rJ   rK   )rO   rL   r   rQ   r    is_pandas_series   rN   rR   indexTypeIs[pd.Index[Any]]c                   r?   )zACheck whether `index` is a pandas Index without importing pandas.Nc                 3  r@   rA   )r   r   r   rB   r#   IndexrC   rS   rG   r   r    rH      rI   z"is_pandas_index.<locals>.<genexpr>)r$   rB   rU   rJ   rK   )rS   rL   r   rV   r    is_pandas_index   rN   rW   TypeIs[mpd.DataFrame]c                 C     t   }duot| |jS )z@Check whether `df` is a modin DataFrame without importing modin.N)r&   rB   r
   )r=   mpdr   r   r    is_modin_dataframe      r[   TypeIs[mpd.Series]c                 C  rY   )z>Check whether `ser` is a modin Series without importing modin.N)r&   rB   r   )rO   rZ   r   r   r    is_modin_series   r\   r^   TypeIs[mpd.Index]c                 C  rY   )z?Check whether `index` is a modin Index without importing modin.N)r&   rB   rU   )rS   rZ   r   r   r    is_modin_index      r`   TypeIs[cudf.DataFrame]c                 C  rY   )z>Check whether `df` is a cudf DataFrame without importing cudf.N)r(   rB   r
   )r=   r'   r   r   r    is_cudf_dataframe   r\   rc   TypeIs[cudf.Series[Any]]c                 C  rY   )z<Check whether `ser` is a cudf Series without importing cudf.N)r(   rB   r   )rO   r'   r   r   r    is_cudf_series   r\   re   TypeIs[cudf.Index]c                 C  rY   )z=Check whether `index` is a cudf Index without importing cudf.N)r(   rB   rU   )rS   r'   r   r   r    is_cudf_index   ra   rg   TypeIs[dd.DataFrame]c                 C  rY   )z>Check whether `df` is a Dask DataFrame without importing Dask.N)r1   rB   r
   )r=   ddr   r   r    is_dask_dataframe   r\   rj   TypeIs[duckdb.DuckDBPyRelation]c                 C  rY   )zACheck whether `df` is a DuckDB Relation without importing DuckDB.N)r3   rB   DuckDBPyRelation)r=   r2   r   r   r    is_duckdb_relation   ra   rm   TypeIs[ibis.Table]c                 C  s   t   }duot| |jjjS )z:Check whether `df` is a Ibis Table without importing Ibis.N)r5   rB   exprtypesTable)r=   r4   r   r   r    is_ibis_table   s   rr   TypeIs[pl.DataFrame]c                 C  rY   )zBCheck whether `df` is a Polars DataFrame without importing Polars.N)r!   rB   r
   r=   plr   r   r    is_polars_dataframe   r\   rv   TypeIs[pl.LazyFrame]c                 C  rY   )zBCheck whether `df` is a Polars LazyFrame without importing Polars.N)r!   rB   r   rt   r   r   r    is_polars_lazyframe   r\   rx   TypeIs[pl.Series]c                 C  rY   )z@Check whether `ser` is a Polars Series without importing Polars.N)r!   rB   r   )rO   ru   r   r   r    is_polars_series   r\   rz   Any | ArrowChunkedArrayTypeIs[ArrowChunkedArray]c                 C  rY   )zHCheck whether `ser` is a PyArrow ChunkedArray without importing PyArrow.N)r,   rB   ChunkedArray)rO   par   r   r    is_pyarrow_chunked_array   s   r   TypeIs[pa.Table]c                 C  rY   )z@Check whether `df` is a PyArrow Table without importing PyArrow.N)r,   rB   rq   )r=   r~   r   r   r    is_pyarrow_table   r\   r   TypeIs[pyspark_sql.DataFrame]c                 C  s   t t  }duot| |jS )zDCheck whether `df` is a PySpark DataFrame without importing PySpark.N)boolr:   rB   r
   )r=   pyspark_sqlr   r   r    is_pyspark_dataframe   s   
r   TypeIs[SQLFrameDataFrame]c                 C  s$   t  durddlm} t| |S dS )zFCheck whether `df` is a SQLFrame DataFrame without importing SQLFrame.Nr   )BaseDataFrameF)r<   sqlframe.base.dataframer   rB   )r=   r   r   r   r    is_sqlframe_dataframe   s   

r   arrAny | _NDArray[_ShapeT]TypeIs[_NDArray[_ShapeT]]c                 C  rY   )z=Check whether `arr` is a NumPy Array without importing NumPy.N)r.   rB   ndarray)r   npr   r   r    is_numpy_array   r\   r   TypeIs[_1DArray]c                 C     t | o| jdkS )z@Check whether `arr` is a 1D NumPy Array without importing NumPy.   r   ndimr   r   r   r    is_numpy_array_1d      r   TypeIs[_2DArray]c                 C  r   )z@Check whether `arr` is a 2D NumPy Array without importing NumPy.   r   r   r   r   r    is_numpy_array_2d   r   r   scalarTypeGuard[_NumpyScalar]c                 C  rY   )zACheck whether `scalar` is a NumPy Scalar without importing NumPy.N)r.   rB   generic)r   r   r   r   r    is_numpy_scalar  s   r   r   c                 C     t | pt| pt| S )zCheck whether `df` is a pandas-like DataFrame without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rM   r[   rc   )r=   r   r   r    is_pandas_like_dataframe	     r   c                 C  r   )zCheck whether `ser` is a pandas-like Series without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rR   r^   re   )rO   r   r   r    is_pandas_like_series  r   r   c                 C  r   )zCheck whether `index` is a pandas-like Index without doing any imports.

    By "pandas-like", we mean: pandas, Modin, cuDF.
    )rW   r`   rg   )rS   r   r   r    is_pandas_like_index  s   r   native_seriesAny | IntoSeriesTTypeIs[IntoSeriesT]c                 C  8   ddl m} t| |pt| dpt| pt| p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   rB   hasattrrz   r   r   )r   r   r   r   r    is_into_series#     
r   native_dataframeAny | IntoDataFrameTTypeIs[IntoDataFrameT]c                 C  r   )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
   rB   r   rv   r   r   )r   r
   r   r   r    is_into_dataframeH  r   r   DataFrame[IntoDataFrameT] | Any!TypeIs[DataFrame[IntoDataFrameT]]c                 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
   rB   )r=   r
   r   r   r    is_narwhals_dataframem  s   	
r   lfAny | LazyFrame[FrameT]TypeIs[LazyFrame[FrameT]]c                 C  r   )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   rB   )r   r   r   r   r    is_narwhals_lazyframe{     
r   Any | Series[IntoSeriesT]TypeIs[Series[IntoSeriesT]]c                 C  r   )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   rB   )rO   r   r   r   r    is_narwhals_series  r   r   )r(   r5   r&   r.   r$   r!   r,   rc   re   rj   rr   r   r   r[   r^   r   r   r   r   rM   rW   r   r   rR   rv   rx   rz   r   r   )r   r   )r=   r   r   r>   )rO   r   r   rP   )rS   r   r   rT   )r=   r   r   rX   )rO   r   r   r]   )rS   r   r   r_   )r=   r   r   rb   )rO   r   r   rd   )rS   r   r   rf   )r=   r   r   rh   )r=   r   r   rk   )r=   r   r   rn   )r=   r   r   rs   )r=   r   r   rw   )rO   r   r   ry   )rO   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   )rO   r   r   r   )rS   r   r   r   )r   r   r   r   )r   r   r   r   )r=   r   r   r   )r   r   r   r   )rO   r   r   r   )]
__future__r   r   typingr   r   r'   dask.dataframe	dataframeri   r2   r4   modin.pandasr#   rZ   rL   r   ru   r+   r~   pyspark.sqlsqlr   typing_extensionsr   r   narwhals._arrow.typingr   narwhals._spark_like.dataframer   r   r
   r   r   r   narwhals.typingr   r   r   r   r   r   r   r   	frozensetrK   r!   r$   r&   r(   r*   r,   r.   r0   r1   r3   r5   r7   r9   r:   r<   rM   rR   rW   r[   r^   r`   rc   re   rg   rj   rm   rr   rv   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __all__r   r   r   r    <module>   s   

















	
	
	















	








%
%

