
    ^j                       U d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlZd dlmZmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d d
l$m%Z&m'Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZK d dlLmMZMmNZNmOZO d dlPmQZR d dlSmTZU d dlVmWZWmXZXmYZY d dlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb d dlcmdZdmeZemfZf errd dlgmhZhmiZimjZjmkZk d dllmmZmmnZnmoZo d dlpmqZqmrZrmsZsmtZtmuZumvZvmwZw d dlxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZ d dl$mZmZ d dlmZmZmZmZmZmZmZmZmZ  ede      Z emd      Z ed      Z G d de&e\         Z% G d  d!e(e^         Z' G d" d#eUe`         ZT G d$ d%eK      ZJ G d& d'eR      ZQe
dsd(       Ze
dtd)       Ze
dud*       Ze
dvd+       Z	 	 	 	 dwd,Ze
dxd-       Ze
dyd.       Ze
	 	 	 	 	 	 dzd/       Ze
d{d0       Ze
	 	 	 	 	 	 d|d1       Ze
	 	 	 	 	 	 d}d2       Ze
	 	 	 	 	 	 d~d3       Ze
	 	 	 	 	 	 dd4       Ze
	 	 	 	 	 	 dd5       Ze
	 	 	 	 	 	 dd6       Ze
dd7       Ze
	 	 	 	 	 	 	 	 	 	 	 	 dd8       Zd9d9d9dd:	 	 	 	 	 	 	 	 	 	 	 dd;Ze
