
    [i                    8   d dl mZ d dlZd dlmZmZmZmZm	Z	 d dl
mZ d dlmZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZmZmZ d d
lmZ er0d dl m!Z! d dl"m#Z# d dlmZmZ d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+m,Z,m-Z-  G d deeef   e	eef         Z.y)    )annotationsN)TYPE_CHECKINGAnyCallableLiteralProtocol)LazyExpr)
AliasNames	EvalNames
EvalSeriesNativeExprTWindowFunction)WindowInputs)combine_alias_output_namescombine_evaluate_output_names)SQLLazyFrameT)ImplementationVersionextend_boolnot_implemented)InvalidOperationError)Sequence)Self)r
   r   )SQLExprDateTimeNamesSpace)SQLExprStringNamespace)SQLNamespace)ModeKeepStrategyPythonLiteral
RankMethodc                     e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   	 dmej
                  d	 	 	 	 	 	 	 	 	 	 	 	 	 dndZdodZ	 	 dpdZ	 	 	 	 	 	 dqdZ		 	 	 	 	 	 drdZ
	 	 	 	 dsdZ	 dm	 	 	 	 	 	 	 dtdZ	 	 	 	 	 	 dudZdvdZdwdZedxd       ZdydZdzdZd{dZd|dZd}dZd}dZd~d Z	 dm	 	 	 	 	 	 	 dd!Z	 	 	 	 dddd"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd#Z	 	 	 	 	 	 dd$Z	 dm	 	 	 	 	 	 	 	 	 	 	 dd%Zedd&       Zedd'       Ze	 	 	 	 	 	 dd(       Z dd)Z!dd*Z"dd+Z#dd,Z$dd-Z%dd.Z&dd/Z'dd0Z(dd1Z)dd2Z*dd3Z+dd4Z,dd5Z-dd6Z.dd7Z/dd8Z0dd9Z1dd:Z2dd;Z3dd<Z4dd=Z5dd>Z6dd?Z7dd@Z8ddAZ9ddBZ:ddCZ;ddDZ<ddEZ=ddFZ>ddGZ?ddHZ@ddIZAddJZBddKZCddLZDddMZEddNZFddOZGddPZHddQZIddRZJddSZKddTZLddUZMddVZNddWZOddXZPddYZQddZZRdd[ZSdd\ZTdd]ZU	 	 	 	 	 	 	 	 	 	 dd^ZV	 	 	 	 	 	 	 	 	 	 dd_ZWdd`ZXddaZYddbZZddcZ[ddddZ\dddeZ]ddfZ^ddgZ_ddhZ`	 	 	 	 	 	 ddiZaddjZbeddk       Zceddl       Zd ee       Zf ee       Zg ee       Zhy)SQLExpr&EvalSeries[SQLLazyFrameT, NativeExprT]_callEvalNames[SQLLazyFrameT]_evaluate_output_namesAliasNames | None_alias_output_namesr   _versionr   _implementation1WindowFunction[SQLLazyFrameT, NativeExprT] | None_window_functionN)implementationc                    y N )selfcallwindow_functionevaluate_output_namesalias_output_namesversionr,   s          c/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/narwhals/_sql/expr.py__init__zSQLExpr.__init__+   s         c                $    | j                  |      S r.   )r#   )r0   dfs     r6   __call__zSQLExpr.__call__6   s    zz"~r8   c                     y r.   r/   r0   s    r6   __narwhals_namespace__zSQLExpr.__narwhals_namespace__9   s    >Ar8   c                    d fd}|S )Nc                     |       }j                         D ci c]  \  }}|| j                  |       }}}|D cg c]  } |fi | c}S c c}}w c c}w r.   )items_evaluate_single_output_expr)	r:   native_series_listkeyvalueother_native_seriesnative_seriesr1   expressifiable_argsr0   s	         r6   funcz.SQLExpr._callable_to_eval_series.<locals>.func@   s    !%b #6";";"=#"=JC R44U;;"=   # &8%7M ]:&9:%7 	#s   A A)r:   r   returnzlist[NativeExprT]r/   )r0   r1   rH   rI   s   ``` r6   _callable_to_eval_seriesz SQLExpr._callable_to_eval_series=   s    		 r8   c               (     	 	 	 	 	 	 d fd}|S )Nc           	         	j                  | |      }j                         D ci c]  \  }}|| j                  ||       }}}|D cg c]  } |fi | c}S c c}}w c c}w r.   )r2   rA   _evaluate_window_expr)
r:   window_inputsrC   rD   rE   rF   rG   r1   rH   r0   s
          r6   window_fz4SQLExpr._push_down_window_function.<locals>.window_fP   s     "&!5!5b-!H #6";";"=#"=JC R--e]CC"=   # &8%7M ]:&9:%7 	#s   AA$r:   r   rO   WindowInputs[NativeExprT]rJ   Sequence[NativeExprT]r/   )r0   r1   rH   rP   s   ``` r6   _push_down_window_functionz"SQLExpr._push_down_window_functionM   s'    		.G	"	$ r8   c                    | j                  | j                  || j                  | j                  | j                  | j
                        S Nr3   r4   r5   r,   )	__class__r#   r%   r'   r(   r)   )r0   r2   s     r6   _with_window_functionzSQLExpr._with_window_functiond   sF     ~~JJ"&"="=#77MM//  
 	
