
    }i                    P   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
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/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rd dlgmhZhmiZimjZj d dlkmlZlmmZmmnZn d dlompZpmqZqmrZrmsZsmtZtmuZumvZv d dlwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~ d dl%mZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZ  ede          Z eld          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dd-            Zedd0            Zedd3            Zedd5            Zdd8Zedd=            Zedd?            ZeddB            ZeddE            ZeddG            ZeddI            ZeddJ            ZeddL            ZeddO            ZeddS            ZeddU            Zedd]            Zd^d^d^dd_ddbZedcddddg            Zedcddddh            Zedcddddi            Zeddj            Zd^ddddlZ	 ddmd^d^dmd_ddqZddrZdduZddvZddyZddzZdddZddZddZddZddZddZddZddZddZddZddZddZ	 dddZdd^dddZddZddZ G d dej                  Z G d dej        eJ          ZddZ	 dddZddZ	 dddddZe&j        Zded<   	 dddZddddZddddÄZddĄZddńZddȄZg dɢZdS )    )annotationswraps)TYPE_CHECKINGAnyCallable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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)IterableMappingSequence)	ParamSpecSelfUnpack)AllowAny	AllowLazyAllowSeriesExcludeSeriesIntoArrowTable
OnlySeriesPassThroughUnknown)ArrowBackendEagerAllowedIntoBackendLazyAllowedPandasPolars)MultiColSelectorMultiIndexSelector)DType)		IntoDTypeIntoExpr
IntoSchemaNonNestedLiteralPythonLiteralSingleColSelectorSingleIndexSelector_1DArray_2DArrayT)defaultPRc                      e Zd Zej        Z ee          dD fd            Ze	dE fd            Z
e		 dFdddG fd            Ze		 dFdH fd            Ze		 dFdI fd            ZedJd            ZedKd            ZedLd!            ZedMd$            ZedNd'            ZdO fd*ZdP fd-Z	 dFdd.dQ fd3Zed4d5dRd9            ZedSd<            Zed=d5dTd@            Zd=d5dT fdAZdU fdBZdU fdCZ xZS )Vr   dfr   level&Literal['full', 'lazy', 'interchange']returnNonec               x    |j         t          j        u sJ t                                          ||           d S N)rx   _versionr   V2super__init__selfrw   rx   	__class__s      O/home/jrussi/.local/lib/python3.11/site-packages/narwhals/stable/v2/__init__.pyr   zDataFrame.__init__v   ;    {gj((((5)))))    native_framer\   backendIntoBackend[EagerAllowed]DataFrame[Any]c               j    t                                          ||          }t          d|          S Nr   r   )r   
from_arrowr   )clsr   r   resultr   s       r   r   zDataFrame.from_arrow~   s2     ##L'#BB$f---r   Nr   dataMapping[str, Any]schema.IntoSchema | Mapping[str, DType | None] | None IntoBackend[EagerAllowed] | Nonec               l    t                                          |||          }t          d|          S r   )r   	from_dictr   r   r   r   r   r   r   s        r   r   zDataFrame.from_dict   s4     ""4"AA$f---r   Sequence[Mapping[str, Any]]c               l    t                                          |||          }t          d|          S r   )r   
from_dictsr   r   s        r   r   zDataFrame.from_dicts   4     ##D&'#BB$f---r   rq   3Mapping[str, DType] | Schema | Sequence[str] | Nonec               l    t                                          |||          }t          d|          S r   r   
from_numpyr   r   s        r   r   zDataFrame.from_numpy   r   r   type[Series[Any]]c                ,    t          dt                    S )Nr   )r   rC   r   s    r   _serieszDataFrame._series   s    '000r   type[LazyFrame[Any]]c                ,    t          dt                    S )Nr   )r   r    r   s    r   
_lazyframezDataFrame._lazyframe   s    *I666r   item-tuple[SingleIndexSelector, SingleColSelector]c                    d S N r   r   s     r   __getitem__zDataFrame.__getitem__   s    WZWZr   2str | tuple[MultiIndexSelector, SingleColSelector]Series[Any]c                    d S r   r   r   s     r   r   zDataFrame.__getitem__   s	     cr   SingleIndexSelector | MultiIndexSelector | MultiColSelector | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, MultiColSelector]rV   c                    d S r   r   r   s     r   r   zDataFrame.__getitem__   s	     sr     SingleIndexSelector | SingleColSelector | MultiColSelector | MultiIndexSelector | tuple[SingleIndexSelector, SingleColSelector] | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, SingleColSelector] | tuple[MultiIndexSelector, MultiColSelector]Series[Any] | Self | Anyc                F    t                                          |          S r   )r   r   )r   r   r   s     r   r   zDataFrame.__getitem__   s     ww""4(((r   namestrc                F    t                                          |          S r   )r   
get_column)r   r   r   s     r   r   zDataFrame.get_column   s     ww!!$'''r   )sessionIntoBackend[LazyAllowed] | Noner   
Any | NoneLazyFrame[Any]c               d    t          t                                          ||                    S )N)r   r   )
_stableifyr   lazy)r   r   r   r   s      r   r   zDataFrame.lazy   s'     %'',,w,HHIIIr   .	as_seriesr   Literal[True]dict[str, Series[Any]]c                   d S r   r   r   r   s     r   to_dictzDataFrame.to_dict   s    TWTWr   Literal[False]dict[str, list[Any]]c                   d S r   r   r   s     r   r   zDataFrame.to_dict   s    MPSr   Tbool-dict[str, Series[Any]] | dict[str, list[Any]]c                   d S r   r   r   s     r   r   zDataFrame.to_dict   s	     9<r   c               H    t                                          |          S )Nr   )r   r   )r   r   r   s     r   r   zDataFrame.to_dict   s    
 ww333r   c                ^    t          t                                                                S r   )r   r   is_duplicatedr   r   s    r   r   zDataFrame.is_duplicated   s!    %''//11222r   c                ^    t          t                                                                S r   )r   r   	is_uniquer   s    r   r   zDataFrame.is_unique   s!    %''++--...r   rw   r   rx   ry   rz   r{   r   r\   r   r   rz   r   r   )r   r   r   r   r   r   rz   r   )r   r   r   r   r   r   rz   r   r   rq   r   r   r   r   rz   r   )rz   r   )rz   r   )r   r   rz   r   )r   r   rz   r   )r   r   rz   rV   )r   r   rz   r   )r   r   rz   r   )r   r   r   r   rz   r   )r   r   rz   r   )r   r   rz   r   )r   r   rz   r   )rz   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       zH[* * * * * * . . . . . [.  BF.
 59. . . . . . . [.  BF. . . . . . [.  GK. . . . . . [. 1 1 1 X1 7 7 7 X7 ZZZ XZ   X 	 	 	 X	) ) ) ) ) )( ( ( ( ( ( 48J #	J J J J J J J J 47WWWWW XWPPP XP#'< < < < < X< $(4 4 4 4 4 4 4 43 3 3 3 3 3/ / / / / / / / / /r   r   c                  x     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    rw   r   rx   ry   rz   r{   c               x    |j         t          j        u sJ t                                          ||           d S r}   r~   r   s      r   r   zLazyFrame.__init__   r   r   type[DataFrame[Any]]c                    t           S r   r   r   s    r   
_dataframezLazyFrame._dataframe       r   Nr   +IntoBackend[Polars | Pandas | Arrow] | Nonekwargsr   c                T    t           t                      j        dd|i|          S )Nr   r   )r   r   collect)r   r   r   r   s      r   r   zLazyFrame.collect   s.     /%''/DD'DVDDEEEr   r   rz   r   r   )r   r   r   r   rz   r   )r   r   r   r   r   r   r   NwLazyFramer   r   r   r   r   r   s   @r   r    r       s        zH[* * * * * *    X FJF F F F F F F F 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   seriesr   rx   ry   rz   r{   c               x    |j         t          j        u sJ t                                          ||           d S r}   r~   )r   r   rx   r   s      r   r   zSeries.__init__  s=     '*,,,,u-----r   r   c                    t           S r   r   r   s    r   r   zSeries._dataframe  r   r   Nr   r   valuesrp   dtypeIntoDType | Noner   r   r   c               n    t                                          ||||          }t          d|          S Nr   r   r   r   r   r   r   r   r   r   s         r   r   zSeries.from_numpy  s5     ##D&%#IIM6***r   Iterable[Any]c               n    t                                          ||||          }t          d|          S r   )r   from_iterabler   r   s         r   r   zSeries.from_iterable"  s5     &&tVUG&LLM6***r   r   c                ^    t          t                                                                S r   )r   r   to_framer   s    r   r   zSeries.to_frame.  s!    %''**,,---r   Fsortparallelr   	normalizer   r   r   
str | Noner  c               h    t          t                                          ||||                    S )Nr   )r   r   value_counts)r   r   r   r   r  r   s        r   r  zSeries.value_counts1  s<     GG  H49 !  
 
 	
r   histignore_nullsr  rm   c               v    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33ww  l ;;;r   )r   r   rx   ry   rz   r{   r   r   )
r   r   r   rp   r   r   r   r   rz   r   )
r   r   r   r   r   r   r   r   rz   r   )rz   r   )
r   r   r   r   r   r  r  r   rz   r   )r  r   rz   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     s}        zH[. . . . . .    X 
 #'		+ 	+ 	+ 	+ 	+ 	+ [	+ 
 #'		+ 	+ 	+ 	+ 	+ 	+ [	+. . . . . . 
 
 
 
 
 
 
 
  !!D!!!!05 < < < < < < < < < < < <r   rC   c                  ,    e Zd ZddddZddZdd	Zd
S )r>   Fr  r  r   rz   rV   c                   d}t          |t                     |                     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  sL    # 	 	c2333  X);\RRR
 
 	
r   c                \    |                      t          t          j        d                    S )zGet the first value.firstr  r   r   ORDERABLE_AGGREGATIONr   s    r   r  z
Expr.firstV  s#      (*H'!R!RSSSr   c                \    |                      t          t          j        d                    S )zGet the last value.lastr  r   s    r   r  z	Expr.lastZ  s#      (*H&!Q!QRRRr   N)r  r   rz   rV   )rz   rV   )r   r   r   r	  r  r  r   r   r   r>   r>   K  sg        05 
 
 
 
 
 
T T T TS S S S S Sr   r>   c                  T     e Zd Zej        Z ee          	 dd fd            Z xZ	S )	rB   Nr   8Mapping[str, DType] | Iterable[tuple[str, DType]] | Nonerz   r{   c                J    t                                          |           d S r   )r   r   )r   r   r   s     r   r   zSchema.__init__b  s#     	     r   r   )r   r  rz   r{   )
r   r   r   r   r   r   r   NwSchemar   r   r   s   @r   rB   rB   _  sa        zH[QU! ! ! ! ! ! ! ! ! ! !r   rB   objNwDataFrame[IntoDataFrameT]rz   DataFrame[IntoDataFrameT]c                    d S r   r   r  s    r   r   r   i      ORsr   NwLazyFrame[IntoLazyFrameT]LazyFrame[IntoLazyFrameT]c                    d S r   r   r  s    r   r   r   k  r   r   NwSeries[IntoSeriesT]Series[IntoSeriesT]c                    d S r   r   r  s    r   r   r   m      CF3r   NwExprc                    d S r   r   r  s    r   r   r   o  s    %(Sr   ZNwDataFrame[IntoDataFrameT] | NwLazyFrame[IntoLazyFrameT] | NwSeries[IntoSeriesT] | NwExprRDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT] | Exprc                8   t          | t                    r8t          | j                            t
          j                  | j                  S t          | t                    r8t          | j                            t
          j                  | j                  S t          | t                    r8t          | j                            t
          j                  | j                  S t          | t                    rt          | j         S t!          |            d S r}   )
isinstancer   r   _compliant_frame_with_versionr   r   _levelr   r    r  rC   _compliant_seriesr(  r>   _nodesr   r  s    r   r   r   s  s     #{## [-;;GJGGszZZZZ#{## [-;;GJGGszZZZZ#x   Yc+99'*EESZXXXX#v !SZ  r   native_objectrN   kwdsUnpack[OnlySeries]c                    d S r   r   r3  r4  s     r   from_nativer8    s    PSPSr   Unpack[AllowSeries]c                    d S r   r   r7  s     r   r8  r8    s    QTQTr   rG   Unpack[ExcludeSeries]c                    d S r   r   r7  s     r   r8  r8    s	     r   rM   Unpack[AllowLazy]c                    d S r   r   r7  s     r   r8  r8    s    UXUXr   rH   c                    d S r   r   r7  s     r   r8  r8    	     !$r   rL   c                    d S r   r   r7  s     r   r8  r8    	     #r   c                    d S r   r   r7  s     r   r8  r8    rB  r   rJ   c                    d S r   r   r7  s     r   r8  r8    r@  r   IntoDataFrameT | IntoSeriesT/DataFrame[IntoDataFrameT] | Series[IntoSeriesT]c                    d S r   r   r7  s     r   r8  r8    s	     7:cr   -IntoDataFrameT | IntoLazyFrameT | IntoSeriesTUnpack[AllowAny]KDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT]c                    d S r   r   r7  s     r   r8  r8    s     SVRUr   Unpack[PassThroughUnknown]c                    d S r   r   r7  s     r   r8  r8    s    LOCr   r   pass_throughr   
eager_onlyseries_onlyallow_seriesbool | Nonec                   d S r   r   r3  rN  rO  rP  rQ  s        r   r8  r8    s	     #r   FrN  rO  rP  rQ  JIntoLazyFrameT | IntoDataFrameT | IntoSeriesT | IntoFrame | IntoSeries | TOLazyFrame[IntoLazyFrameT] | DataFrame[IntoDataFrameT] | Series[IntoSeriesT] | Tc          	         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)rN  rO  rP  rQ  eager_or_interchange_onlyversion)r-  r   r    rC   rO   r   r   rT  s        r   r8  r8    s}    X -)Y!788  -(( k \ !!"'
   r   .rN  narwhals_objectr   c                   d S r   r   r\  rN  s     r   	to_nativer_    	     Sr   c                   d S r   r   r^  s     r   r_  r_    r`  r   c                   d S r   r   r^  s     r   r_  r_    s	     #r   c                   d S r   r   r^  s     r   r_  r_    r'  r   3IntoDataFrameT | IntoLazyFrameT | IntoSeriesT | Anyc               .    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.
    r[  )nwr_  r^  s     r   r_  r_    s    & <lCCCCr   TfuncCallable[..., Any] | NoneCallable[..., Any]c               :    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.
    rg  ri  rz   c                H     t                     d fd            }|S )Nargsr   r   rz   c                 <   	fd| D             }	fd|                                 D             }fdg ||                                R D             }|                                dk    rd}t          |           
|i |}t	          |          S )Nc           	     8    g | ]}t          |           S rU  r8  ).0argrQ  rO  rN  rP  s     r   
<listcomp>zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>A  sI     	 	 	  !-) +!-  	 	 	r   c           
     @    i | ]\  }}|t          |           S ro  rp  )rq  r   valuerQ  rO  rN  rP  s      r   
<dictcomp>zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<dictcomp>L  sO     	 	 	  D% k!-) +!-  	 	 	r   c                J    h | ]}t          |d d          x              S )__native_namespace__N)getattr)rq  vbs     r   	<setcomp>zAnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<setcomp>W  sG        $:DAAAA  r      z_Found multiple backends. Make sure that all dataframe/series inputs come from the same backend.r[  )itemsr   __len__
ValueErrorr_  )rl  r   args_nw	kwargs_nwbackendsr
  r   r{  rQ  rO  rg  rN  rP  s          @r   wrapperz.narwhalify.<locals>.decorator.<locals>.wrapper?  s   	 	 	 	 	 	 	  	 	 	G	 	 	 	 	 	 	 $*<<>>	 	 	I   878Y%5%5%7%788  H !!A%%w oo%T70i00FV,????r   )rl  r   r   r   rz   r   r   )rg  r  rQ  rO  rN  rP  s   ` r   	decoratorznarwhalify.<locals>.decorator>  sX    	t#	@ #	@ #	@ #	@ #	@ #	@ #	@ #	@ #	@ 
#	@J r   N)rg  ri  rz   ri  r   )rg  rN  rO  rP  rQ  r  s    ```` r   
narwhalifyr    sP    R' ' ' ' ' ' ' ' 'R |9T??r   c                 B    t          t          j                              S )z3Instantiate an expression representing all columns.)r   rf  allr   r   r   r  r  m      bfhhr   namesstr | Iterable[str]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   rf  colr  s    r   r  r  r  s     bfen%%%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   rf  excluder  s    r   r  r  {  s     bj%()))r   indicesint | Sequence[int]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   rf  nth)r  s    r   r  r    s     bfg&'''r   c                 B    t          t          j                              S )zReturn the number of rows.)r   rf  lenr   r   r   r  r    r  r   ru  rl   r   r   c                F    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   rf  lit)ru  r   s     r   r  r    s     bfUE**+++r   columnsr   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   rf  minr  s    r   r  r         bfg&'''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   rf  maxr  s    r   r  r    r  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   rf  meanr  s    r   r  r    s     bgw'(((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   rf  medianr  s    r   r  r    s     bi)***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   rf  sumr  s    r   r  r    r  r   exprsIntoExpr | Iterable[IntoExpr]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   rf  sum_horizontalr  s    r   r  r         b'/000r   r  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   rf  all_horizontalr  r  s     r   r  r    "     b'J\JJK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   rf  any_horizontalr  s     r   r  r    r  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   rf  mean_horizontalr  s    r   r  r    s     b(%01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   rf  min_horizontalr  s    r   r  r    r  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   rf  max_horizontalr  s    r   r  r  %  r  r   pearsonarj   r{  methodLiteral['pearson', 'spearman']c                J    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')
    )r  )r   rf  corr)r  r{  r  s      r   r  r  2  s#     bga6222333r    	separatorr  
more_exprsr  c               H    t          t          j        | g|R ||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   rf  
concat_str)r  r  r  r  s       r   r  r  ?  s5    & 
eYjYYILYYY  r   f_stringrl  c                @    t          t          j        | g|R            S )zFormat expressions as a string.

    Arguments:
        f_string: A string that with placeholders.
        args: Expression(s) that fill the placeholders.
    )r   rf  format)r  rl  s     r   r  r  W  s$     bi04000111r   c                @    t          t          j        | g|R            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   rf  coalesce)r  r  s     r   r  r  a  s$     bk%5*555666r   c                  .    e Zd Zed
d            ZddZd	S )Whenwhen	nw_f.Whenrz   c                &     | |j         d          S )Nr   )chain)
_predicate)r   r  s     r   	from_whenzWhen.from_whenr  s    s4?"----r   ru  &IntoExpr | NonNestedLiteral | _1DArrayThenc                \    g | j         | j        |fR }t                              |          S r   )_chainr  r  _from_chain)r   ru  	new_chains      r   thenz	When.thenv  s1    <dk<DOU#;<<		***r   N)r  r  rz   r  )ru  r  rz   r  )r   r   r   r   r  r  r   r   r   r  r  q  sF        . . . [.+ + + + + +r   r  c                      e Zd ZdS )r  N)r   r   r   r   r   r   r  r  {  s          r   r  
predicatesc                 N    t                               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11r   r   r   r   r   r   c               B    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LLMMMr   r   r\   r   c               H    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!      dolGDDDEEEr   r   r   r   r   #Mapping[str, DType] | Schema | Noner   c               J    t          t          j        | ||                    S )aX  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 or dict of {name: type}. 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#    > dnT67CCCDDDr   r	   r   rq   r   c               J    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}, 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#    4 dodFGDDDEEEr   ,)r  sourcer   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r  r   r  r   s       r   r  r    s2    . fMgMMfMM  r   IntoBackend[Backend]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    s2    , fMgMMfM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  8  s*    $ d'JJJ6JJK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  M  s+    F d'JJJ6JJKKKr   IntoExpr | Sequence[IntoExpr]named_exprsc                 >    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)r  r  s     r   r  r  s  s!     dk58K88999r   )Vr!   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<   r  r  r  r  r  r@   r  r  rD   rE   rE   r   r  r  r   r   r   r8  r   r   rP   r   r  r  r  r  r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  rF   rF   rA   r  r  r  r_  rQ   r  )r  r  rz   r  )r  r!  rz   r"  )r  r$  rz   r%  )r  r(  rz   r>   )r  r*  rz   r+  )r3  rN   r4  r5  rz   rN   )r3  rN   r4  r9  rz   rN   )r3  rG   r4  r;  rz   rG   )r3  rM   r4  r=  rz   rM   )r3  rH   r4  r;  rz   r  )r3  rL   r4  r5  rz   r%  )r3  rL   r4  r9  rz   r%  )r3  rJ   r4  r=  rz   r"  )r3  rE  r4  r9  rz   rF  )r3  rH  r4  rI  rz   rJ  )r3  rr   r4  rL  rz   rr   )r3  r   rN  r   rO  r   rP  r   rQ  rR  rz   r   )r3  rV  rN  r   rO  r   rP  r   rQ  rR  rz   rW  )r\  r  rN  r   rz   rH   )r\  r"  rN  r   rz   rJ   )r\  r%  rN  r   rz   rL   )r\  r   rN  r   rz   r   )r\  rJ  rN  r   rz   rd  r   )rg  rh  rN  r   rO  r   rP  r   rQ  rR  rz   ri  )rz   r>   )r  r  rz   r>   )r  r  rz   r>   )ru  rl   r   r   rz   r>   )r  r   rz   r>   )r  r  rz   r>   )r  r  r  r   rz   r>   )r  )r  rj   r{  rj   r  r  rz   r>   )
r  r  r  rj   r  r   r  r   rz   r>   )r  r   rl  rj   rz   r>   )r  r  r  rj   rz   r>   )r  r  rz   r  )
r   r   r   r   r   r   r   r   rz   r   r   )r   r   r   r  r   r   rz   r   r   )
r  r   r   r   r  r   r   r   rz   r   )
r  r   r   r  r  r   r   r   rz   r   )r  r   r   r   r   r   rz   r   )r  r   r   r  r   r   rz   r   )r  r  r  rj   rz   r>   )
__future__r   	functoolsr   typingr   r   r   r	   r
   r   r   narwhalsrf  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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   narwhals.exceptionsr=   narwhals.exprr>   r(  narwhals.functionsr?   r@   rA   narwhals.schemarB   r  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   typing_extensionsrU   rV   rW   narwhals._translaterX   rY   rZ   r[   r\   r]   r^   narwhals._typingr_   r`   ra   rb   rc   rd   re   rf   rg   narwhals.stable.v2.dtypesrh   narwhals.typingri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rt   ru   r   r8  r_  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r   r  r  r  r  r  __all__r   r   r   <module>r     s   " " " " " " "       O O O O O O O O O O O O O O O O O O     2 2 2 2 2 2 2 2 . . . . . . ; ; ; ; ; ; ; ; 9 9 9 9 9 9 9 9                          R Q Q Q Q Q Q Q                                                           < 8 7 7 7 7 7 ( ( ( ( ( ( F F F F F F F F F F . . . . . . . . . . . . > > > > > > > > > >	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 U T T T T T T T T T ';;;;;;;;;;9999999999                                   HGGGGGGG//////
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 	S!!!A	#AA}/ }/ }/ }/ }/N+ }/ }/ }/@F F F F FN+ F F F$C< C< C< C< C<Xk" C< C< C<LS S S S S6 S S S(! ! ! ! !X ! ! ! 
 R R R 
 R	 R R R 
 R	 F F F 
 F	 ( ( ( 
 (   " 
 S S S 
 S	 T T T 
 T	   
 
 X X X 
 X	$ $ $ 
$ 
   
 
   
 
$ $ $ 
$ 
: : : 
: 
V V V 
V 
 O O O 
 O	   
   $9 9 9 9 9 9x 
RU     
 
RU     
 
LO     
 
 F F F 
 F D D D D D D. '+U  $U U U U U Up       
& & & &* * * *
( 
( 
( 
(       

, 
, 
, 
, 
,	( 	( 	( 	(	( 	( 	( 	(	) 	) 	) 	)+ + + +	( 	( 	( 	(
1 
1 
1 
1L L L L L L L L 2 2 2 2
1 
1 
1 
1
1 
1 
1 
1 HQ
4 
4 
4 
4 
4  	     02 2 2 27 7 7 7 + + + + +49 + + + !        49d      2 2 2 2. #N N N N N4F F F F* 37E 15	E E E E E ED (
 ( ( ( (
 CGF F F F FB 	     : EH     6L L L L*#L #L #L #LL: : : :W W Wr   