d<d=	 	 	 	 	 dd>       Ze
d<d=	 	 	 	 	 dd?       Ze
d<d=	 	 	 	 	 dd@       Ze
ddA       Zd9d=	 	 	 	 	 ddBZ	 ddCd9d9dCd:	 	 	 	 	 	 	 	 	 	 	 ddDZddEZddFZddGZddHZddIZdddJZddKZddLZddMZddNZddOZddPZddQZddRZddSZddTZddUZ	 d	 	 	 	 	 	 	 ddVZdWdXddYZdZd9d[	 	 	 	 	 	 	 	 	 dd\Zdd]Zdd^Z G d_ d`ejR                        Z G da dbejT                  eJ      ZddcZ	 d	 	 	 	 	 	 	 	 	 dddZ	 	 	 	 	 	 ddeZ	 dddf	 	 	 	 	 	 	 ddgZe%j^                  Zdhedi<   	 d	 	 	 	 	 	 	 ddjZdkdl	 	 	 	 	 	 	 	 	 ddmZdkdl	 	 	 	 	 	 	 	 	 ddnZ	 	 	 	 	 	 	 	 ddoZ	 	 	 	 	 	 	 	 ddpZddqZg drZy)    )annotationswraps)TYPE_CHECKINGAnyFinalLiteralcastoverloadN)
exceptions	functions)issue_warning)ExprKindExprNode)TypeVarassert_never)ImplementationVersiongenerate_temporary_column_nameinherit_docis_ordered_categoricalmaybe_align_indexmaybe_convert_dtypesmaybe_get_indexmaybe_reset_indexmaybe_set_indexnot_implemented)	DataFrame	LazyFrame)ArrayBinaryBooleanCategoricalDateDatetimeDecimalDurationEnumFieldFloat16Float32Float64Int8Int16Int32Int64Int128ListObjectStringStructTimeUInt8UInt16UInt32UInt64UInt128Unknown)NarwhalsUnstableWarning)Expr)_new_series_implconcatshow_versions)Schema)Series)dependenciesdtypes	selectors)
DataFrameTIntoDataFrameT	IntoFrameIntoLazyFrameT
IntoSeriesIntoSeriesT
LazyFrameTSeriesT)_from_native_implget_native_namespaceto_py_scalar)CallableIterableMappingSequence)	ParamSpecSelfUnpack)AllowAny	AllowLazyAllowSeriesExcludeSeriesIntoArrowTable
OnlySeriesPassThroughUnknown)ArrowBackendEagerAllowedIntoBackendLazyAllowedPandasPolars)MultiColSelectorMultiIndexSelector)		IntoDTypeIntoExpr
IntoSchemaNonNestedLiteralPythonLiteralSingleColSelectorSingleIndexSelector_1DArray_2DArrayT)defaultPRc                      e Zd Zej                  Z ee      d fd       Ze		 	 	 	 	 	 d fd       Z
e		 ddd	 	 	 	 	 	 	 d fd       Ze		 d	 	 	 	 	 	 	 d fd       Ze		 d	 	 	 	 	 	 	 d fd       Zed d       Zed!d	       Zed"d
       Ze	 	 	 	 d#d       Ze	 	 	 	 d$d       Z	 	 	 	 d% fdZd& fdZ	 ddd	 	 	 	 	 d' fdZeddd(d       Zed)d       Zedd	 	 	 d*d       Zdd	 	 	 d* fdZd+ fdZd+ fdZ xZS ),r   c               d    |j                   t        j                  u sJ t        |   ||       y N)level_versionr   V2super__init__selfdfry   	__class__s      T/opt/ringagent/.cad-venv/lib/python3.12/site-packages/narwhals/stable/v2/__init__.pyr~   zDataFrame.__init__v   +    {{gjj(((5)    c               >    t         |   ||      }t        d|      S NbackendDataFrame[Any])r}   
from_arrowr
   )clsnative_framer   resultr   s       r   r   zDataFrame.from_arrow~   s'     #L'#B$f--r   Nr   c               @    t         |   |||      }t        d|      S r   )r}   	from_dictr
   r   dataschemar   r   r   s        r   r   zDataFrame.from_dict   s)     "4"A$f--r   c               @    t         |   |||      }t        d|      S r   )r}   
from_dictsr
   r   s        r   r   zDataFrame.from_dicts   )     #D&'#B$f--r   c               @    t         |   |||      }t        d|      S r   r}   
from_numpyr
   r   s        r   r   zDataFrame.from_numpy   r   r   c                "    t        dt              S )Ntype[Series[Any]])r
   rC   r   s    r   _serieszDataFrame._series   s    '00r   c                "    t        dt              S )Ntype[LazyFrame[Any]])r
   r   r   s    r   
_lazyframezDataFrame._lazyframe   s    *I66r   c                     y N r   items     r   __getitem__zDataFrame.__getitem__   s    WZr   c                     y r   r   r   s     r   r   zDataFrame.__getitem__   s     r   c                     y r   r   r   s     r   r   zDataFrame.__getitem__   s     r   c                "    t         |   |      S r   )r}   r   )r   r   r   s     r   r   zDataFrame.__getitem__   s     w"4((r   c                "    t         |   |      S r   )r}   
get_column)r   namer   s     r   r   zDataFrame.get_column   s     w!$''r   )sessionc               8    t        t        | 	  ||            S )N)r   r   )
_stableifyr}   lazy)r   r   r   r   s      r   r   zDataFrame.lazy   s     %',w,HIIr   .	as_seriesc                    y r   r   r   r   s     r   to_dictzDataFrame.to_dict   s    TWr   c                    y r   r   r   s     r   r   zDataFrame.to_dict   s    MPr   Tc                    y r   r   r   s     r   r   zDataFrame.to_dict   s     9<r   c               $    t         |   |      S )Nr   )r}   r   )r   r   r   s     r   r   zDataFrame.to_dict   s    
 w33r   c                2    t        t        | 	               S r   )r   r}   is_duplicatedr   r   s    r   r   zDataFrame.is_duplicated   s    %'/122r   c                2    t        t        | 	               S r   )r   r}   	is_uniquer   s    r   r   zDataFrame.is_unique   s    %'+-..r   r   r   ry   &Literal['full', 'lazy', 'interchange']returnNoner   r]   r   IntoBackend[EagerAllowed]r   r   r   r   zMapping[str, Any]r   2IntoSchema | Mapping[str, IntoDType | None] | Noner   z IntoBackend[EagerAllowed] | Noner   r   )r   zSequence[Mapping[str, Any]]r   r   r   r   r   r   r   rq   r   z!IntoSchema | Sequence[str] | Noner   r   r   r   )r   r   )r   r   )r   z-tuple[SingleIndexSelector, SingleColSelector]r   r   )r   z2str | tuple[MultiIndexSelector, SingleColSelector]r   Series[Any])r   zSingleIndexSelector | MultiIndexSelector | MultiColSelector | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, MultiColSelector]r   rW   )r   a  SingleIndexSelector | SingleColSelector | MultiColSelector | MultiIndexSelector | tuple[SingleIndexSelector, SingleColSelector] | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, SingleColSelector] | tuple[MultiIndexSelector, MultiColSelector]r   zSeries[Any] | Self | Any)r   strr   r   )r   zIntoBackend[LazyAllowed] | Noner   z
Any | Noner   LazyFrame[Any])r   zLiteral[True]r   zdict[str, Series[Any]])r   Literal[False]r   zdict[str, list[Any]])r   boolr   z-dict[str, Series[Any]] | dict[str, list[Any]])r   r   )__name__
__module____qualname__r   r|   r{   r   NwDataFramer~   classmethodr   r   r   r   propertyr   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r   s   s`   zzH* * .).7P.	. .  FJ.
 59.. C.
 2. 
. .  FJ.). C.
 +. 
. .  59.. 2.
 +. 
. . 1 1 7 7 Z ZF	  	:	 
	 	):) 
")( 48J #	J0J 	J
 
J 47W WP P#'< <	6< < $(4 4	643/ /r   r   c                  z     e Zd Zej                  Z ee      d fd       Ze	dd       Z
	 d	 	 	 	 	 d fdZ xZS )r   c               d    |j                   t        j                  u sJ t        |   ||       y rx   rz   r   s      r   r~   zLazyFrame.__init__   r   r   c                    t         S r   r   r   s    r   
