o
    Lhr                     @  s:  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rd 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 deeef e	eef Z0dS )    )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                   @  s  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< 	dejddddZdddZdd!d"Zdd&d'Z	d	d)d*Z
d
d,d-Zdd.d/Zdd0d1Zdd4d5Zdd7d8Zedd9d:Zdd@dAZddDdEZddGdHZddIdJZ	dddNdOZ	P	P		ddddQdd[d\ZddadbZ	dddidjZeddmdnZeddpdqZeddrdsZeddvdwZddxdyZddzd{Z dd|d}Z!dd~dZ"dddZ#dddZ$dddZ%dddZ&dddZ'dddZ(dddZ)dddZ*dddZ+dddZ,dddZ-dddZ.dddZ/dddZ0dddZ1dddZ2dddZ3dddZ4dddZ5dddZ6dddZ7dddZ8dddZ9dddZ:dddZ;dddZ<dddZ=dddZ>d ddZ?dddZ@dddZAd!ddƄZBd"ddȄZCd"ddʄZDd"dd̄ZEd"dd΄ZFd"ddЄZGd#dd҄ZHd#ddԄZId$ddքZJd$dd؄ZKdddڄZLd%dd݄ZMddd߄ZNdddZOd&ddZPdddZQd'ddZRd(ddZSed)ddZTed*ddZUeV ZWded< eV ZXded< eV ZYded< eV ZZded< eV Z[ded< eV Z\ded< eV Z]ded< eV Z^ded< eV Z_ded< eV Z`ded< eV Zaded < eV Zbded< eV Zcded< eV Zdded< dS (+  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)implementationcallwindow_functionevaluate_output_namesalias_output_namesversionr.   returnNonec                C     d S N )selfr/   r0   r1   r2   r3   r.   r8   r8   S/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/narwhals/_sql/expr.py__init__2   s   	zSQLExpr.__init__dfr   Sequence[NativeExprT]c                 C  
   |  |S r7   )r$   )r9   r<   r8   r8   r:   __call__=   s   
