
    Whq                    D   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 er>d d
lmZmZ d dl m!Z!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) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/  G d deeef   e	eef         Z0y)    )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not_implemented)IterableSequence)SelfTypeIs)r
   r   )ExprMetadata)SQLExprDateTimeNamesSpace)SQLExprStringNamespace)SQLNamespace)ModeKeepStrategyNumericLiteralPythonLiteral
RankMethodTemporalLiteralc                  V   e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   	 daej
                  d	 	 	 	 	 	 	 	 	 	 	 	 	 dbdZdcdZ	 	 dddZ	 	 	 	 	 	 dedZ		 	 	 	 	 	 dfdZ
	 	 	 	 dgdZ	 	 	 	 	 	 dhdZ	 	 	 	 	 	 dhdZdidZdjdZedkd       ZdldZdmdZdndZdodZ	 da	 	 	 	 	 	 	 dpd Z	 	 	 	 dqddd!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 drd"Z	 	 	 	 	 	 dsd#Z	 da	 	 	 	 	 	 	 	 	 	 	 dtd$Zedud%       Zedvd&       Zedwd'       Ze	 	 	 	 	 	 dxd(       Zdyd)Zdzd*Z dzd+Z!dzd,Z"dzd-Z#dzd.Z$dzd/Z%dzd0Z&dzd1Z'dzd2Z(dzd3Z)dzd4Z*dzd5Z+dzd6Z,dzd7Z-dzd8Z.dzd9Z/dzd:Z0dzd;Z1dzd<Z2dzd=Z3d{d>Z4d{d?Z5d{d@Z6d{dAZ7d{dBZ8d|dCZ9d{dDZ:d{dEZ;d{dFZ<d{dGZ=	 	 	 	 	 	 d}dHZ>d{dIZ?d~dJZ@d{dKZAd{dLZBddMZCddNZDddOZEddPZFddQZGddRZHddSZIddTZJ	 	 	 	 	 	 	 	 	 	 ddUZK	 	 	 	 	 	 	 	 	 	 ddVZLd{dWZMddXZNd{dYZOd{dZZPdd[ZQd{d\ZR	 	 	 	 	 	 dd]ZSdd^ZTedd_       ZUedd`       ZV eW       ZX eW       ZYy)SQLExpr&EvalSeries[SQLLazyFrameT, NativeExprT]_callEvalNames[SQLLazyFrameT]_evaluate_output_namesAliasNames | None_alias_output_namesr   _versionr   _implementationzExprMetadata | None	_metadata1WindowFunction[SQLLazyFrameT, NativeExprT] | None_window_functionN)implementationc                    y N )selfcallwindow_functionevaluate_output_namesalias_output_namesversionr0   s          L/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/_sql/expr.py__init__zSQLExpr.__init__2   s         c                $    | j                  |      S r2   )r&   )r4   dfs     r:   __call__zSQLExpr.__call__=   s    zz"~r<   c                     y r2   r3   r4   s    r:   __narwhals_namespace__zSQLExpr.__narwhals_namespace__@   s    >Ar<   c                    d fd}|S )Nc                     |       }j                         D ci c]9  \  }}|j                  |      r| j                  |      nj                  |      ; }}}|D cg c]  } |fi | c}S c c}}w c c}w r2   )items_is_expr_evaluate_expr_lit)	r>   native_series_listkeyvalueother_native_seriesnative_seriesr5   expressifiable_argsr4   s	         r:   funcz.SQLExpr._callable_to_eval_series.<locals>.funcG   s    !%b
 #6";";"=	# C ==' &&u-YYu%&# # &8! ]:&9: #s   >A5"A;)r>   r   returnzlist[NativeExprT]r3   )r4   r5   rN   rO   s   ``` r:   _callable_to_eval_seriesz SQLExpr._callable_to_eval_seriesD   s    	 r<   c               (     	 	 	 	 	 	 d fd}|S )Nc           	        	j                  | |      }j                         D ci c]:  \  }}|	j                  |      r| j                  ||      n	j	                  |      < }}}|D cg c]  } |fi | c}S c c}}w c c}w r2   )r6   rE   rF   _evaluate_window_exprrH   )