_dataframezLazyFrame._dataframe       r   c                8    t        t        |   dd|i|      S )Nr   r   )r   r}   collect)r   r   kwargsr   s      r   r   zLazyFrame.collect   s!     %'/D'DVDEEr   r   r   ztype[DataFrame[Any]]r   )r   z+IntoBackend[Polars | Pandas | Arrow] | Noner   r   r   r   )r   r   r   r   r|   r{   r   NwLazyFramer~   r   r   r   r   r   s   @r   r   r      se    zzH* *   FJFBFUXF	F Fr   r   c                  &    e Zd ZU ej                  Z ee      	 	 	 	 	 	 d fd       Ze	dd       Z
e	 d	 	 	 	 	 	 	 	 	 d fd       Ze	 d	 	 	 	 	 	 	 	 	 d fd       Zd fdZddddd		 	 	 	 	 	 	 	 	 d fd
Z e       Zded<   ddd fdZ xZS )rC   r   c               d    |j                   t        j                  u sJ t        |   ||       y rx   rz   )r   seriesry   r   s      r   r~   zSeries.__init__  s-     '**,,,u-r   c                    t         S r   r   r   s    r   r   zSeries._dataframe  r   r   Nc               B    t         |   ||||      }t        d|      S Nr   r   r   r   r   valuesdtyper   r   r   s         r   r   zSeries.from_numpy  s*     #D&%#IM6**r   c               B    t         |   ||||      }t        d|      S r   )r}   from_iterabler
   r   s         r   r   zSeries.from_iterable"  s*     &tVUG&LM6**r   c                2    t        t        | 	               S r   )r   r}   to_framer   s    r   r   zSeries.to_frame.  s    %'*,--r   Fsortparallelr   	normalizec               <    t        t        | 	  ||||            S )Nr   )r   r}   value_counts)r   r   r   r   r   r   s        r   r   zSeries.value_counts1  s-     G H49 ! 
 	
r   histignore_nullsc               H    d}t        |t               t        |   |      S )Nz_`Series.any_value` is being called from the stable API although considered an unstable feature.r   )r   r=   r}   	any_value)r   r   msgr   s      r   r   zSeries.any_valueB  s-    # 	 	c23w l ;;r   )r   r   ry   r   r   r   r   r   )
r   r   r   rp   r   IntoDType | Noner   r   r   r   )
r   r   r   zIterable[Any]r   r   r   r   r   r   )r   r   )
r   r   r   r   r   z
str | Noner   r   r   r   )r   r   r   rm   )r   r   r   r   r|   r{   r   NwSeriesr~   r   r   r   r   r   r   r   r   r   __annotations__r   r   r   s   @r   rC   rC     sG   zzH..%K.	. .   
 #'		+	+ 	+  		+ +	+ 
	+ 	+ 
 #'		+	+ 	+  		+ +	+ 
	+ 	+. 
 
 	

 
 
 

  !D#!05 < <r   rC   c                  *    e Zd ZddddZddZddZy)	r>   Fr   c               |    d}t        |t               | j                  t        t        j
                  d|            S )Nz]`Expr.any_value` is being called from the stable API although considered an unstable feature.r   r   )r   r=   _append_noder   r   AGGREGATION)r   r   r   s      r   r   zExpr.any_valueL  s>    # 	 	c23  X));\R
 	