r8   c                   | j                   | j                  |fi ||| j                  | j                  | j                  | j
                        S rV   )rX   rK   r%   r'   r(   r)   )r0   r1   window_funcrH   s       r6   _with_callablezSQLExpr._with_callablep   sU     ~~)D))$F2EF"&"="=#77MM//  
 	
r8   c                   | j                   | j                  |fi | | j                  |fi || j                  | j                  | j
                  | j                        S rV   rX   rK   rT   r%   r'   r(   r)   )r0   r1   rH   s      r6   _with_elementwisezSQLExpr._with_elementwise   sh     ~~)D))$F2EF+D++DH4GH"&"="=#77MM//  
 	
r8   c                    | j                  | j                  ||      | j                  ||      | j                  | j                  | j
                  | j                        S )NotherrW   r^   )r0   oprb   s      r6   _with_binaryzSQLExpr._with_binary   s`    ~~))"E):++Be+<"&"="=#77MM//  
 	
r8   c                   | j                   d n	nfd} t        |       | j                  | j                  | j                  || j
                  | j                        S )Nc                       |             S r.   r/   )output_namescurrent_alias_output_namesrI   s    r6   <lambda>z2SQLExpr._with_alias_output_names.<locals>.<lambda>   s    d+El+S&Tr8   rW   )r'   typer#   r+   r%   r(   r)   )r0   rI   r4   rh   s    ` @r6   _with_alias_output_namesz SQLExpr._with_alias_output_names   sq    %)%=%=" |  *1 T 	 tDzJJ!!"&"="=1MM//
 	
r8   c                <     	 	 	 	 	 	 d fd} j                   xs |S )Nc                    |j                   rJ  |       D cg c]  }j                  ||j                          c}S c c}w r.   )order_by_window_expressionpartition_byr:   inputsexprr0   s      r6   default_window_funcz4SQLExpr.window_function.<locals>.default_window_func   sK     &&OSTVxOWt''f.A.ABx  s   #A r:   r   rr   rR   rJ   rS   )r+   )r0   rt   s   ` r6   r2   zSQLExpr.window_function   s4    		'@	"	 $$;(;;r8   c                D     | j                         j                  |g| S r.   )r>   	_function)r0   nameargss      r6   rw   zSQLExpr._function   s#    6t**,66tCdCCr8   c                @    | j                         j                  |      S r.   )r>   _lit)r0   rE   s     r6   r{   zSQLExpr._lit   s    **,11%88r8   c                <     | j                         j                  | S r.   )r>   	_coalesce)r0   rs   s     r6   r}   zSQLExpr._coalesce   s    6t**,66==r8   c                     y r.   r/   r=   s    r6   _count_starzSQLExpr._count_star   s    #r8   c                     y r.   r/   r0   rs   rn   s      r6   _firstzSQLExpr._first   s    r8   c                     y r.   r/   r   s      r6   _lastzSQLExpr._last   s    sr8   c                    y r.   r/   )r0   rs   ignore_nullss      r6   
_any_valuezSQLExpr._any_value   s    SVr8   c                D    | j                         j                  |||      S r.   )r>   _when)r0   	conditionrE   	otherwises       r6   r   zSQLExpr._when   s"     **,229eYOOr8   
descending
nulls_lastc                    y r.   r/   )r0   rs   rp   rn   
rows_startrows_endr   r   s           r6   ro   zSQLExpr._window_expression   s     r8   c               (     	 	 	 	 	 	 d fd}|S )Nc                ,   t        t        |j                              } |       D cg c]^  }j                  j	                  d|       j                  j	                  |      |j                  |j                  ||d            ` c}S c c}w )Nisnullr   r   r   r   )r   lenrn   r   rw   ro   rp   )r:   rr   flagsrs   	func_namereverser0   s       r6   rI   z&SQLExpr._cum_window_func.<locals>.func   s      V__)=>E !H %D 

^^Hd33++y$7++#(#(!" , 
 %  s   A#Bru   r/   )r0   r   r   rI   s   ``` r6   _cum_window_funczSQLExpr._cum_window_func   s'    		'@	"	& r8   c                   	
 g d|r|dz
  dz  }|dz
  dz  }||z    
|	n|dz
   
d		 	 	 	 	 	 d	 
fd}|S )N)summeanstdvar      r   c                   dv r}n\dk(  rdk(  rd}nOdv rdk(  rd}nCdk(  rdk(  rd}n6dk(  rdk(  rd	}n)d
v rd d}t        |      d d d}t        |      |j                  |j                  d} 
|       D cg c]h  }
j                   
j                  
j                  d|      fi |
j                  	      k\   
j                  
j                  ||      fi |      j c}S c c}w )N>   r   r   r   r   var_popr   var_sampr   
stddev_popstddev_samp>   r   r   z;Only ddof=0 and ddof=1 are currently supported for rolling_.z,Only the following functions are supported: z.
Got: )rp   rn   r   r   count)
ValueErrorrp   rn   r   ro   rw   r{   )r:   rr   func_msgwindow_kwargsrs   ddofendr   min_samplesr0   startsupported_funcss         r6   rI   z*SQLExpr._rolling_window_func.<locals>.func   sT    O+&e#	!e#	"e#	$e#	%n,ST]S^^_` o%D_DUU]^g]hhij o% & 3 3"OO#	"M !H	 %D 