r>   window_inputsrI   rJ   rK   rL   rM   r5   rN   r4   s
          r:   window_fz4SQLExpr._push_down_window_function.<locals>.window_fY   s     "&!5!5b-!H
 #6";";"=	# C ==' --e]CYYu%&# # &8! ]:&9: #s   ?B -Br>   r   rU   WindowInputs[NativeExprT]rP   Sequence[NativeExprT]r3   )r4   r5   rN   rV   s   ``` r:   _push_down_window_functionz"SQLExpr._push_down_window_functionV   s'    		.G	"	( r<   c                    | j                  | j                  || j                  | j                  | j                  | j
                        S Nr7   r8   r9   r0   )	__class__r&   r(   r*   r+   r,   )r4   r6   s     r:   _with_window_functionzSQLExpr._with_window_functiono   sF     ~~JJ"&"="=#77MM//  
 	
r<   c                   | j                   | j                  |fi || j                  | j                  | j                  | j
                        S r\   )r^   rQ   r(   r*   r+   r,   r4   r5   rN   s      r:   _with_callablezSQLExpr._with_callable{   sR     ~~)D))$F2EF"&"="=#77MM//  
 	
r<   c                   | j                   | j                  |fi | | j                  |fi || j                  | j                  | j
                  | j                        S r\   r^   rQ   rZ   r(   r*   r+   r,   ra   s      r:   _with_elementwisezSQLExpr._with_elementwise   sh     ~~)D))$F2EF+D++DH4GH"&"="=#77MM//  
 	
r<   c                    | j                  | j                  ||      | j                  ||      | j                  | j                  | j
                  | j                        S )N)otherr]   rd   )r4   oprg   s      r:   _with_binaryzSQLExpr._with_binary   s`    ~~))"E):++Be+<"&"="=#77MM//  
 	
r<   c                   | j                   d n	nfd} t        |       | j                  | j                  | j                  || j
                  | j                        S )Nc                       |             S r2   r3   )output_namescurrent_alias_output_namesrO   s    r:   <lambda>z2SQLExpr._with_alias_output_names.<locals>.<lambda>   s    d+El+S&T r<   r]   )r*   typer&   r/   r(   r+   r,   )r4   rO   r8   rm   s    ` @r:   _with_alias_output_namesz SQLExpr._with_alias_output_names   sq    %)%=%=" |  *1 T 	 tDzJJ!!"&"="=1MM//
 	
r<   c                <     	 	 	 	 	 	 d fd} j                   xs |S )Nc                    |j                   rJ  |       D cg c])  }j                  ||j                  |j                         + c}S c c}w r2   )order_by_window_expressionpartition_byr>   inputsexprr4   s      r:   default_window_funcz4SQLExpr.window_function.<locals>.default_window_func   sQ     && !H ''f.A.A6??S  s   .Ar>   r   rw   rX   rP   rY   )r/   )r4   ry   s   ` r:   r6   zSQLExpr.window_function   s4    		'@	"	 $$;(;;r<   c                D     | j                         j                  |g| S r2   )rB   	_function)r4   nameargss      r:   r|   zSQLExpr._function   s#    6t**,66tCdCCr<   c                @    | j                         j                  |      S r2   )rB   rH   )r4   rK   s     r:   rH   zSQLExpr._lit   s    **,11%88r<   c                <     | j                         j                  | S r2   )rB   	_coalesce)r4   rx   s     r:   r   zSQLExpr._coalesce   s    6t**,66==r<   c                     y r2   r3   rA   s    r:   _count_starzSQLExpr._count_star   s    r<   c                D    | j                         j                  |||      S r2   )rB   _when)r4   	conditionrK   	otherwises       r:   r   zSQLExpr._when   s"     **,229eYOOr<   
descending
nulls_lastc                    y r2   r3   )r4   rx   ru   rs   
rows_startrows_endr   r   s           r:   rt   zSQLExpr._window_expression   s     r<   c               (     	 	 	 	 	 	 d fd}|S )Nc                    |       D cg c]k  }j                  j                  |      |j                  |j                  gt	        |j                        z  gt	        |j                        z  d      m c}S c c}w )Nr   )r   r   r   )rt   r|   ru   rs   len)r>   rw   rx   	func_namereverser4   s      r:   rO   z&SQLExpr._cum_window_func.<locals>.func   s     !H
  ''NN9d3''OO 'y3v+?? 'y3v+?? ( 
 
 
s   A0A?rz   r3   )r4   r   r   rO   s   ``` r:   _cum_window_funczSQLExpr._cum_window_func   s'    		'@	"	 r<   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: )ru   rs   r   r   count)
ValueErrorru   rs   r   rt   r|   rH   )r>   rw   func_msgwindow_kwargsrx   ddofendr   min_samplesr4   startsupported_funcss         r:   rO   z*SQLExpr._rolling_window_func.<locals>.func  sM    O+&e#	!e#	"e#	$e#	%n,ST]S^^_` o%D_DUU]^g]hhij o% & 3 3"OO#	"M !H	  