zSQLExpr.__call__3SQLNamespace[SQLLazyFrameT, Self, Any, NativeExprT]c                 C  r6   r7   r8   r9   r8   r8   r:   __narwhals_namespace__@   s   zSQLExpr.__narwhals_namespace__Callable[..., NativeExprT]expressifiable_args
Self | Anyc                  s   d fdd}|S )Nr<   r   r4   list[NativeExprT]c                   s4    } fdd  D fdd|D S )Nc                   s0   i | ]\}}| |r |n|qS r8   )_is_expr_evaluate_expr_lit.0keyvalue)r<   r9   r8   r:   
<dictcomp>I   s    zBSQLExpr._callable_to_eval_series.<locals>.func.<locals>.<dictcomp>c                      g | ]
} |fi qS r8   r8   rK   native_seriesr/   other_native_seriesr8   r:   
<listcomp>O       zBSQLExpr._callable_to_eval_series.<locals>.func.<locals>.<listcomp>)items)r<   native_series_listr/   rD   r9   )r<   rS   r:   funcG   s   z.SQLExpr._callable_to_eval_series.<locals>.func)r<   r   r4   rF   r8   )r9   r/   rD   rY   r8   rX   r:   _callable_to_eval_seriesD   s   z SQLExpr._callable_to_eval_series*WindowFunction[SQLLazyFrameT, NativeExprT]c                     d	 fdd}|S )
Nr<   r   window_inputsWindowInputs[NativeExprT]r4   r=   c                   s:     } fdd D fdd|D S )Nc                   s2   i | ]\}}| |r |n|qS r8   )rG   _evaluate_window_exprrI   rJ   )r<   r9   r]   r8   r:   rN   b   s    zHSQLExpr._push_down_window_function.<locals>.window_f.<locals>.<dictcomp>c                   rO   r8   r8   rP   rR   r8   r:   rT   h   rU   zHSQLExpr._push_down_window_function.<locals>.window_f.<locals>.<listcomp>)r0   rV   )r<   r]   rW   rX   )r<   rS   r]   r:   window_fY   s   z4SQLExpr._push_down_window_function.<locals>.window_fr<   r   r]   r^   r4   r=   r8   )r9   r/   rD   r`   r8   rX   r:   _push_down_window_functionV   s   z"SQLExpr._push_down_window_functionr   c                 C  s    | j | j|| j| j| j| jdS Nr1   r2   r3   r.   )	__class__r$   r&   r(   r)   r*   )r9   r0   r8   r8   r:   _with_window_functiono   s   zSQLExpr._with_window_functionc                K  s*   | j | j|fi || j| j| j| jdS rc   )re   rZ   r&   r(   r)   r*   r9   r/   rD   r8   r8   r:   _with_callable{   s   zSQLExpr._with_callablec                K  s:   | j | j|fi || j|fi || j| j| j| jdS rc   re   rZ   rb   r&   r(   r)   r*   rg   r8   r8   r:   _with_elementwise   s   zSQLExpr._with_elementwiseopotherc                 C  s2   | j | j||d| j||d| j| j| j| jdS )N)rl   rd   ri   )r9   rk   rl   r8   r8   r:   _with_binary   s   zSQLExpr._with_binaryrY   c                  sN   | j  d u r	d n d u rn fdd}t| | j| j| j|| j| jdS )Nc                   s    | S r7   r8   )output_namescurrent_alias_output_namesrY   r8   r:   <lambda>       z2SQLExpr._with_alias_output_names.<locals>.<lambda>rd   )r(   typer$   r-   r&   r)   r*   )r9   rY   r2   r8   ro   r:   _with_alias_output_names   s   z SQLExpr._with_alias_output_namesc                   s   d	 fdd} j p|S )
Nr<   r   inputsr^   r4   r=   c                   s"    j rJ  fdd| D S )Nc                   s   g | ]} | j jqS r8   )_window_expressionpartition_byorder_byrK   exprru   r9   r8   r:   rT      s    zHSQLExpr.window_function.<locals>.default_window_func.<locals>.<listcomp>rx   r<   ru   rA   ru   r:   default_window_func   s   
z4SQLExpr.window_function.<locals>.default_window_funcr<   r   ru   r^   r4   r=   )r-   )r9   r   r8   rA   r:   r0      s   
	zSQLExpr.window_functionnamestrargsNativeExprT | PythonLiteralr   c                 G  s   |   j|g|R  S r7   )rB   	_function)r9   r   r   r8   r8   r:   r         zSQLExpr._functionrM   r   c                 C  s   |   |S r7   )rB   rI   r9   rM   r8   r8   r:   rI         zSQLExpr._litrz   c                 G  s   |   j| S r7   )rB   	_coalesce)r9   rz   r8   r8   r:   r      r   zSQLExpr._coalescec                 C  r6   r7   r8   rA   r8   r8   r:   _count_star   s    zSQLExpr._count_star	condition	otherwiseNativeExprT | Nonec                 C  s   |   |||S r7   )rB   _when)r9   r   rM   r   r8   r8   r:   r      s   zSQLExpr._whenr8   
descending
nulls_lastrw   Sequence[str | NativeExprT]rx   
rows_start
int | Nonerows_endr   Sequence[bool] | Noner   c                C  r6   r7   r8   )r9   rz   rw   rx   r   r   r   r   r8   r8   r:   rv      s   
zSQLExpr._window_expression	func_name0Literal['sum', 'max', 'min', 'count', 'product']reverseboolc                  r\   )
Nr<   r   ru   r^   r4   r=   c                   s    fdd| D S )Nc              
     sF   g | ]}j  |jjgtj gtj d dqS )r   )r   r   r   )rv   r   rw   rx   lenry   )r   ru   r   r9   r8   r:   rT      s    	
z:SQLExpr._cum_window_func.<locals>.func.<locals>.<listcomp>r8   r}   r   r   r9   r~   r:   rY      s   	z&SQLExpr._cum_window_func.<locals>.funcr   r8   )r9   r   r   rY   r8   r   r:   _cum_window_func   s   zSQLExpr._cum_window_func$Literal['sum', 'mean', 'std', 'var']window_sizeintmin_samplesddofcenterc          	        s`   g d|r|d d }|d d }||  |n|d  dd fdd}|S )N)summeanstdvar      r   r<   r   ru   r^   r4   r=   c                   s   dv r nGdkrdkrd n<dv rdkrd n1dkr(dkr(d n&dkr3dkr3d	 nd
v rAd d}t |d d d}t ||j|jd fdd| D S )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: )rw   rx   r   r   c              
     sN   g | ]#} jd |fi kj |fi qS )count)r   rv   r   rI   ry   )func_r   r9   window_kwargsr8   r:   rT     s    