+D++w59F yy-. ,D++DNN5$,GY=Y %	 	 	s   
A-C:ru   r/   )r0   r   window_sizer   r   centerhalf	remainderrI   r   r   r   s   `` ``    @@@r6   _rolling_window_funczSQLExpr._rolling_window_func   sv     8!O)D$qA-IY&'EC!Ao&EC"	"	'@"	""	 "	H r8   c                6    | j                   j                         S r.   )r)   _backend_versionr=   s    r6   r   zSQLExpr._backend_version&  s    ##4466r8   c                    y r.   r/   )clsrs   rx   s      r6   _alias_nativezSQLExpr._alias_native*  s    LOr8   c                    dfd}	 	 	 	 	 	 dfd}d   } | ||t         t         |j                  |j                        S )Nc           	     \     D cg c]  } ||       D ]  }|  c}}      gS c c}}w r.   r/   )r:   rs   eexprsrI   s      r6   r1   z5SQLExpr._from_elementwise_horizontal_op.<locals>.call1  s/    @tBx!!x!@ABB@s   (
c                r    D cg c]  }|j                  | |      D ]  }|  }}} |      gS c c}}w r.   )r2   )r:   rO   rs   r   lstr   rI   s        r6   r2   z@SQLExpr._from_elementwise_horizontal_op.<locals>.window_function4  sA     "'X0D0DR0W110W1CXI; Ys    3r   )r2   r3   r4   r5   r,   r:   r   rJ   rS   rQ   )r   r   r(   r)   )r   rI   r   r1   r2   contexts    ``   r6   _from_elementwise_horizontal_opz'SQLExpr._from_elementwise_horizontal_op-  sf    	C		.G	"	 (+"?"G95A$$"22
 	
r8   c                J    | j                   j                  j                         S )a	  Return `True` for multi-output aggregations without names.

        For example, column `'a'` only appears in the output as a grouping key:

            df.group_by('a').agg(nw.all().sum())

        It does not get included in:

            nw.all().sum().
        )	_metadataexpansion_kindis_multi_unnamedr=   s    r6   _is_multi_output_unnamedz SQLExpr._is_multi_output_unnamedD  s     ~~,,==??r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__eq__rs   rb   s     r6   ri   z SQLExpr.__eq__.<locals>.<lambda>S      T[[5Gr8   rd   r0   rb   s     r6   r   zSQLExpr.__eq__R        !GOOr8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__ne__r   s     r6   ri   z SQLExpr.__ne__.<locals>.<lambda>V  r   r8   r   r   s     r6   r   zSQLExpr.__ne__U  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__add__r   s     r6   ri   z!SQLExpr.__add__.<locals>.<lambda>Y      T\\%5Hr8   r   r   s     r6   r   zSQLExpr.__add__X        !H%PPr8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__sub__r   s     r6   ri   z!SQLExpr.__sub__.<locals>.<lambda>\  r   r8   r   r   s     r6   r   zSQLExpr.__sub__[  r   r8   c                F    | j                  d |      j                  d      S )Nc                    || z
  S r.   r/   r   s     r6   ri   z"SQLExpr.__rsub__.<locals>.<lambda>_      UT\r8   literalrd   aliasr   s     r6   __rsub__zSQLExpr.__rsub__^  "      !A5IOOPYZZr8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__mul__r   s     r6   ri   z!SQLExpr.__mul__.<locals>.<lambda>b  r   r8   r   r   s     r6   r   zSQLExpr.__mul__a  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__truediv__r   s     r6   ri   z%SQLExpr.__truediv__.<locals>.<lambda>e  s    T5E5Ee5Lr8   r   r   s     r6   r   zSQLExpr.__truediv__d  s      !LeTTr8   c                F    | j                  d |      j                  d      S )Nc                    || z  S r.   r/   r   s     r6   ri   z&SQLExpr.__rtruediv__.<locals>.<lambda>h  r   r8   r   r   r   s     r6   __rtruediv__zSQLExpr.__rtruediv__g  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__pow__r   s     r6   ri   z!SQLExpr.__pow__.<locals>.<lambda>k  r   r8   r   r   s     r6   r   zSQLExpr.__pow__j  r   r8   c                F    | j                  d |      j                  d      S )Nc                    || z  S r.   r/   r   s     r6   ri   z"SQLExpr.__rpow__.<locals>.<lambda>n  s    UD[r8   r   r   r   s     r6   __rpow__zSQLExpr.__rpow__m  s!      !@%HNNyYYr8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__mod__r   s     r6   ri   z!SQLExpr.__mod__.<locals>.<lambda>q  r   r8   r   r   s     r6   r   zSQLExpr.__mod__p  r   r8   c                F    | j                  d |      j                  d      S )Nc                    || z  S r.   r/   r   s     r6   ri   z"SQLExpr.__rmod__.<locals>.<lambda>t  r   r8   r   r   r   s     r6   __rmod__zSQLExpr.__rmod__s  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__ge__r   s     r6   ri   z SQLExpr.__ge__.<locals>.<lambda>w  r   r8   r   r   s     r6   r   zSQLExpr.__ge__v  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__gt__r   s     r6   ri   z SQLExpr.__gt__.<locals>.<lambda>z  r   r8   r   r   s     r6   r   zSQLExpr.__gt__y  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__le__r   s     r6   ri   z SQLExpr.__le__.<locals>.<lambda>}  r   r8   r   r   s     r6   r  zSQLExpr.__le__|  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__lt__r   s     r6   ri   z SQLExpr.__lt__.<locals>.<lambda>  r   r8   r   r   s     r6   r  zSQLExpr.__lt__  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__and__r   s     r6   ri   z!SQLExpr.__and__.<locals>.<lambda>  r   r8   r   r   s     r6   r  zSQLExpr.__and__  r   r8   c                (    | j                  d |      S )Nc                $    | j                  |      S r.   )__or__r   s     r6   ri   z SQLExpr.__or__.<locals>.<lambda>  r   r8   r   r   s     r6   r  zSQLExpr.__or__  r   r8   c                6     d fd} j                  ||      S )Nc                    j                  |j                  d      k7  t        j                  | |      j                  d             S Nr   r   r{   rc   floordivrs   rb   r0   s     r6   rI   z"SQLExpr.__floordiv__.<locals>.func  s;    ::1%r{{4'?4 r8   ra   rs   r   rb   r   rJ   r   r   r0   rb   rI   s   `  r6   __floordiv__zSQLExpr.__floordiv__  s     	
   U 33r8   c                T     d fd} j                  ||      j                  d      S )Nc                    j                  | j                  d      k7  t        j                  ||       j                  d             S r  r  r  s     r6   rI   z#SQLExpr.__rfloordiv__.<locals>.func  s;    ::		!$bkk%&>		$ r8   ra   r   r  r   r  s   `  r6   __rfloordiv__zSQLExpr.__rfloordiv__  s+    	
   U 399)DDr8   c                L     d fd}	 	 	 	 	 	 d fd} j                  ||      S )Nc                f    j                  j                  d|       j                  d            S Nbool_andTr}   rw   r{   rs   r0   s    r6   fzSQLExpr.all.<locals>.f  s'    >>$..T"BDIIdOTTr8   c                     |       D cg c]M  }j                  j                  j                  d|      |j                        j	                  d            O c}S c c}w r  r}   ro   rw   rp   r{   rq   s      r6   rP   zSQLExpr.all.<locals>.window_f  sl     !H %D ++z48&:M:M IIdO	 %     AA!rs   r   rJ   r   ru   r\   r0   r  rP   s   `  r6   allzSQLExpr.all  ;    	U		'@	"	 ""1h//r8   c                L     d fd}	 	 	 	 	 	 d fd} j                  ||      S )Nc                f    j                  j                  d|       j                  d            S Nbool_orFr  r  s    r6   r  zSQLExpr.any.<locals>.f  s(    >>$..D"A499UCSTTr8   c                     |       D cg c]M  }j                  j                  j                  d|      |j                        j	                  d            O c}S c c}w r)  r   rq   s      r6   rP   zSQLExpr.any.<locals>.window_f  sm     !H %D ++y$79L9L IIe$	 %  r!  r"  ru   r#  r$  s   `  r6   anyzSQLExpr.any  r&  r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nmaxrw   r  s    r6   ri   zSQLExpr.max.<locals>.<lambda>      ud0Kr8   r#  r=   s   `r6   r/  zSQLExpr.max      ""#KLLr8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nr   r0  r  s    r6   ri   zSQLExpr.mean.<locals>.<lambda>      vt0Lr8   r#  r=   s   `r6   r   zSQLExpr.mean  s    ""#LMMr8   c               6     d fd} j                  |      S )Nc                F   dk(  rj                  d|       S dk(  rj                  d|       S j                  d|       }t        j                  j                  d|       j                  dt        j                  |d      t        j                  |      z              S )Nr   r   r   r   r   sqrtrw   rc   mulsubrs   	n_samplesr   r0   s     r6   rI   zSQLExpr.std.<locals>.func  s    qy~~lD99qy~~mT::w5I66}d3vy!(<yRV@W'WX r8   r"  r#  r0   r   rI   s   `` r6   r   zSQLExpr.std      		 ""4((r8   c               6     d fd} j                  |      S )Nc                &   dk(  rj                  d|       S dk(  rj                  d|       S j                  d|       }t        j                  j                  d|       t        j                  |d      t        j                  |      z        S )Nr   r   r   r   r   r9  r<  s     r6   rI   zSQLExpr.var.<locals>.func  s    qy~~i66qy~~j$77w5I66z40y!$rvvi'>> r8   r"  r#  r>  s   `` r6   r   zSQLExpr.var  r?  r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nmedianr0  r  s    r6   ri   z SQLExpr.median.<locals>.<lambda>  s    x0Nr8   r#  r=   s   `r6   rD  zSQLExpr.median  s    ""#NOOr8   c                6     d fd} j                  |      S )Nc                h    j                  j                  d|       j                        |       S )Nisnan)r   rw   r{   )rs   r0   rE   s    r6   	_fill_nanz#SQLExpr.fill_nan.<locals>._fill_nan  s*    ::dnnWd;TYYu=MtTTr8   r"  r_   )r0   rE   rH  s   `` r6   fill_nanzSQLExpr.fill_nan  s    	U %%i00r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nminr0  r  s    r6   ri   zSQLExpr.min.<locals>.<lambda>  r1  r8   r#  r=   s   `r6   rM  zSQLExpr.min  r2  r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nr   r0  r  s    r6   ri   zSQLExpr.count.<locals>.<lambda>  s    w0Mr8   r#  r=   s   `r6   r   zSQLExpr.count  s    ""#MNNr8   c                L     d fd}	 	 	 	 	 	 d fd} j                  ||      S )Nc                f    j                  j                  d|       j                  d            S Nr   r   r  r  s    r6   r  zSQLExpr.sum.<locals>.f  s'    >>$.."=tyy|LLr8   c                    |j                   rJ  |       D cg c]M  }j                  j                  j                  d|      |j                        j                  d            O c}S c c}w rR  )rn   r}   ro   rw   rp   r{   rq   s      r6   rP   zSQLExpr.sum.<locals>.window_f  s{     && !H %D ++ud3V5H5H IIaL	 %  s   AA/r"  ru   r#  r$  s   `  r6   r   zSQLExpr.sum  s;    	M		'@	"	 ""1h//r8   c                      j                    j                   j                  d       j                  d      cd fd}	 	 	 	 	 	 d fd} j                  ||      S )Nr   r   c                |    t        j                   d|        dj                   d|                         S Ncount_distinctr/  r   )rc   addr   )rs   Foner0   zeros    r6   rI   zSQLExpr.n_unique.<locals>.func	  s=    66"D)%Ah$5sDAB r8   c                     |       D cg c]`  }t        j                    d|      |j                          dj                   d|                  |j                              b c}S c c}w rV  )rc   rX  rp   r   )r:   rr   rs   rY  WrZ  r0   r[  s      r6   rP   z"SQLExpr.n_unique.<locals>.window_f  s     !H	 %D a($/1D1DE%Ah,=sD!IJ++ %	 	 	s   A%A4r"  ru   )rw   ro   r{   r\   )r0   rI   rP   rY  r]  rZ  r[  s   `  @@@@r6   n_uniquezSQLExpr.n_unique  ss    NN##IIaL$))A,	c	 			'@	"	 	 ""422r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nabsr0  r  s    r6   ri   zSQLExpr.abs.<locals>.<lambda>!      4>>%3Nr8   rI  r=   s   `r6   ra  zSQLExpr.abs       %%&NOOr8   c                H     	 	 	 	 	 	 	 	 d fd} j                  |||      S )Nc                L    j                  dj                  d| |      |      S )Ngreatestleastr0  )rs   lower_boundupper_boundr0   s      r6   _clipzSQLExpr.clip.<locals>._clip$  s*     >>DNN7D+F r8   )rh  ri  )rs   r   rh  r   ri  r   rJ   r   rI  )r0   rh  ri  rj  s   `   r6   clipzSQLExpr.clip#  sI    		,7	FQ		 %%{ & 
 	