r   c                T    | j                  t        t        j                  d            S )zGet the first value.firstr   r   r   ORDERABLE_AGGREGATIONr   s    r   r   z
Expr.firstV  s       (*H*H'!RSSr   c                T    | j                  t        t        j                  d            S )zGet the last value.lastr  r   s    r   r  z	Expr.lastZ  s       (*H*H&!QRRr   N)r   r   r   rW   )r   rW   )r   r   r   r   r   r  r   r   r   r>   r>   K  s    05 
TSr   r>   c                  $    e Zd Zej                  Zy)rB   N)r   r   r   r   r|   r{   r   r   r   rB   rB   _  s    zzHr   rB   c                     y r   r   objs    r   r   r   c      ORr   c                     y r   r   r  s    r   r   r   e  r	  r   c                     y r   r   r  s    r   r   r   g      CFr   c                     y r   r   r  s    r   r   r   i  s    %(r   c                2   t        | t              r>t        | j                  j	                  t
        j                        | j                        S t        | t              r>t        | j                  j	                  t
        j                        | j                        S t        | t              r>t        | j                  j	                  t
        j                        | j                        S t        | t              rt        | j                   S t!        |        y rx   )
isinstancer   r   _compliant_frame_with_versionr   r|   _levelr   r   r   rC   _compliant_seriesNwExprr>   _nodesr   r  s    r   r   r   m  s     #{#--;;GJJGszzZZ#{#--;;GJJGszzZZ#x c++99'**ESZZXX#vSZZ  r   c                     y r   r   native_objectkwdss     r   from_nativer  ~  s    PSr   c                     y r   r   r  s     r   r  r    s    QTr   c                     y r   r   r  s     r   r  r    s     r   c                     y r   r   r  s     r   r  r    s    UXr   c                     y r   r   r  s     r   r  r         !$r   c                     y r   r   r  s     r   r  r         r   c                     y r   r   r  s     r   r  r    r!  r   c                     y r   r   r  s     r   r  r    r  r   c                     y r   r   r  s     r   r  r    s     7:r   c                     y r   r   r  s     r   r  r    s	     SVr   c                     y r   r   r  s     r   r  r    s    LOr   c                    y r   r   r  pass_through
eager_onlyseries_onlyallow_seriess        r   r  r    s     r   Fr)  r*  r+  r,  c          	         t        | t        t        f      r|s| S t        | t              r|s|r| S t	        | ||||dt
        j                        S )a  Convert `native_object` to Narwhals Dataframe, Lazyframe, or Series.

    Arguments:
        native_object: Raw object from user.
            Depending on the other arguments, input object can be

            - a Dataframe / Lazyframe / Series supported by Narwhals (pandas, Polars, PyArrow, ...)
            - an object which implements `__narwhals_dataframe__`, `__narwhals_lazyframe__`,
              or `__narwhals_series__`
        pass_through: Determine what happens if the object can't be converted to Narwhals

            - `False` (default): raise an error
            - `True`: pass object through as-is
        eager_only: Whether to only allow eager objects

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        series_only: Whether to only allow Series

            - `False` (default): don't require `native_object` to be a Series
            - `True`: only convert to Narwhals if `native_object` is a Series
        allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)

            - `False` or `None` (default): don't convert to Narwhals if `native_object` is a Series
            - `True`: allow `native_object` to be a Series

    Returns:
        DataFrame, LazyFrame, Series, or original object, depending
            on which combination of parameters was passed.
    F)r)  r*  r+  r,  eager_or_interchange_onlyversion)r  r   r   rC   rO   r   r|   r(  s        r   r  r    sV    X -)Y!78-(k\!!"'

 r   .r)  c                    y r   r   narwhals_objectr)  s     r   	to_nativer5         r   c                    y r   r   r3  s     r   r5  r5    r6  r   c                    y r   r   r3  s     r   r5  r5    s     r   c                    y r   r   r3  s     r   r5  r5    r  r   c               0    t        j                  | |      S )a]  Convert Narwhals object to native one.

    Arguments:
        narwhals_object: Narwhals object.
        pass_through: Determine what happens if `narwhals_object` isn't a Narwhals class

            - `False` (default): raise an error
            - `True`: pass object through as-is

    Returns:
        Object of class that user started with.
    r1  )nwr5  r3  s     r   r5  r5    s    & <<lCCr   Tc               4    dfd}| |S  ||       S )a  Decorate function so it becomes dataframe-agnostic.

    This will try to convert any dataframe/series-like object into the Narwhals
    respective DataFrame/Series, while leaving the other parameters as they are.
    Similarly, if the output of the function is a Narwhals DataFrame or Series, it will be
    converted back to the original dataframe/series type, while if the output is another
    type it will be left as is.
    By setting `pass_through=False`, then every input and every output will be required to be a
    dataframe/series-like object.

    Arguments:
        func: Function to wrap in a `from_native`-`to_native` block.
        pass_through: Determine what happens if the object can't be converted to Narwhals

            - `False`: raise an error
            - `True` (default): pass object through as-is
        eager_only: Whether to only allow eager objects

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        series_only: Whether to only allow Series

            - `False` (default): don't require `native_object` to be a Series
            - `True`: only convert to Narwhals if `native_object` is a Series
        allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)

            - `False` or `None`: don't convert to Narwhals if `native_object` is a Series
            - `True` (default): allow `native_object` to be a Series

    Returns:
        Decorated function.
    c                :     t               d fd       }|S )Nc                    | D cg c]  }t        |       }}|j                         D ci c]  \  }}|t        |       }}}g ||j                         D ch c]  }t        |dd       x}r |        }	}|	j	                         dkD  rd}
t        |
       |i |}t        |      S c c}w c c}}w c c}w )Nr-  __native_namespace__   z_Found multiple backends. Make sure that all dataframe/series inputs come from the same backend.r1  )r  itemsr   getattr__len__