z>SQLExpr._rolling_window_func.<locals>.func.<locals>.<listcomp>)
ValueErrorrw   rx   )r<   ru   msgr   endr   r   r9   startsupported_funcs)r   r   r:   rY     s.   z*SQLExpr._rolling_window_func.<locals>.funcr   r8   )	r9   r   r   r   r   r   half	remainderrY   r8   r   r:   _rolling_window_func   s   	

$zSQLExpr._rolling_window_funcobjTypeIs[Self]c                 C  s
   t |dS )N__narwhals_expr__)hasattr)clsr   r8   r8   r:   rG   *     
zSQLExpr._is_exprtuple[int, ...]c                 C  s
   | j  S r7   )r*   _backend_versionrA   r8   r8   r:   r   .  r   zSQLExpr._backend_versionc                C  r6   r7   r8   )r   rz   r   r8   r8   r:   _alias_native2     zSQLExpr._alias_native.Callable[[Iterable[NativeExprT]], NativeExprT]exprsc                   sH   d fdd}d fd	d
} d }| ||t   t  |j|jdS )Nr<   r   r4   r=   c                   s    fddD }|gS )Nc                 3  s"    | ]}| D ]}|V  qqd S r7   r8   rK   _exprcolr<   r8   r:   	<genexpr>:  s     zHSQLExpr._from_elementwise_horizontal_op.<locals>.call.<locals>.<genexpr>r8   )r<   colsr   rY   r   r:   r/   9  s   
z5SQLExpr._from_elementwise_horizontal_op.<locals>.callr]   r^   c                   s    fddD }|gS )Nc                 3  s&    | ]}|  D ]}|V  q
qd S r7   )r0   r   r<   r]   r8   r:   r   @  s    zSSQLExpr._from_elementwise_horizontal_op.<locals>.window_function.<locals>.<genexpr>r8   )r<   r]   r   r   r   r:   r0   =  s   
z@SQLExpr._from_elementwise_horizontal_op.<locals>.window_functionr   )r0   r1   r2   r3   r.   r<   r   r4   r=   ra   )r   r   r)   r*   )r   rY   r   r/   r0   contextr8   r   r:   _from_elementwise_horizontal_op5  s   z'SQLExpr._from_elementwise_horizontal_opc                 C     |  dd |S )Nc                 S  r>   r7   )__eq__rz   rl   r8   r8   r:   rq   Q     
 z SQLExpr.__eq__.<locals>.<lambda>rm   r9   rl   r8   r8   r:   r   P     zSQLExpr.__eq__c                 C  r   )Nc                 S  r>   r7   )__ne__r   r8   r8   r:   rq   T  r   z SQLExpr.__ne__.<locals>.<lambda>r   r   r8   r8   r:   r   S  r   zSQLExpr.__ne__c                 C  r   )Nc                 S  r>   r7   )__add__r   r8   r8   r:   rq   W  r   z!SQLExpr.__add__.<locals>.<lambda>r   r   r8   r8   r:   r   V  r   zSQLExpr.__add__c                 C  r   )Nc                 S  r>   r7   )__sub__r   r8   r8   r:   rq   Z  r   z!SQLExpr.__sub__.<locals>.<lambda>r   r   r8   r8   r:   r   Y  r   zSQLExpr.__sub__c                 C     |  dd |dS )Nc                 S  s   ||  S r7   r8   r   r8   r8   r:   rq   ]      z"SQLExpr.__rsub__.<locals>.<lambda>literalrm   aliasr   r8   r8   r:   __rsub__\  r   zSQLExpr.__rsub__c                 C  r   )Nc                 S  r>   r7   )__mul__r   r8   r8   r:   rq   `  r   z!SQLExpr.__mul__.<locals>.<lambda>r   r   r8   r8   r:   r   _  r   zSQLExpr.__mul__c                 C  r   )Nc                 S  r>   r7   )__truediv__r   r8   r8   r:   rq   c  r   z%SQLExpr.__truediv__.<locals>.<lambda>r   r   r8   r8   r:   r   b  r   zSQLExpr.__truediv__c                 C  r   )Nc                 S  s   ||  S r7   r8   r   r8   r8   r:   rq   f  r   z&SQLExpr.__rtruediv__.<locals>.<lambda>r   r   r   r8   r8   r:   __rtruediv__e  r   zSQLExpr.__rtruediv__c                 C  r   )Nc                 S  r>   r7   )__floordiv__r   r8   r8   r:   rq   i  r   z&SQLExpr.__floordiv__.<locals>.<lambda>r   r   r8   r8   r:   r   h  r   zSQLExpr.__floordiv__c                 C  r   )Nc                 S  s   ||  S r7   r8   r   r8   r8   r:   rq   l  r   z'SQLExpr.__rfloordiv__.<locals>.<lambda>r   r   r   r8   r8   r:   __rfloordiv__k  s   zSQLExpr.__rfloordiv__c                 C  r   )Nc                 S  r>   r7   )__pow__r   r8   r8   r:   rq   q  r   z!SQLExpr.__pow__.<locals>.<lambda>r   r   r8   r8   r:   r   p  r   zSQLExpr.__pow__c                 C  r   )Nc                 S  s   ||  S r7   r8   r   r8   r8   r:   rq   t  r   z"SQLExpr.__rpow__.<locals>.<lambda>r   r   r   r8   r8   r:   __rpow__s  r   zSQLExpr.__rpow__c                 C  r   )Nc                 S  r>   r7   )__mod__r   r8   r8   r:   rq   w  r   z!SQLExpr.__mod__.<locals>.<lambda>r   r   r8   r8   r:   r   v  r   zSQLExpr.__mod__c                 C  r   )Nc                 S  s   ||  S r7   r8   r   r8   r8   r:   rq   z  r   z"SQLExpr.__rmod__.<locals>.<lambda>r   r   r   r8   r8   r:   __rmod__y  r   zSQLExpr.__rmod__c                 C  r   )Nc                 S  r>   r7   )__ge__r   r8   r8   r:   rq   }  r   z SQLExpr.__ge__.<locals>.<lambda>r   r   r8   r8   r:   r   |  r   zSQLExpr.__ge__c                 C  r   )Nc                 S  r>   r7   )__gt__r   r8   r8   r:   rq     r   z SQLExpr.__gt__.<locals>.<lambda>r   r   r8   r8   r:   r     r   zSQLExpr.__gt__c                 C  r   )Nc                 S  r>   r7   )__le__r   r8   r8   r:   rq     r   z SQLExpr.__le__.<locals>.<lambda>r   r   r8   r8   r:   r     r   zSQLExpr.__le__c                 C  r   )Nc                 S  r>   r7   )__lt__r   r8   r8   r:   rq     r   z SQLExpr.__lt__.<locals>.<lambda>r   r   r8   r8   r:   r     r   zSQLExpr.__lt__c                 C  r   )Nc                 S  r>   r7   )__and__r   r8   r8   r:   rq     r   z!SQLExpr.__and__.<locals>.<lambda>r   r   r8   r8   r:   r     r   zSQLExpr.__and__c                 C  r   )Nc                 S  r>   r7   )__or__r   r8   r8   r:   rq     r   z SQLExpr.__or__.<locals>.<lambda>r   r   r8   r8   r:   r     r   zSQLExpr.__or__c                   ,   d fdd}d fdd}  ||S )Nrz   r   r4   c                         d|  dS )Nbool_andTr   r   rI   rz   rA   r8   r:   f     zSQLExpr.all.<locals>.fr<   r   ru   r^   r=   c                       fdd| D S )Nc              
     0   g | ]} d | jdqS )r   Tr   rv   r   rw   rI   ry   r{   r8   r:   rT         z1SQLExpr.all.<locals>.window_f.<locals>.<listcomp>r8   r}   rA   r~   r:   r`        zSQLExpr.all.<locals>.window_frz   r   r4   r   r   rh   rf   r9   r   r`   r8   rA   r:   all     zSQLExpr.allc                   r   )Nrz   r   r4   c                   r   )Nbool_orFr   r   rA   r8   r:   r     r   zSQLExpr.any.<locals>.fr<   r   ru   r^   r=   c                   r   )Nc              
     r   )r  Fr   ry   r{   r8   r:   rT     r   z1SQLExpr.any.<locals>.window_f.<locals>.<listcomp>r8   r}   rA   r~   r:   r`     r   zSQLExpr.any.<locals>.window_fr   r   r   r   r8   rA   r:   any  r  zSQLExpr.anyc                         fddS )Nc                        d| S )Nmaxr   r   rA   r8   r:   rq     rr   zSQLExpr.max.<locals>.<lambda>rh   rA   r8   rA   r:   r       zSQLExpr.maxc                   r  )Nc                   r  )Nr   r  r   rA   r8   r:   rq     rr   zSQLExpr.mean.<locals>.<lambda>r  rA   r8   rA   r:   r     r	  zSQLExpr.meanc                   r  )Nc                   r  )Nmedianr  r   rA   r8   r:   rq     rr   z SQLExpr.median.<locals>.<lambda>r  rA   r8   rA   r:   r
    r	  zSQLExpr.medianfloat | Nonec                   s   d fdd}  |S )Nrz   r   r4   c                   s      d|  | S )Nisnan)r   r   rI   r   r   r8   r:   	_fill_nan  s   z#SQLExpr.fill_nan.<locals>._fill_nanr   rj   )r9   rM   r  r8   r   r:   fill_nan  s   
zSQLExpr.fill_nanc                   r  )Nc                   r  )Nminr  r   rA   r8   r:   rq     rr   zSQLExpr.min.<locals>.<lambda>r  rA   r8   rA   r:   r    r	  zSQLExpr.minc                   r  )Nc                   r  )Nr   r  r   rA   r8   r:   rq     rr   zSQLExpr.count.<locals>.<lambda>r  rA   r8   rA   r:   r     r	  zSQLExpr.countc                   r   )Nrz   r   r4   c                   r   )Nr   r   r   r   rA   r8   r:   r     r   zSQLExpr.sum.<locals>.fr<   r   ru   r^   r=   c                   r   )Nc              
     r   )r   r   r   ry   r{   r8   r:   rT     r   z1SQLExpr.sum.<locals>.window_f.<locals>.<listcomp>r8   r}   rA   r~   r:   r`     r   zSQLExpr.sum.<locals>.window_fr   r   r   r   r8   rA   r:   r     r  zSQLExpr.sumc                   r  )Nc                   r  )Nabsr  r   rA   r8   r:   rq     rr   zSQLExpr.abs.<locals>.<lambda>r  rA   r8   rA   r:   r    r	  zSQLExpr.abslower_bound.Self | NumericLiteral | TemporalLiteral | Noneupper_boundc                   sf   d fdd}d fd	d
}d fdd}|d u r  j ||dS |d u r+ j ||dS  j |||dS )Nrz   r   r  r   r4   c                        d| |S )Ngreatestr  )rz   r  rA   r8   r:   _clip_lower  r   z!SQLExpr.clip.<locals>._clip_lowerr  c                   r  )Nleastr  )rz   r  rA   r8   r:   _clip_upper  r   z!SQLExpr.clip.<locals>._clip_upperc                   s     d  d| ||S )Nr  r  r  )rz   r  r  rA   r8   r:   
_clip_both  s   z SQLExpr.clip.<locals>._clip_both)r  )r  )r  r  )rz   r   r  r   r4   r   )rz   r   r  r   r4   r   )rz   r   r  r   r  r   r4   r   r  )r9   r  r  r  r  r  r8   rA   r:   clip  s   zSQLExpr.clipc                   r  )Nc                   r  )Nisnullr  r   rA   r8   r:   rq     rr   z!SQLExpr.is_null.<locals>.<lambda>r  rA   r8   rA   r:   is_null  r	  zSQLExpr.is_nulldecimalsc                   s     fddS )Nc                   s    d|  S )Nround)r   rI   r   r  r9   r8   r:   rq      s    zSQLExpr.round.<locals>.<lambda>r  )r9   r  r8   r   r:   r       zSQLExpr.roundc                   s   d fdd}  |S )Nrz   r   r4   c                   s*     |  dk  td d| S )Nr   nansqrt)r   rI   floatr   r   rA   r8   r:   _sqrt  s   "zSQLExpr.sqrt.<locals>._sqrtr   r  )r9   r%  r8   rA   r:   r#    s   
zSQLExpr.sqrtc                   r  )Nc                   r  )Nexpr  r   rA   r8   r:   rq     rr   zSQLExpr.exp.<locals>.<lambda>r  rA   r8   rA   r:   r&    r	  zSQLExpr.expbaser$  c                   s   d fdd} |S )Nrz   r   r4   c                   s`   j }| dk td| dktdt|d| |d S )Nr   r"  z-inflog)r   r   rI   r$  rk   truediv)rz   Fr'  r9   r8   r:   _log  s   zSQLExpr.log.<locals>._logr   r  )r9   r'  r,  r8   r+  r:   r(    s   
zSQLExpr.logc                C     |  | jd|dS )Nr   r   rf   r   r9   r   r8   r8   r:   cum_sum     zSQLExpr.cum_sumc                C  r-  )Nr  r.  r/  r0  r8   r8   r:   cum_max!  r2  zSQLExpr.cum_maxc                C  r-  )Nr  r.  r/  r0  r8   r8   r:   cum_min$  r2  zSQLExpr.cum_minc                C  r-  )Nr   r.  r/  r0  r8   r8   r:   	cum_count'  r2  zSQLExpr.cum_countc                C  r-  )Nproductr.  r/  r0  r8   r8   r:   cum_prod*  r!  zSQLExpr.cum_prodc                C     |  | jd|||dS )Nr   r   rf   r   r9   r   r   r   r8   r8   r:   rolling_sum0     zSQLExpr.rolling_sumc                C  r8  )Nr   r9  r:  r;  r8   r8   r:   rolling_mean5  r=  zSQLExpr.rolling_meanc             	   C     |  | jd||||dS )Nr   r   r   r:  r9   r   r   r   r   r8   r8   r:   rolling_var:  
   
zSQLExpr.rolling_varc             	   C  r?  )Nr   r@  r:  rA  r8   r8   r:   rolling_stdC  rC  zSQLExpr.rolling_stdc                      d	 fdd}  |S )
Nr<   r   ru   r^   r4   r=   c                   s&   j  j fdd| D S )Nc              	     s*   g | ]}t | d |jjqS lag)rk   subrw   rx   ry   r*  ru   windowr8   r:   rT   S  s    z.SQLExpr.diff.<locals>.func.<locals>.<listcomp>)r   rv   r}   rA   rI  r:   rY   N  s
   zSQLExpr.diff.<locals>.funcr   rf   r9   rY   r8   rA   r:   diffM  s   

zSQLExpr.diffnc                   s   d	 fdd} |S )
Nr<   r   ru   r^   r4   r=   c                   s    fdd| D S )Nc              	     s(   g | ]} d | j jqS rF  )rv   r   rw   rx   ry   )ru   rN  r9   r8   r:   rT   ^  s    z/SQLExpr.shift.<locals>.func.<locals>.<listcomp>r8   r}   rN  r9   r~   r:   rY   [  s   zSQLExpr.shift.<locals>.funcr   rK  )r9   rN  rY   r8   rO  r:   shiftZ  s   

zSQLExpr.shiftc                   rE  )
Nr<   r   ru   r^   r4   r=   c                   r   )Nc                   s8   g | ]} d g  j|R  jdkqS )
row_numberr   )rv   r   rw   rx   rI   ry   r{   r8   r:   rT   l  s    z;SQLExpr.is_first_distinct.<locals>.func.<locals>.<listcomp>r8   r}   rA   r~   r:   rY   h  s   z'SQLExpr.is_first_distinct.<locals>.funcr   rK  rL  r8   rA   r:   is_first_distinctg  s   
zSQLExpr.is_first_distinctc                   rE  )
Nr<   r   ru   r^   r4   r=   c                   r   )Nc              
     sV   g | ]'}j d g  j|R  jdgt j dgt j ddkqS )rQ  Tr   r   )rv   r   rw   rx   r   rI   ry   r{   r8   r:   rT   |  s    	z:SQLExpr.is_last_distinct.<locals>.func.<locals>.<listcomp>r8   r}   rA   r~   r:   rY   y  s   	z&SQLExpr.is_last_distinct.<locals>.funcr   rK  rL  r8   rA   r:   is_last_distinctx  s   
zSQLExpr.is_last_distinctmethodr    c                  s|   dv r
 dndkr dn d		ddfdd d fdd}d fdd}||S )N>   r  r  averagerankdense
dense_rankrQ  r8   rz   r   rw   r   rx   r   Sequence[bool]r   r4   c                  s     }|| g|R ||d}dg || R i}j}j}	dkr<tt| fi |||fi |d}
n-dkrat| fi |tt||fi |dd}
n| fi |}
|	d|  |
S )N)rw   rx   r   r   rw   r  r   rU  g       @r  )	r   rv   r   rk   rH  addrI   r)  r   )rz   rw   rx   r   r   
count_exprr   count_window_kwargsrJ  r*  	rank_expr)rY   rT  r9   r8   r:   _rank  s6   
zSQLExpr.rank.<locals>._rankc                   s    | gdgdS )NTr   r8   r   )r^  r   r8   r:   _unpartitioned_rank  r	  z)SQLExpr.rank.<locals>._unpartitioned_rankr<   r   ru   r^   r=   c                   s    fdd| D S )Nc                   sF   g | ]} |j jgd gtj  dgd gtj  dqS )FTr   )rw   rx   r   ry   )r^  r   ru   r8   r:   rT     s    z;SQLExpr.rank.<locals>._partitioned_rank.<locals>.<listcomp>r8   r}   )r^  r   r9   r~   r:   _partitioned_rank  s   z'SQLExpr.rank.<locals>._partitioned_rank)r8   r8   )rz   r   rw   r   rx   r   r   rY  r   rY  r4   r   r   r   )r   rh   rf   )r9   rT  r   r_  r`  r8   )r^  r   rY   rT  r9   r:   rV    s   
&
zSQLExpr.rankc                   s<   dfdd d fdd	}d fdd} ||S )Nrz   r   rw   str | NativeExprTr4   c                   s"       | g|R  dkS )Nr   )rv   r   rI   )rz   rw   rA   r8   r:   
_is_unique  s
   z%SQLExpr.is_unique.<locals>._is_uniquec                   s    | S r7   r8   r   )rb  r8   r:   _unpartitioned_is_unique  s   z3SQLExpr.is_unique.<locals>._unpartitioned_is_uniquer<   r   ru   r^   r=   c                   s"    j rJ  fdd| D S )Nc                   s   g | ]} |gj R  qS r8   )rw   ry   )rb  ru   r8   r:   rT     s    zESQLExpr.is_unique.<locals>._partitioned_is_unique.<locals>.<listcomp>r|   r}   rb  r9   r~   r:   _partitioned_is_unique  s   