+D++w59F yy-. ,D++DNN5$,GY=Y	 	 	s   
A-C:rz   r3   )r4   r   window_sizer   r   centerhalf	remainderrO   r   r   r   s   `` ``    @@@r:   _rolling_window_funczSQLExpr._rolling_window_func   sv     8!O)D$qA-IY&'EC!Ao&EC"	"	'@"	""	 "	H r<   c                    t        |d      S )N__narwhals_expr__)hasattr)clsobjs     r:   rF   zSQLExpr._is_expr*  s    s/00r<   c                6    | j                   j                         S r2   )r,   _backend_versionrA   s    r:   r   zSQLExpr._backend_version.  s    ##4466r<   c                    y r2   r3   )r   rx   r}   s      r:   _alias_nativezSQLExpr._alias_native2  s    LOr<   c                    dfd}	 	 	 	 	 	 dfd}d   } | ||t         t         |j                  |j                        S )Nc                .      fdD        } |      gS )Nc              3  <   K   | ]  } |      D ]  }|   y wr2   r3   ).0_exprcolr>   s      r:   	<genexpr>zHSQLExpr._from_elementwise_horizontal_op.<locals>.call.<locals>.<genexpr>:  s!     @EeBi@sC@C@s   r3   )r>   colsexprsrO   s   ` r:   r5   z5SQLExpr._from_elementwise_horizontal_op.<locals>.call9  s    @U@DJ<r<   c                2      fdD        } |      gS )Nc              3  P   K   | ]  }|j                        D ]  }|   y wr2   )r6   )r   r   r   r>   rU   s      r:   r   zSSQLExpr._from_elementwise_horizontal_op.<locals>.window_function.<locals>.<genexpr>@  s5      %2G2GM2Z+.s   #&r3   )r>   rU   r   r   rO   s   `` r:   r6   z@SQLExpr._from_elementwise_horizontal_op.<locals>.window_function=  s     !&D J<r<   r   )r6   r7   r8   r9   r0   r>   r   rP   rY   rW   )r   r   r+   r,   )r   rO   r   r5   r6   contexts    ``   r:   _from_elementwise_horizontal_opz'SQLExpr._from_elementwise_horizontal_op5  se    	 	 	 .G	 "	  (+"?"G95A$$"22
 	