r8   c                6     d fd} j                  ||      S )Nc                *    j                  d| |      S )Nrf  r0  )rs   rh  r0   s     r6   rj  z!SQLExpr.clip_lower.<locals>._clip0  s    >>*dK@@r8   )rh  )rs   r   rh  r   rJ   r   rI  )r0   rh  rj  s   `  r6   
clip_lowerzSQLExpr.clip_lower/  s!    	A %%e%EEr8   c                6     d fd} j                  ||      S )Nc                *    j                  d| |      S )Nrg  r0  )rs   ri  r0   s     r6   rj  z!SQLExpr.clip_upper.<locals>._clip6  s    >>'4==r8   )ri  )rs   r   ri  r   rJ   r   rI  )r0   ri  rj  s   `  r6   
clip_upperzSQLExpr.clip_upper5  s     	> %%e%EEr8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nr   r0  r  s    r6   ri   z!SQLExpr.is_null.<locals>.<lambda><  s    4>>(D3Qr8   rI  r=   s   `r6   is_nullzSQLExpr.is_null;  s    %%&QRRr8   c                0      j                   fd      S )Nc                H    j                  d| j                              S )Nround)rw   r{   )rs   decimalsr0   s    r6   ri   zSQLExpr.round.<locals>.<lambda>@  s    tyy7JKr8   rI  )r0   rx  s   ``r6   rw  zSQLExpr.round>  s    %%K
 	
r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nfloorr0  r  s    r6   ri   zSQLExpr.floor.<locals>.<lambda>D  s    4>>'43Pr8   rI  r=   s   `r6   r{  zSQLExpr.floorC  s    %%&PQQr8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nceilr0  r  s    r6   ri   zSQLExpr.ceil.<locals>.<lambda>G  s    4>>&$3Or8   rI  r=   s   `r6   r~  zSQLExpr.ceilF  s    %%&OPPr8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nsinr0  r  s    r6   ri   zSQLExpr.sin.<locals>.<lambda>J  rb  r8   rI  r=   s   `r6   r  zSQLExpr.sinI  rc  r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Ncosr0  r  s    r6   ri   zSQLExpr.cos.<locals>.<lambda>M  rb  r8   rI  r=   s   `r6   r  zSQLExpr.cosL  rc  r8   c                2     d fd} j                  |      S )Nc                    j                  | j                  d      k  j                  t        d            j                  d|             S )Nr   nanr8  )r   r{   floatrw   r  s    r6   _sqrtzSQLExpr.sqrt.<locals>._sqrtP  sA    ::tyy|#TYYuU|%<dnnVUY>Z r8   r"  rI  )r0   r  s   ` r6   r8  zSQLExpr.sqrtO  s    	
 %%e,,r8   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nexpr0  r  s    r6   ri   zSQLExpr.exp.<locals>.<lambda>X  rb  r8   rI  r=   s   `r6   r  zSQLExpr.expW  rc  r8   c                6     d fd} j                  |      S )Nc                n   j                   }j                  | j                  d      k  j                  t        d            j                  | j                  d      k(  j                  t        d            t	        j
                   |d|        |dj                                                S )Nr   r  z-inflog)rw   r   r{   r  rc   truediv)rs   rY  baser0   s     r6   _logzSQLExpr.log.<locals>._log[  s    A::tyy|#		%,'

DIIaL(IIeFm,JJq~q		$/HI r8   r"  rI  )r0   r  r  s   `` r6   r  zSQLExpr.logZ  s    
	 %%d++r8   c               F    | j                  | j                  d|            S )Nr   r   rY   r   r0   r   s     r6   cum_sumzSQLExpr.cum_sumj  #    ))$*?*?w*?*WXXr8   c               F    | j                  | j                  d|            S )Nr/  r  r  r  s     r6   cum_maxzSQLExpr.cum_maxm  r  r8   c               F    | j                  | j                  d|            S )NrM  r  r  r  s     r6   cum_minzSQLExpr.cum_minp  r  r8   c               B     	 	 	 	 	 	 d fd} j                  |      S )Nc                    t        t        |j                              } |       D cg c]=  }j                  j	                  d|      |j
                  |j                  ||d      ? c}S c c}w )Nr   r   r   )r   r   rn   ro   rw   rp   )r:   rr   r   rs   r   r0   s       r6   rI   zSQLExpr.cum_count.<locals>.funct  s      V__)=>E !H
 %D ''NN7D1''OO$$ (  %
 
 
s   AA0ru   rY   )r0   r   rI   s   `` r6   	cum_countzSQLExpr.cum_counts  s3    		'@	"	  ))$//r8   c               F    | j                  | j                  d|            S )Nproductr  r  r  s     r6   cum_prodzSQLExpr.cum_prod  s(    ))!!)W!=
 	
r8   c               J    | j                  | j                  d|||            S )Nr   r   rY   r   r0   r   r   r   s       r6   rolling_sumzSQLExpr.rolling_sum  s,    ))%%e[+f%U
 	
r8   c               J    | j                  | j                  d|||            S )Nr   r  r  r  s       r6   rolling_meanzSQLExpr.rolling_mean  s,    ))%%fk;v%V
 	
r8   c          	     L    | j                  | j                  d||||            S )Nr   r   r   r  r0   r   r   r   r   s        r6   rolling_varzSQLExpr.rolling_var  5     ))%%{Kd6 & 
 	
r8   c          	     L    | j                  | j                  d||||            S )Nr   r  r  r  s        r6   rolling_stdzSQLExpr.rolling_std  r  r8   c                >     	 	 	 	 	 	 d fd} j                  |      S )Nc                    j                   }j                  } |       D cg c];  }t        j                  | | |d|      |j                  |j
                              = c}S c c}w Nlag)rw   ro   rc   r;  rp   rn   )r:   rr   rY  windowrs   r0   s        r6   rI   zSQLExpr.diff.<locals>.func  sh     A,,F !H$D tVAeTNF4G4GYZ$  s   A A'ru   r  r0   rI   s   ` r6   diffzSQLExpr.diff  s3    		'@	"	 ))$//r8   c                B     	 	 	 	 	 	 d fd} j                  |      S )Nc           
          |       D cg c]:  }j                  j                  d|      |j                  |j                        < c}S c c}w r  )ro   rw   rp   rn   )r:   rr   rs   nr0   s      r6   rI   zSQLExpr.shift.<locals>.func  s[     !H	 %D ''NN5$2F4G4G %	  s   ?Aru   r  )r0   r  rI   s   `` r6   shiftzSQLExpr.shift  s3    		'@	"	 ))$//r8   c                >     	 	 	 	 	 	 d fd} j                  |      S )Nc                     |       D cg c]O  }j                  j                  d      g |j                  ||j                        j	                  d      k(  Q c}S c c}w )N