z1SQLExpr.is_unique.<locals>._partitioned_is_unique)rz   r   rw   ra  r4   r   r   r   r   )r9   rc  re  r8   rd  r:   	is_unique  s   
zSQLExpr.is_uniqueSequence[str]c                   s.   d fdd}j |jjjjdS )	Nr<   r   r4   r=   c                   s    | t S r7   )r0   r   r   rx   rw   r9   r8   r:   rY     r	  zSQLExpr.over.<locals>.funcrd   r   )re   r&   r(   r)   r*   )r9   rw   rx   rY   r8   rh  r:   over  s   zSQLExpr.overkeepr   c                  s6   |dkrd| d j  d}t|  fddS )Nr  z`Expr.mode(keep='z#')` is not implemented for backend z3

Hint: Use `nw.col(...).mode(keep='any')` instead.c                   r  )Nmoder  r   rA   r8   r:   rq     rr   zSQLExpr.mode.<locals>.<lambda>)r*   NotImplementedErrorrh   )r9   rj  r   r8   rA   r:   rk    s
   zSQLExpr.modeSQLExprStringNamespace[Self]c                 C  r6   r7   r8   rA   r8   r8   r:   r     r   zSQLExpr.strSQLExprDateTimeNamesSpace[Self]c                 C  r6   r7   r8   rA   r8   r8   r:   dt  r   z