r<   c                f    | j                   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().
        )r-   expansion_kindis_multi_unnamedrA   s    r:   _is_multi_output_unnamedz SQLExpr._is_multi_output_unnamedO  s-     ~~)))~~,,==??r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__eq__rx   rg   s     r:   rn   z SQLExpr.__eq__.<locals>.<lambda>_      T[[5G r<   ri   r4   rg   s     r:   r   zSQLExpr.__eq__^        !GOOr<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__ne__r   s     r:   rn   z SQLExpr.__ne__.<locals>.<lambda>b  r   r<   r   r   s     r:   r   zSQLExpr.__ne__a  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__add__r   s     r:   rn   z!SQLExpr.__add__.<locals>.<lambda>e      T\\%5H r<   r   r   s     r:   r   zSQLExpr.__add__d        !H%PPr<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__sub__r   s     r:   rn   z!SQLExpr.__sub__.<locals>.<lambda>h  r   r<   r   r   s     r:   r   zSQLExpr.__sub__g  r   r<   c                F    | j                  d |      j                  d      S )Nc                    || z
  S r2   r3   r   s     r:   rn   z"SQLExpr.__rsub__.<locals>.<lambda>k  
    UT\ r<   literalri   aliasr   s     r:   __rsub__zSQLExpr.__rsub__j  "      !A5IOOPYZZr<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__mul__r   s     r:   rn   z!SQLExpr.__mul__.<locals>.<lambda>n  r   r<   r   r   s     r:   r   zSQLExpr.__mul__m  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__truediv__r   s     r:   rn   z%SQLExpr.__truediv__.<locals>.<lambda>q  s    T5E5Ee5L r<   r   r   s     r:   r   zSQLExpr.__truediv__p  s      !LeTTr<   c                F    | j                  d |      j                  d      S )Nc                    || z  S r2   r3   r   s     r:   rn   z&SQLExpr.__rtruediv__.<locals>.<lambda>t  r   r<   r   r   r   s     r:   __rtruediv__zSQLExpr.__rtruediv__s  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__floordiv__r   s     r:   rn   z&SQLExpr.__floordiv__.<locals>.<lambda>w  s    T5F5Fu5M r<   r   r   s     r:   r   zSQLExpr.__floordiv__v  s      !MuUUr<   c                F    | j                  d |      j                  d      S )Nc                    || z  S r2   r3   r   s     r:   rn   z'SQLExpr.__rfloordiv__.<locals>.<lambda>z  s
    Ud] r<   r   r   r   s     r:   __rfloordiv__zSQLExpr.__rfloordiv__y  s&      !BEJPP
 	