row_numberr   )ro   rw   rp   rn   r{   rq   s      r6   rI   z'SQLExpr.is_first_distinct.<locals>.func  su     !H %D ''NN<00f))040OO
 99Q<  %  s   AA#ru   r  r  s   ` r6   is_first_distinctzSQLExpr.is_first_distinct  s3    		'@	"	 ))$//r8   c                >     	 	 	 	 	 	 d fd} j                  |      S )Nc           
        t        dt        |j                              } |       D cg c]R  }j                  j	                  d      g |j
                  ||j                  ||      j                  d      k(  T c}S c c}w )NTr  r   r   )r   r   rn   ro   rw   rp   r{   )r:   rr   r   rs   r0   s       r6   rI   z&SQLExpr.is_last_distinct.<locals>.func  s      c&//&:;E !H
 %D ''NN<00f))040OO$$ (  99Q<  %
 
 
s   ABru   r  r  s   ` r6   is_last_distinctzSQLExpr.is_last_distinct  s3    		'@	"	  ))$//r8   c                R     d fd}	 	 	 	 	 	 d fd} j                  ||      S )Nc                H    sd}t        |       j                  | g S Nz#Expected `order_by` to be specified)r   r   rs   r   rn   r0   s     r6   r  zSQLExpr.first.<locals>.f  s,    ;+C004;;t/h//r8   c           
        r|j                   rd}t        |      s|j                   sd}t        |       |       D cg c]=  }j                   j                  |g|j                   xs  |j                        ? c}S c c}w )Nz4Can't specify both `order_by` in `over` and `first`.z4Must specify `order_by` either in `over` or `first`.)rn   r   ro   r   rp   r:   rr   r   rs   rn   r0   s       r6   rP   zSQLExpr.first.<locals>.window_f  s     FOOL+C00FOOL+C00
 !H	 %D ''DKKE(C8EvGZGZ %	     ABr"  ru   r#  r0   rn   r  rP   s   ``  r6   firstzSQLExpr.first  s:    	0		'@	"	  ""1h//r8   c                R     d fd}	 	 	 	 	 	 d fd} j                  ||      S )Nc                H    sd}t        |       j                  | g S r  )r   r   r  s     r6   r  zSQLExpr.last.<locals>.f  s,    ;+C004::d.X..r8   c           
        r|j                   rd}t        |      s|j                   sd}t        |       |       D cg c]=  }j                   j                  |g|j                   xs  |j                        ? c}S c c}w )Nz3Can't specify both `order_by` in `over` and `last`.z3Must specify `order_by` either in `over` or `last`.)rn   r   ro   r   rp   r  s       r6   rP   zSQLExpr.last.<locals>.window_f  s     FOOK+C00FOOK+C00
 !H	 %D ''DJJtDv'B(DfFYFY %	  r  r"  ru   r#  r  s   ``  r6   lastzSQLExpr.last   s:    	/		'@	"	  ""1h//r8   c               0      j                   fd      S )Nc                *    j                  |       S )N)r   )r   )rs   r   r0   s    r6   ri   z#SQLExpr.any_value.<locals>.<lambda>  s    LIr8   r#  )r0   r   s   ``r6   	any_valuezSQLExpr.any_value  s    ""I
 	
r8   c                    dv r j                  d      n(dk(  r j                  d      n j                  d      	 d		 	 	 	 	 	 	 d
 fddfd}	 	 	 	 	 	 d fd} j                  ||      S )N>   r/  rM  averagerankdense
dense_rankr  c               :   j                         }|| f|gdgd}dg || i}j                  }j                  }
dk(  rHt        j                  t        j
                   |	fi | ||fi |      j                  d            }ny
dk(  rkt        j
                   |	fi |t        j                  t        j                   ||fi |j                  d            j                  d                  }n	 |	fi |}j                   |d|        |      S )	NT)rp   rn   r   r   rp   r/  r   r  g       @r   )	r   ro   rw   rc   r;  rX  r{   r  r   )rs   rp   r   
count_exprr   count_window_kwargsr  rY  	rank_exprrI   methodr0   s            r6   _rankzSQLExpr.rank.<locals>._rank&  s-    ))+J ,!G)l#f	-M 4BCX\CXSWCX2Y,,FAFFFFt5}5zA-@A IIaL	 9$FF41=1JJvjH4GH$))TU,W		#	 #49=9	::q400)<<r8   c                     |       S )Nr   r/   )rs   r  r   s    r6   _unpartitioned_rankz)SQLExpr.rank.<locals>._unpartitioned_rankJ  s    *55r8   c                    |j                   rd}t        |       |       D cg c]  } ||j                         c}S c c}w )Nz[`rank` followed by `over` with `order_by` specified is not supported for SQL-like backends.r  )rn   NotImplementedErrorrp   )r:   rr   r   rs   r  r   r0   s       r6   _partitioned_rankz'SQLExpr.rank.<locals>._partitioned_rankM  sV     s)#.. !H$D dF//JG$  s   Ar/   )rs   r   rp   Sequence[str | NativeExprT]r   boolrJ   r   r"  ru   )rw   r\   )r0   r  r   r  r  r  rI   s   ```  @@r6   r  zSQLExpr.rank  s    ..>>&)Dw>>,/D>>,/D 9;"	="	=5"	= 	"	=
 "	=H	6				'@		"		 ""#68IJJr8   c                     	 	 	 	 	 	 d fddfd}	 	 	 	 	 	 d fd} j                  |      j                  |      S )Nc                p    j                  j                         | g|      j                  d      k(  S )Nr   )ro   r   r{   )rs   rp   r0   s     r6   