ValueErrorr5  )argsr   argargs_nwr   value	kwargs_nwvbbackendsr   r   r,  r*  funcr)  r+  s               r   wrapperz.narwhalify.<locals>.decorator.<locals>.wrapper9  s     	  !-) +!-	G 	& $*<<>	  D% k!-) +!- 	I 	 978Y%5%5%78 $:DAAAA H  !A%w o%70i0FV,??E		s   B;C 'C)rE  r   r   r   r   r   r   )rM  rN  r,  r*  r)  r+  s   ` r   	decoratorznarwhalify.<locals>.decorator8  s)    	t#	@ #	@ 
#	@J r   )rM  Callable[..., Any]r   rP  r   )rM  r)  r*  r+  r,  rO  s    ```` r   
narwhalifyrQ    s&    R' 'R |T?r   c                 <    t        t        j                               S )z3Instantiate an expression representing all columns.)r   r;  allr   r   r   rS  rS  g      bffhr   c                 8    t        t        j                  |        S )zCreates an expression that references one or more columns by their name(s).

    Arguments:
        names: Name(s) of the columns to use.
    )r   r;  colnamess    r   rV  rV  l  s     bffen%%r   c                 8    t        t        j                  |        S )zCreates an expression that excludes columns by their name(s).

    Arguments:
        names: Name(s) of the columns to exclude.
    )r   r;  excluderW  s    r   rZ  rZ  u  s     bjj%())r   c                 8    t        t        j                  |        S )a!  Creates an expression that references one or more columns by their index(es).

    Notes:
        `nth` is not supported for Polars version<1.0.0. Please use
        [`narwhals.col`][] instead.

    Arguments:
        indices: One or more indices representing the columns to retrieve.
    )r   r;  nth)indicess    r   r\  r\  ~  s     bffg&''r   c                 <    t        t        j                               S )zReturn the number of rows.)r   r;  lenr   r   r   r_  r_    rT  r   c                @    t        t        j                  | |            S )a  Return an expression representing a literal value.

    Arguments:
        value: The value to use as literal. Can be a scalar value, list, tuple, or dict.
            Lists and tuples are converted to `List` dtype, dicts to `Struct` dtype.
        dtype: The data type of the literal value. If not provided, the data type will
            be inferred by the native library. For empty lists/dicts, dtype must be
            specified explicitly.
    )r   r;  lit)rH  r   s     r   ra  ra    s     bffUE*++r   c                 8    t        t        j                  |        S )zReturn the minimum value.

    Note:
       Syntactic sugar for ``nw.col(columns).min()``.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.
    )r   r;  mincolumnss    r   rc  rc         bffg&''r   c                 8    t        t        j                  |        S )zReturn the maximum value.

    Note:
       Syntactic sugar for ``nw.col(columns).max()``.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.
    )r   r;  maxrd  s    r   rh  rh    rf  r   c                 8    t        t        j                  |        S )zGet the mean value.

    Note:
        Syntactic sugar for ``nw.col(columns).mean()``

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function
    )r   r;  meanrd  s    r   rj  rj    s     bggw'((r   c                 8    t        t        j                  |        S )aL  Get the median value.

    Notes:
        - Syntactic sugar for ``nw.col(columns).median()``
        - Results might slightly differ across backends due to differences in the
            underlying algorithms used to compute the median.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function
    )r   r;  medianrd  s    r   rl  rl    s     bii)**r   c                 8    t        t        j                  |        S )zSum all values.

    Note:
        Syntactic sugar for ``nw.col(columns).sum()``

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function
    )r   r;  sumrd  s    r   rn  rn    rf  r   c                 8    t        t        j                  |        S )a
  Sum all values horizontally across columns.

    Warning:
        Unlike Polars, we support horizontal sum over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r;  sum_horizontalexprss    r   rp  rp         b''/00r   c                >    t        t        j                  |d| i      S )a  Compute the bitwise AND horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
        ignore_nulls: Whether to ignore nulls:

            - If `True`, null values are ignored. If there are no elements, the result
              is `True`.
            - If `False`, Kleene logic is followed. Note that this is not allowed for
              pandas with classical NumPy dtypes when null values are present.
    r   )r   r;  all_horizontalr   rr  s     r   ru  ru         b''J\JKKr   c                >    t        t        j                  |d| i      S )a  Compute the bitwise OR horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
        ignore_nulls: Whether to ignore nulls:

            - If `True`, null values are ignored. If there are no elements, the result
              is `False`.
            - If `False`, Kleene logic is followed. Note that this is not allowed for
              pandas with classical NumPy dtypes when null values are present.
    r   )r   r;  any_horizontalrv  s     r   ry  ry    rw  r   c                 8    t        t        j                  |        S )zCompute the mean of all values horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r;  mean_horizontalrq  s    r   r{  r{    s     b((%011r   c                 8    t        t        j                  |        S )a  Get the minimum value horizontally across columns.

    Notes:
        We support `min_horizontal` over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r;  min_horizontalrq  s    r   r}  r}    rs  r   c                 8    t        t        j                  |        S )a  Get the maximum value horizontally across columns.

    Notes:
        We support `max_horizontal` over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r;  max_horizontalrq  s    r   r  r    rs  r   c                D    t        t        j                  | ||            S )zCompute the Pearson's or Spearman rank correlation between two columns.

    Arguments:
        a: Column name or Expression
        b: Column name or Expression
        method: Correlation method ('pearson' or 'spearman')
    )method)r   r;  corr)arK  r  s      r   r  r  ,  s     bgga6233r   r@  ddofc               D    t        t        j                  | ||            S )a2  Compute the covariance between two columns.

    Arguments:
        a: Column name or Expression
        b: Column name or Expression
        ddof: "Delta Degrees of Freedom": the divisor used in the calculation is N - ddof,
            where N represents the number of elements. By default ddof is 1.
    r  )r   r;  cov)r  rK  r  s      r   r  r  9  s     bffQ-..r    	separatorr   c               H    t        t        j                  | g|||d      S )a  Horizontally concatenate columns into a single string column.

    Arguments:
        exprs: Columns to concatenate into a single string column. Accepts expression
            input. Strings are parsed as column names, other non-expression inputs are
            parsed as literals. Non-`String` columns are cast to `String`.
        *more_exprs: Additional columns to concatenate into a single string column,
            specified as positional arguments.
        separator: String that will be used to separate the values of each column.
        ignore_nulls: Ignore null values (default is `False`).
            If set to `False`, null values will be propagated and if the row contains any
            null values, the output is null.
    r  )r   r;  