r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__pow__r   s     r:   rn   z!SQLExpr.__pow__.<locals>.<lambda>  r   r<   r   r   s     r:   r   zSQLExpr.__pow__~  r   r<   c                F    | j                  d |      j                  d      S )Nc                    || z  S r2   r3   r   s     r:   rn   z"SQLExpr.__rpow__.<locals>.<lambda>  s
    UD[ r<   r   r   r   s     r:   __rpow__zSQLExpr.__rpow__  s!      !@%HNNyYYr<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__mod__r   s     r:   rn   z!SQLExpr.__mod__.<locals>.<lambda>  r   r<   r   r   s     r:   r   zSQLExpr.__mod__  r   r<   c                F    | j                  d |      j                  d      S )Nc                    || z  S r2   r3   r   s     r:   rn   z"SQLExpr.__rmod__.<locals>.<lambda>  r   r<   r   r   r   s     r:   __rmod__zSQLExpr.__rmod__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__ge__r   s     r:   rn   z SQLExpr.__ge__.<locals>.<lambda>  r   r<   r   r   s     r:   r  zSQLExpr.__ge__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__gt__r   s     r:   rn   z SQLExpr.__gt__.<locals>.<lambda>  r   r<   r   r   s     r:   r  zSQLExpr.__gt__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__le__r   s     r:   rn   z SQLExpr.__le__.<locals>.<lambda>  r   r<   r   r   s     r:   r	  zSQLExpr.__le__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__lt__r   s     r:   rn   z SQLExpr.__lt__.<locals>.<lambda>  r   r<   r   r   s     r:   r  zSQLExpr.__lt__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__and__r   s     r:   rn   z!SQLExpr.__and__.<locals>.<lambda>  r   r<   r   r   s     r:   r  zSQLExpr.__and__  r   r<   c                (    | j                  d |      S )Nc                $    | j                  |      S r2   )__or__r   s     r:   rn   z SQLExpr.__or__.<locals>.<lambda>  r   r<   r   r   s     r:   r  zSQLExpr.__or__  r   r<   c                h     d fd}	 	 	 	 	 	 d fd} j                  |      j                  |      S )Nc                f    j                  j                  d|       j                  d            S Nbool_andTr   r|   rH   rx   r4   s    r:   fzSQLExpr.all.<locals>.f  s'    >>$..T"BDIIdOTTr<   c                     |       D cg c]M  }j                  j                  j                  d|      |j                        j	                  d            O c}S c c}w r  r   rt   r|   ru   rH   rv   s      r:   rV   zSQLExpr.all.<locals>.window_f  se     !H  ++z48&:M:M IIdO	     AA!rx   r   rP   r   rz   rb   r_   r4   r  rV   s   `  r:   allzSQLExpr.all  D    	U		'@	"	 ""1%;;HEEr<   c                h     d fd}	 	 	 	 	 	 d fd} j                  |      j                  |      S )Nc                f    j                  j                  d|       j                  d            S Nbool_orFr  r  s    r:   r  zSQLExpr.any.<locals>.f  s(    >>$..D"A499UCSTTr<   c                     |       D cg c]M  }j                  j                  j                  d|      |j                        j	                  d            O c}S c c}w r$  r  rv   s      r:   rV   zSQLExpr.any.<locals>.window_f  sf     !H  ++y$79L9L IIe$	  r  r  rz   r  r  s   `  r:   anyzSQLExpr.any  r!  r<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nmaxr|   r  s    r:   rn   zSQLExpr.max.<locals>.<lambda>      ud0K r<   rb   rA   s   `r:   r*  zSQLExpr.max      ""#KLLr<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nr   r+  r  s    r:   rn   zSQLExpr.mean.<locals>.<lambda>      vt0L r<   r-  rA   s   `r:   r   zSQLExpr.mean  s    ""#LMMr<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nmedianr+  r  s    r:   rn   z SQLExpr.median.<locals>.<lambda>  s    x0N r<   r-  rA   s   `r:   r4  zSQLExpr.median  s    ""#NOOr<   c                6     d fd} j                  |      S )Nc                h    j                  j                  d|       j                        |       S )Nisnan)r   r|   rH   )rx   r4   rK   s    r:   	_fill_nanz#SQLExpr.fill_nan.<locals>._fill_nan  s*    ::dnnWd;TYYu=MtTTr<   r  re   )r4   rK   r8  s   `` r:   fill_nanzSQLExpr.fill_nan  s    	U %%i00r<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nminr+  r  s    r:   rn   zSQLExpr.min.<locals>.<lambda>  r,  r<   r-  rA   s   `r:   r=  zSQLExpr.min  r.  r<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nr   r+  r  s    r:   rn   zSQLExpr.count.<locals>.<lambda>  s    w0M r<   r-  rA   s   `r:   r   zSQLExpr.count  s    ""#MNNr<   c                h     d fd}	 	 	 	 	 	 d fd} j                  |      j                  |      S )Nc                f    j                  j                  d|       j                  d            S Nr   r   r  r  s    r:   r  zSQLExpr.sum.<locals>.f  s'    >>$.."=tyy|LLr<   c                     |       D cg c]M  }j                  j                  j                  d|      |j                        j	                  d            O c}S c c}w rB  r  rv   s      r:   rV   zSQLExpr.sum.<locals>.window_f  se     !H  ++ud3V5H5H IIaL	  r  r  rz   r  r  s   `  r:   r   zSQLExpr.sum  sD    	M		'@	"	 ""1%;;HEEr<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nabsr+  r  s    r:   rn   zSQLExpr.abs.<locals>.<lambda>      4>>%3N r<   r9  rA   s   `r:   rF  zSQLExpr.abs      %%&NOOr<   c                     d fd}d fd}	 	 	 	 	 	 	 	 d	 fd}| j                  ||      S | j                  ||      S  j                  |||      S )