_is_uniquez%SQLExpr.is_unique.<locals>._is_unique[  s>     **  "T$9L$91 r8   c                     |       S r.   r/   )rs   r  s    r6   _unpartitioned_is_uniquez3SQLExpr.is_unique.<locals>._unpartitioned_is_uniqueb  s    d##r8   c                x    |j                   rJ  |       D cg c]  } |g|j                    c}S c c}w r.   )rn   rp   )r:   rr   rs   r  r0   s      r6   _partitioned_is_uniquez1SQLExpr.is_unique.<locals>._partitioned_is_uniquee  s>     &&GKBxPxtJt:f&9&9:xPPPs   7)rs   r   rp   zstr | NativeExprTrJ   r   r"  ru   )r\   rY   )r0   r  r  r  s   `  @r6   	is_uniquezSQLExpr.is_uniqueZ  sj    		.?			$	Q	Q'@	Q"	Q ""#;<RR"
 	
r8   c                     d fd} j                  | j                   j                   j                   j                        S )Nc                <    j                  | t                    S r.   )r2   r   )r:   rn   rp   r0   s    r6   rI   zSQLExpr.over.<locals>.funcs  s    ''Lx,PQQr8   rW   r   )rX   r%   r'   r(   r)   )r0   rp   rn   rI   s   ``` r6   overzSQLExpr.overp  sF    	R ~~"&"="=#77MM//  
 	