SQLExpr.dtr   arg_maxarg_minarg_truecat
drop_nullsewm_meangather_everyheadmap_batchesreplace_strictsorttailsampleuniquer7   )r/   r#   r0   r,   r1   r%   r2   r'   r3   r   r.   r   r4   r5   r   )r4   r@   )r/   rC   rD   rE   r4   r#   )r/   rC   rD   rE   r4   r[   )r0   r[   r4   r   )r/   rC   rD   rE   r4   r   )rk   rC   rl   rE   r4   r   )rY   r'   r4   r   )r4   r[   )r   r   r   r   r4   r   )rM   r   r4   r   r   )r4   r   )r   r   rM   r   r   r   r4   r   )r8   r8   NN)rz   r   rw   r   rx   r   r   r   r   r   r   r   r   r   r4   r   )r   r   r   r   r4   r[   )r   r   r   r   r   r   r   r   r   r   r4   r[   )r   rE   r4   r   )r4   r   )rz   r   r   r   r4   r   )rY   r   r   r   r4   r   )rl   r   r4   r   )r4   r   )rM   r  r4   r   )r  r  r  r  r4   r   )r  r   r4   r   )r'  r$  r4   r   )r   r   r4   r   )r   r   r   r   r   r   r4   r   )
r   r   r   r   r   r   r   r   r4   r   )rN  r   r4   r   )rT  r    r   r   r4   r   )rw   r   rx   rg  r4   r   )rj  r   r4   r   )r4   rm  )r4   rn  )e__name__
__module____qualname____annotations__r   DUCKDBr;   r?   rB   rZ   rb   rf   rh   rj   rm   rt   propertyr0   r   rI   r   r   r   rv   r   r   classmethodrG   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#  r&  r(  r1  r3  r4  r5  r7  r<  r>  rB  rD  rM  rP  rR  rS  rV  rf  ri  rk  r   ro  r   rp  rq  rr  rs  rt  ru  rv  rw  rx  ry  rz  r{  r|  r}  r8   r8   r8   r:   r"   )   s   
 
9	
Er"   )1
__future__r   operatorrk   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"   r8   r8   r8   r:   <module>   s&    &	