Nc                *    j                  d| |      S )Ngreatestr+  )rx   lower_boundr4   s     r:   _clip_lowerz!SQLExpr.clip.<locals>._clip_lower  s    >>*dK@@r<   c                *    j                  d| |      S )Nleastr+  )rx   upper_boundr4   s     r:   _clip_upperz!SQLExpr.clip.<locals>._clip_upper  s    >>'4==r<   c                L    j                  dj                  d| |      |      S )NrK  rO  r+  )rx   rL  rP  r4   s      r:   
_clip_bothz SQLExpr.clip.<locals>._clip_both  s*     >>DNN7D+F r<   )rP  )rL  )rL  rP  )rx   r   rL  r   rP   r   )rx   r   rP  r   rP   r   )rx   r   rL  r   rP  r   rP   r   r9  )r4   rL  rP  rM  rQ  rS  s   `     r:   clipzSQLExpr.clip  s    
	A	>		,/	>A		 ))+;)OO))+;)OO%%K[ & 
 	
r<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nisnullr+  r  s    r:   rn   z!SQLExpr.is_null.<locals>.<lambda>
  s    4>>(D3Q r<   r9  rA   s   `r:   is_nullzSQLExpr.is_null	  s    %%&QRRr<   c                0      j                   fd      S )Nc                H    j                  d| j                              S )Nround)r|   rH   )rx   decimalsr4   s    r:   rn   zSQLExpr.round.<locals>.<lambda>  s    tyy7JK r<   r9  )r4   r\  s   ``r:   r[  zSQLExpr.round  s    %%K
 	
r<   c                2     d fd} j                  |      S )Nc                    j                  | j                  d      k  j                  t        d            j                  d|             S )Nr   nansqrt)r   rH   floatr|   r  s    r:   _sqrtzSQLExpr.sqrt.<locals>._sqrt  sA    ::tyy|#TYYuU|%<dnnVUY>Z r<   r  r9  )r4   rb  s   ` r:   r`  zSQLExpr.sqrt  s    	
 %%e,,r<   c                ,      j                   fd      S )Nc                (    j                  d|       S )Nexpr+  r  s    r:   rn   zSQLExpr.exp.<locals>.<lambda>  rG  r<   r9  rA   s   `r:   re  zSQLExpr.exp  rH  r<   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)r|   r   rH   ra  rh   truediv)rx   Fbaser4   s     r:   _logzSQLExpr.log.<locals>._log  s    A::tyy|#		%,'

DIIaL(IIeFm,JJq~q		$/HI r<   r  r9  )r4   rk  rl  s   `` r:   rh  zSQLExpr.log  s    
	 %%d++r<   c               F    | j                  | j                  d|            S )Nr   r   r_   r   r4   r   s     r:   cum_sumzSQLExpr.cum_sum,  #    ))$*?*?w*?*WXXr<   c               F    | j                  | j                  d|            S )Nr*  rn  ro  rp  s     r:   cum_maxzSQLExpr.cum_max/  rr  r<   c               F    | j                  | j                  d|            S )Nr=  rn  ro  rp  s     r:   cum_minzSQLExpr.cum_min2  rr  r<   c               F    | j                  | j                  d|            S )Nr   rn  ro  rp  s     r:   	cum_countzSQLExpr.cum_count5  s$    ))$*?*?QX*?*YZZr<   c               F    | j                  | j                  d|            S )Nproductrn  ro  rp  s     r:   cum_prodzSQLExpr.cum_prod8  s(    ))!!)W!=
 	
r<   c               J    | j                  | j                  d|||            S )Nr   r   r_   r   r4   r   r   r   s       r:   rolling_sumzSQLExpr.rolling_sum>  s,    ))%%e[+f%U
 	
r<   c               J    | j                  | j                  d|||            S )Nr   r}  r~  r  s       r:   rolling_meanzSQLExpr.rolling_meanC  s,    ))%%fk;v%V
 	
r<   c          	     L    | j                  | j                  d||||            S )Nr   r   r   r~  r4   r   r   r   r   s        r:   rolling_varzSQLExpr.rolling_varH  5     ))%%{Kd6 & 
 	
r<   c          	     L    | j                  | j                  d||||            S )Nr   r  r~  r  s        r:   rolling_stdzSQLExpr.rolling_stdQ  r  r<   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)r|   rt   rh   subru   rs   )r>   rw   rj  windowrx   r4   s        r:   rO   zSQLExpr.diff.<locals>.func\  sc     A,,F !H tVAeTNF4G4GYZ  s   A A'rz   r_   r4   rO   s   ` r:   diffzSQLExpr.diff[  s3    		'@	"	 ))$//r<   c                B     	 	 	 	 	 	 d fd} j                  |      S )Nc           
          |       D cg c]:  }j                  j                  d|      |j                  |j                        < c}S c c}w r  )rt   r|   ru   rs   )r>   rw   rx   nr4   s      r:   rO   zSQLExpr.shift.<locals>.funci  sT     !H	  ''NN5$2F4G4G  s   ?Arz   r  )r4   r  rO   s   `` r:   shiftzSQLExpr.shifth  s3    		'@	"	 ))$//r<   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   )rt   r|   ru   rs   rH   rv   s      r:   rO   z'SQLExpr.is_first_distinct.<locals>.funcv  sn     !H  ''NN<00f))040OO
 99Q<   s   AA#rz   r  r  s   ` r:   is_first_distinctzSQLExpr.is_first_distinctu  s3    		'@	"	 ))$//r<   c                >     	 	 	 	 	 	 d fd} j                  |      S )Nc                2    |       D cg c]  }j                  j                  d      g |j                  ||j                  dgt	        |j                        z  dgt	        |j                        z        j                  d      k(   c}S c c}w )Nr  Tr   r   )rt   r|   ru   rs   r   rH   rv   s      r:   rO   z&SQLExpr.is_last_distinct.<locals>.func  s     !H
  ''NN<00f))040OO $vFOO(<< $vFOO(<< (  99Q< 
 
 
s   BBrz   r  r  s   ` r:   is_last_distinctzSQLExpr.is_last_distinct  s3    		'@	"	 ))$//r<   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                  |      j                  |      S )N>   r*  r=  averagerankdense
dense_rankr  c               <   j                         }|| 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 )N)ru   rs   r   r   ru   r*  r   r  g       @rW  )	r   rt   r|   rh   r  addrH   ri  r   )rx   ru   rs   r   r   
count_exprr   count_window_kwargsr  rj  	rank_exprrO   methodr4   s              r:   _rankzSQLExpr.rank.<locals>._rank  s/    ))+J ,!-H-((	-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)<<r<   c                     | gdg      S )NTr   r3   )rx   r  r   s    r:   _unpartitioned_rankz)SQLExpr.rank.<locals>._unpartitioned_rank  s    :,D6JJr<   c                     |       D cg c]Y  } ||j                   |j                  gdgt        |j                        z  z   dgdgt        |j                        z  z         [ c}S c c}w )NFTr   )ru   rs   r   )r>   rw   rx   r  r   r4   s      r:   _partitioned_rankz'SQLExpr.rank.<locals>._partitioned_rank  sw     !H	  ''OO *|ugFOO8L.LL $v#foo2F(FF	 	 	s   AA-)r3   r3   )rx   r   ru   Sequence[str | NativeExprT]rs   r  r   Sequence[bool]r   r  rP   r   r  rz   )r|   rb   r_   )r4   r  r   r  r  r  rO   s   ```  @@r:   r  zSQLExpr.rank  s    ..>>&)Dw>>,/D>>,/D 9;46$	=$	=5$	= 2$	=
 '$	= '$	= $	=L	K		'@	"	  ""#67MM
 	
r<   c                     	 	 	 	 	 	 d fddfd}	 	 	 	 	 	 d fd} j                  |      j                  |      S )Nc                p    j                  j                         | g|      j                  d      k(  S )Nr   )rt   r   rH   )rx   ru   r4   s     r:   
_is_uniquez%SQLExpr.is_unique.<locals>._is_unique  s>     **  "T$9L$91 r<   c                     |       S r2   r3   )rx   r  s    r:   _unpartitioned_is_uniquez3SQLExpr.is_unique.<locals>._unpartitioned_is_unique  s    d##r<   c                x    |j                   rJ  |       D cg c]  } |g|j                    c}S c c}w r2   )rs   ru   )r>   rw   rx   r  r4   s      r:   _partitioned_is_uniquez1SQLExpr.is_unique.<locals>._partitioned_is_unique  s:     &&GKBxPtJt:f&9&9:PPPs   7)rx   r   ru   zstr | NativeExprTrP   r   r  rz   r  )r4   r  r  r  s   `  @r:   	is_uniquezSQLExpr.is_unique  sj    		.?			$	Q	Q'@	Q"	Q ""#;<RR"
 	