r8   c               r     |dk7  rd| d j                    d}t        |       j                   fd      S )Nr,  z`Expr.mode(keep='z#')` is not implemented for backend z3

Hint: Use `nw.col(...).mode(keep='any')` instead.c                (    j                  d|       S )Nmoder0  r  s    r6   ri   zSQLExpr.mode.<locals>.<lambda>  r5  r8   )r)   r  r\   )r0   keepr   s   `  r6   r  zSQLExpr.mode~  sP    5=#D6)LTMaMaLb cD D  &c**""#LMMr8   c                     y r.   r/   r=   s    r6   strzSQLExpr.str  s    36r8   c                     y r.   r/   r=   s    r6   dtz
SQLExpr.dt  s    58r8   r.   )r1   r"   r2   r*   r3   r$   r4   r&   r5   r   r,   r   rJ   Noner   )rJ   z3SQLNamespace[SQLLazyFrameT, Self, Any, NativeExprT])r1   Callable[..., NativeExprT]rH   r   rJ   r"   )r1   r  rH   r   rJ   *WindowFunction[SQLLazyFrameT, NativeExprT])r2   r  rJ   r   )r1   r  r[   r*   rH   r   rJ   r   )r1   r  rH   r   rJ   r   )rc   r  rb   r   rJ   r   )rI   r&   rJ   r   )rJ   r  )rx   r  ry   zNativeExprT | PythonLiteralrJ   r   )rE   r   rJ   r   r"  )rJ   r   )rs   r   rn   r  rJ   r   )rs   r   r   r  rJ   r   )r   r   rE   r   r   zNativeExprT | NonerJ   r   )r/   r/   NN)rs   r   rp   r  rn   r  r   
int | Noner   r  r   Sequence[bool] | Noner   r  rJ   r   )r   z'Literal['sum', 'max', 'min', 'product']r   r  rJ   r  )r   z$Literal['sum', 'mean', 'std', 'var']r   intr   r   r   r  r   r  rJ   r  )rJ   ztuple[int, ...])rs   r   rx   r  rJ   r   )rI   z*Callable[[list[NativeExprT]], NativeExprT]r   r   rJ   r   )rJ   r  )rb   r   rJ   r   )rJ   r   )r   r   rJ   r   )rE   zfloat | NonerJ   r   )rh  r   ri  r   rJ   r   )rh  r   rJ   r   )ri  r   rJ   r   )rx  r   rJ   r   )r  r  rJ   r   )r   r  rJ   r   )r   r   r   r   r   r  rJ   r   )
r   r   r   r   r   r  r   r   rJ   r   )r  r   rJ   r   r  )rn   Sequence[str]rJ   r   )r   r  rJ   r   )r  r   r   r  rJ   r   )rp   r  rn   r  rJ   r   )r  r   rJ   r   )rJ   zSQLExprStringNamespace[Self])rJ   zSQLExprDateTimeNamesSpace[Self])i__name__
__module____qualname____annotations__r   DUCKDBr7   r;   r>   rK   rT   rY   r\   r_   rd   rk   propertyr2   rw   r{   r}   r   r   r   r   r   ro   r   r   r   classmethodr   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   rD  rJ  rM  r   r   r^  ra  rk  rn  rq  rt  rw  r{  r~  r  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   
drop_nullsfilteruniquer/   r8   r6   r!   r!   #   s   1144**##GG
 NR	 *8)>)>	4	 K	
  8	 .	 	 '	 
	B	<B.JN	/ .JN	3.

I

	

 JN
(
 G

  $
 

 

.

JN

	



$ 	< 	<D9> .KJV
 )-	PP P &	P
 
P 5702!%#
 -1,0

 2
 .	

 
 
 *
 *
 

@NR	3:  777 7 	7
 7 7 
47r 7 7 O O
=
GK
	
 
,@PPQQ[QU[QZQ[PPPPQP4E0&0&MN))P1MO0(38P

FFS

RQPP-P, YYY0&






03
=A
IL
	


03
=A
IL
	
000"0&0202

:Kx
,
7
CP
	
N 6 68 8 "JFFr8   r!   )/
__future__r   operatorrc   typingr   r   r   r   r   narwhals._compliant.exprr	   narwhals._compliant.typingr
   r   r   r   r   narwhals._compliant.windowr   narwhals._expression_parsingr   r   narwhals._sql.typingr   narwhals._utilsr   r   r   r   narwhals.exceptionsr   collections.abcr   typing_extensionsr   narwhals._sql.expr_dtr   narwhals._sql.expr_strr   narwhals._sql.namespacer   narwhals.typingr   r   r   r!   r/   r8   r6   <module>r     su    "  B B -  4 / Q Q 5(&E?=4KKnh}k12H]K=W4X nr8   