concat_str)rr  r  r   
more_exprss       r   r  r  E  s)    & 
eYjYILY r   c                @    t        t        j                  | g|       S )zFormat expressions as a string.

    Arguments:
        f_string: A string that with placeholders.
        args: Expression(s) that fill the placeholders.
    )r   r;  format)f_stringrE  s     r   r  r  ]  s     bii04011r   c                @    t        t        j                  | g|       S )a  Folds the columns from left to right, keeping the first non-null value.

    Arguments:
        exprs: Columns to coalesce, must be a str, nw.Expr, or nw.Series
            where strings are parsed as column names and both nw.Expr/nw.Series
            are passed through as-is. Scalar values must be wrapped in `nw.lit`.

        *more_exprs: Additional columns to coalesce, specified as positional arguments.

    Raises:
        TypeError: If any of the inputs are not a str, nw.Expr, or nw.Series.
    )r   r;  coalesce)rr  r  s     r   r  r  g  s     bkk%5*566r   c                  &    e Zd Zedd       ZddZy)Whenc                *     | |j                   d      S )Nr   )chain)
_predicate)r   whens     r   	from_whenzWhen.from_whenx  s    4??"--r   c                f    g | j                   | j                  |f}t        j                  |      S r   )_chainr  Then_from_chain)r   rH  	new_chains      r   thenz	When.then|  s/    <dkk<DOOU#;<		**r   N)r  z	nw_f.Whenr   r  )rH  z&IntoExpr | NonNestedLiteral | _1DArrayr   r  )r   r   r   r   r  r  r   r   r   r  r  w  s    . .+r   r  c                  (     e Zd ZddZd fdZ xZS )r  c                ,    t        |d| j                  iS )Nr  )r  r  )r   
predicatess     r   r  z	Then.when  s    Z3t{{33r   c                4    t        t        | 	  |            S r   )r   r}   	otherwise)r   otherwise_valuer   s     r   r  zThen.otherwise  s    %'+O<==r   r  IntoExpr | Iterable[IntoExpr]r   r  )r  zIntoExpr | NonNestedLiteralr   r>   )r   r   r   r  r  r   r   s   @r   r  r    s    4> >r   r  c                 L    t         j                  t        j                  |        S )a  Start a `when-then-otherwise` expression.

    Expression similar to an `if-else` statement in Python. Always initiated by a
    `nw.when(<condition>).then(<value if condition>)`, and optionally followed by
    chained `.when(<condition>).then(<value>)` calls.
    An `.otherwise(<value if condition is false>)` can be appended at the end.
    If not appended, and the condition is not `True`, `None` will be returned.

    Arguments:
        predicates: Condition(s) that must be met in order to apply the subsequent
            statement. Accepts one or more boolean expressions, which are implicitly
            combined with `&`. String input is parsed as a column name.

    Returns:
        A "When" object, which `.then` can be called on.
    )r  r  nw_fr  )r  s    r   r  r    s    " >>$))Z011r   c               2    t        t        | |||            S )a  Instantiate Narwhals Series from iterable (e.g. list or array).

    Arguments:
        name: Name of resulting Series.
        values: Values of make Series from.
        dtype: (Narwhals) dtype. If not provided, the native library
            may auto-infer it from `values`.
        backend: specifies which eager backend instantiate to.

            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
    r   )r   r?   )r   r   r   r   s       r   