r<   c                     d fd} j                  | j                   j                   j                   j                        S )Nc                <    j                  | t                    S r2   )r6   r   )r>   rs   ru   r4   s    r:   rO   zSQLExpr.over.<locals>.func  s    ''Lx,PQQr<   r]   r   )r^   r(   r*   r+   r,   )r4   ru   rs   rO   s   ``` r:   overzSQLExpr.over  sF    	R ~~"&"="=#77MM//  
 	
r<   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moder+  r  s    r:   rn   zSQLExpr.mode.<locals>.<lambda>	  r1  r<   )r,   NotImplementedErrorrb   )r4   keepr   s   `  r:   r  zSQLExpr.mode  sP    5=#D6)LTMaMaLb cD D  &c**""#LMMr<   c                     y r2   r3   rA   s    r:   strzSQLExpr.str  s    36r<   c                     y r2   r3   rA   s    r:   dtz
SQLExpr.dt  s    58r<   r2   )r5   r%   r6   r.   r7   r'   r8   r)   r9   r   r0   r   rP   Noner   )rP   z3SQLNamespace[SQLLazyFrameT, Self, Any, NativeExprT])r5   Callable[..., NativeExprT]rN   
Self | AnyrP   r%   )r5   r  rN   r  rP   *WindowFunction[SQLLazyFrameT, NativeExprT])r6   r  rP   r   )r5   r  rN   r  rP   r   )rh   r  rg   r  rP   r   )rO   r)   rP   r   )rP   r  )r}   r  r~   zNativeExprT | PythonLiteralrP   r   )rK   r   rP   r   r  )rP   r   )r   r   rK   r   r   zNativeExprT | NonerP   r   )r3   r3   NN)rx   r   ru   r  rs   r  r   
int | Noner   r  r   Sequence[bool] | Noner   r  rP   r   )r   z0Literal['sum', 'max', 'min', 'count', 'product']r   boolrP   r  )r   z$Literal['sum', 'mean', 'std', 'var']r   intr   r  r   r  r   r  rP   r  )r   r  rP   zTypeIs[Self])rP   ztuple[int, ...])rx   r   r}   r  rP   r   )rO   z.Callable[[Iterable[NativeExprT]], NativeExprT]r   r   rP   r   )rP   r  )rg   r   rP   r   )rP   r   )rK   zfloat | NonerP   r   )rL  .Self | NumericLiteral | TemporalLiteral | NonerP  r  rP   r   )r\  r  rP   r   )rk  ra  rP   r   )r   r  rP   r   )r   r  r   r  r   r  rP   r   )
r   r  r   r  r   r  r   r  rP   r   )r  r  rP   r   )r  r!   r   r  rP   r   )ru   r  rs   zSequence[str]rP   r   )r  r   rP   r   )rP   zSQLExprStringNamespace[Self])rP   zSQLExprDateTimeNamesSpace[Self])Z__name__
__module____qualname____annotations__r   DUCKDBr;   r?   rB   rQ   rZ   r_   rb   re   ri   rp   propertyr6   r|   rH   r   r   r   rt   r   r   classmethodrF   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   r4  r:  r=  r   r   rF  rT  rX  r[  r`  re  rh  rq  rt  rv  rx  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   
drop_nullsuniquer3   r<   r:   r$   r$   )   s   1144**##""GG
 NR	 *8)>)>	4	 K	
  8	 .	 	 '	 
	B	<B.JT	/$.JT	32

I

	

	
.	
JT	
		


.

JT

	



$ 
< 
<D9> . )-	PP P &	P
 
P 5702!%#
 -1,0

 2
 .	

 
 
 *
 *
 

C 	
 
48  777 7 	7
 7 7 
47r 1 1 7 7 O O
A
KO
	
 
2@PPQQ[QU[V

QZQ[PPPPQPF&F&MNP1MOF(P
C
 D
 
	
4S

-P, YYY[






03
=A
IL
	


03
=A
IL
	
000"0$C
J
,
7
CP
	
N 6 68 8 "JFr<   r$   )1
__future__r   operatorrh   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   collections.abcr   r   typing_extensionsr   r   r   narwhals._sql.expr_dtr   narwhals._sql.expr_strr   narwhals._sql.namespacer   narwhals.typingr   r   r    r!   r"   r$   r3   r<   r:   <module>r     sy    "  B B -  4 / D D2.E9?=4 jh}k12H]K=W4X jr<   