new_seriesr    s    . &tVUGLMMr   c               B    t        t        j                  | |            S )aL  Construct a DataFrame from an object which supports the PyCapsule Interface.

    Arguments:
        native_frame: Object which implements `__arrow_c_stream__`.
        backend: specifies which eager backend instantiate to.

            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
    r   )r   r  r   )r   r   s     r   r   r     s      doolGDEEr   r   c               D    t        t        j                  | ||            S )a  Instantiate DataFrame from dictionary.

    Indexes (if present, for pandas-like backends) are aligned following
    the [left-hand-rule](../concepts/pandas_index.md/).

    Notes:
        For pandas-like dataframes, conversion to schema is applied after dataframe
        creation.

    Arguments:
        data: Dictionary to create DataFrame from.
        schema: The DataFrame schema as Schema, dict of {name: type}, or a
            iterable of (name, type) tuples.
            If not specified, the schema will be inferred by the native library.
            If any `dtype` is `None`, the data type for that column will be
            inferred by the native library.
        backend: specifies which eager backend instantiate to. Only
            necessary if inputs are not Narwhals Series.

            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
    r   )r   r  r   r   r   r   s      r   r   r     s    @ dnnT67CDDr   r   r   c               D    t        t        j                  | ||            S )a^  Construct a DataFrame from a NumPy ndarray.

    Notes:
        Only row orientation is currently supported.

        For pandas-like dataframes, conversion to schema is applied after dataframe
        creation.

    Arguments:
        data: Two-dimensional data represented as a NumPy ndarray.
        schema: The DataFrame schema as Schema, dict of {name: type}, an iterable
            of (name, type) tuples, or a sequence of str.
        backend: specifies which eager backend instantiate to.

            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
    r   )r   r  r   r  s      r   r   r     s    6 doodFGDEEr   ,)r  c               F    t        t        j                  | f||d|      S )a  Read a CSV file into a DataFrame.

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
        separator: Single byte character to use as separator in the file.
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.read_csv('file.csv', backend='pandas', engine='pyarrow')`.
    r   r  )r   r  read_csvsourcer   r  r   s       r   r  r    s)    . fMgMfM r   c               F    t        t        j                  | f||d|      S )a  Lazily read from a CSV file.

    For the libraries that do not support lazy dataframes, the function reads
    a csv file eagerly and then converts the resulting dataframe to a lazyframe.

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
        separator: Single byte character to use as separator in the file.
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.scan_csv('file.csv', backend=pd, engine='pyarrow')`.
    r  )r   r  scan_csvr  s       r   r  r  *  s)    , fMgMfM r   c               D    t        t        j                  | fd|i|      S )a  Read into a DataFrame from a parquet file.

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN` or `CUDF`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.read_parquet('file.parquet', backend=pd, engine='pyarrow')`.
    r   )r   r  read_parquetr  r   r   s      r   r  r  E  s$    $ d''JJ6JKKr   c               D    t        t        j                  | fd|i|      S )a  Lazily read from a parquet file.

    For the libraries that do not support lazy dataframes, the function reads
    a parquet file eagerly and then converts the resulting dataframe to a lazyframe.

    Note:
        Spark like backends require a session object to be passed in `kwargs`.

        For instance:

        ```py
        import narwhals as nw
        from sqlframe.duckdb import DuckDBSession

        nw.scan_parquet(source, backend="sqlframe", session=DuckDBSession())
        ```

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `backend` can be specified in various ways

            - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                `POLARS`, `MODIN`, `CUDF`, `PYSPARK` or `SQLFRAME`.
            - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"`, `"cudf"`,
                `"pyspark"` or `"sqlframe"`.
            - Directly as a module `pandas`, `pyarrow`, `polars`, `modin`, `cudf`,
                `pyspark.sql` or `sqlframe`.
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.scan_parquet('file.parquet', backend=pd, engine='pyarrow')`.
    r   )r   r  scan_parquetr  s      r   r  r  Z  s%    F d''JJ6JKKr   c                 >    t        t        j                  | i |      S )a  Collect columns into a struct column.

    Arguments:
        *exprs: Column(s) to collect into a struct column, specified as
            positional arguments. Accepts only expression input. Strings are parsed
            as column names, other non-expression inputs are not allowed.
        **named_exprs: Additional columns to collect into the struct column,
            specified as keyword arguments. The columns will be renamed to the
            keyword used.
    )r   r  struct)rr  named_exprss     r   r  r    s     dkk58K899r   )Xr    r!   r"   r#   r   r$   r%   r&   r'   r(   r>   r)   r*   r+   r,   r   r-   r.   r/   r0   r1   r   r2   r3   rB   rC   r4   r5   r6   r7   r8   r9   r:   r;   r<   rS  ru  ry  r  rV  r@   r  r  r  rD   rE   rE   r   rZ  r  r   r   r   r  r   r   rP   r   r_  ra  rh  r  r   r   r   r   r   rj  r{  rl  rc  r}  rQ  r  r\  r  r  r  r  rF   rF   rA   r  rn  rp  r5  rQ   r  )r  zNwDataFrame[IntoDataFrameT]r   DataFrame[IntoDataFrameT])r  zNwLazyFrame[IntoLazyFrameT]r   LazyFrame[IntoLazyFrameT])r  zNwSeries[IntoSeriesT]r   Series[IntoSeriesT])r  r  r   r>   )r  zZNwDataFrame[IntoDataFrameT] | NwLazyFrame[IntoLazyFrameT] | NwSeries[IntoSeriesT] | NwExprr   zRDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT] | Expr)r  rN   r  Unpack[OnlySeries]r   rN   )r  rN   r  Unpack[AllowSeries]r   rN   )r  rG   r  Unpack[ExcludeSeries]r   rG   )r  rM   r  Unpack[AllowLazy]r   rM   )r  rH   r  r  r   r  )r  rL   r  r  r   r  )r  rL   r  r  r   r  )r  rJ   r  r  r   r  )r  zIntoDataFrameT | IntoSeriesTr  r  r   z/DataFrame[IntoDataFrameT] | Series[IntoSeriesT])r  z-IntoDataFrameT | IntoLazyFrameT | IntoSeriesTr  zUnpack[AllowAny]r   KDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT])r  rr   r  zUnpack[PassThroughUnknown]r   rr   )r  r   r)  r   r*  r   r+  r   r,  bool | Noner   r   )r  zJIntoLazyFrameT | IntoDataFrameT | IntoSeriesT | IntoFrame | IntoSeries | Tr)  r   r*  r   r+  r   r,  r  r   zOLazyFrame[IntoLazyFrameT] | DataFrame[IntoDataFrameT] | Series[IntoSeriesT] | T)r4  r  r)  r   r   rH   )r4  r  r)  r   r   rJ   )r4  r  r)  r   r   rL   )r4  r   r)  r   r   r   )r4  r  r)  r   r   z3IntoDataFrameT | IntoLazyFrameT | IntoSeriesT | Anyr   )rM  zCallable[..., Any] | Noner)  r   r*  r   r+  r   r,  r  r   rP  )r   r>   )rX  zstr | Iterable[str]r   r>   )r]  zint | Sequence[int]r   r>   )rH  rl   r   r   r   r>   )re  r   r   r>   )rr  r  r   r>   )rr  r  r   r   r   r>   )pearson)r  rj   rK  rj   r  zLiteral['pearson', 'spearman']r   r>   )r  rj   rK  rj   r  intr   r>   )
rr  r  r  rj   r  r   r   r   r   r>   )r  r   rE  rj   r   r>   )rr  r  r  rj   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   IntoBackend[Backend]r  r   r   r   r   r   )r  r   r   r   r   r   r   r   )r  r   r   r  r   r   r   r   )rr  zIntoExpr | Sequence[IntoExpr]r  rj   r   r>   )
__future__r   	functoolsr   typingr   r   r   r	   r
   r   narwhalsr;  r   r   r  narwhals._exceptionsr   narwhals._expression_parsingr   r   narwhals._typing_compatr   r   narwhals._utilsr   r   r   r   r   r   r   r   r   r   r   narwhals.dataframer   r   r   r   narwhals.dtypesr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   narwhals.exceptionsr=   narwhals.exprr>   r  narwhals.functionsr?   r@   rA   narwhals.schemarB   NwSchemanarwhals.seriesrC   r   narwhals.stable.v2rD   rE   rF   narwhals.stable.v2.typingrG   rH   rI   rJ   rK   rL   rM   rN   narwhals.translaterO   rP   rQ   collections.abcrR   rS   rT   rU   typing_extensionsrV   rW   rX   narwhals._translaterY   rZ   r[   r\   r]   r^   r_   narwhals._typingr`   ra   rb   rc   rd   re   rf   rg   rh   narwhals.typingri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rt   ru   r   r  r5  rQ  rS  rV  rZ  r\  r_  ra  rc  rh  rj  rl  rn  rp  ru  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r   r  r  r  r  r  __all__r   r   r   <module>r     s   "  E E  2 . ; 9    R       > 8 ( F F . . > >	 	 	 U TEE99     H
 
 
 	S!A#AA}/N+ }/@FN+ F$C<Xk" C<LS6 S(X  
 R 
 R	 R 
 R	 F 
 F	 ( 
 (

 X" 
 S 
 S	 T 
 T	'< 
 
 X 
 X	$!$+@$$ 
$ 
(: 
 
(; 
 
$!$+<$$ 
$ 
:/:9L:4: 
: 
V@VJZVPV 
V 
 O 
 O	  	
   	 
   $99 9 9 9 9 U9x 
RU.AO 
 
RU.AO 
 
LO(;I 
 
 F 
 F DD
 D 9D. '+U  $U
#U U 	U
 U U Up 
&*
( 

,	(	(	)+	(
1L L 2
1
1 HQ
4
4
4&D
4	
4 23 	/ 	(  	
 
027 +499 +>499d >2. #N
NN N
 'N N4F F.GFF* BF E 15	 E
 E> E .	 E
  EF ((
E (
 15F
F-F '	F
 FD 	 ' 	
  : EH1>ASV6LL6LBELL*#L#L1#L=@#L#LL:Yr   