
    /_iހ                    6   U d dl mZ d dlmZ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 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mZmZm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z) d,dZ*d-dZ+	 	 	 	 d.dZ,d/dZ-	 	 	 	 	 	 	 	 d0dZ. G d de      Z/d1dZ0 G d de      Z1 G d d      Z2 G d d      Z3e/jh                  e3jj                  e/jl                  e3jn                  e/jp                  e3jr                  e/jt                  e3jn                  e/jv                  e3jx                  e/jz                  e3j|                  e/j~                  e3j                  e/j                  e3j                  e/j                  e3jn                  i	ZDdeEd<   e/jh                  e3j                  e/jp                  e3j                  e/j                  e3j                  e/j                  e3j                  e/j                  e3j                  e/j                  e3j                  e/j                  e3j                  e/j                  e3j                  iZTdeEd<   	 	 	 	 	 	 	 	 	 	 d2d ZU	 	 	 	 	 	 d3d!ZVd"d#d$d%	 	 	 	 	 	 	 	 	 d4d&ZW	 	 	 	 	 	 	 	 	 	 d5d'ZXd6d(ZYd7d)ZZ	 	 	 	 	 	 	 	 d8d*Z[	 	 	 	 	 	 d9d+Z\y#):    )annotations)Enumauto)TYPE_CHECKINGAnyCallableLiteralcast)
zip_strict)is_numpy_array_1d)InvalidIntoExprErrorInvalidOperationErrorMultiOutputExpressionError)IteratorSequence)NeverTypeIs)CompliantExprCompliantFrameT)
AliasNamesCompliantExprAnyCompliantFrameAnyCompliantNamespaceAny	EvalNamesExprSeries)IntoExprNonNestedLiteral_1DArrayc                &    ddl m} t        | |      S )'Check whether `obj` is a Narwhals Expr.r   r   )narwhals.exprr   
isinstance)objr   s     [/var/www/html/land_sniper/venv/lib/python3.12/site-packages/narwhals/_expression_parsing.pyis_exprr(   $   s    "c4      c                &    ddl m} t        | |      S )r#   r   r   )narwhals.seriesr   r%   )r&   r   s     r'   	is_seriesr,   +   s    &c6""r)   c                      d fd}|S )Nc                2    d   j                  |       d d S Nr      )_evaluate_output_names)dfexprss    r'   evaluate_output_namesz<combine_evaluate_output_names.<locals>.evaluate_output_names7   s    Qx..r22A66r)   )r2   r   returnSequence[str] )r3   r4   s   ` r'   combine_evaluate_output_namesr8   2   s    
7 ! r)   c                 4      d   j                   y d fd}|S )Nr   c                2    d   j                  |       d d S r/   _alias_output_names)namesr3   s    r'   alias_output_namesz6combine_alias_output_names.<locals>.alias_output_namesC   s    Qx++E22A66r)   )r=   r6   r5   r6   r;   )r3   r>   s   ` r'   combine_alias_output_namesr?   =   s%     Qx##+7 r)   c                   | j                  |      }| j                  |n| j                  |      }|rR| j                  j                  j	                         r.t        t        ||      D cg c]  \  }}||vr||f c}} \  }}||fS c c}}w N)r1   r<   	_metadataexpansion_kindis_multi_unnamedr   )exprr2   excludeoutput_namesaliasesxaliass          r'   !evaluate_output_names_and_aliasesrK   I   s     ..r2L ##+ 	%%l3 
 4>>00AAC * !+< AAuG# E
!
g   s   +B	
c                  F   e Zd ZdZ e       Z	  e       Z	  e       Z	  e       Z	  e       Z		  e       Z
	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	  e       Z	 edd       Zedd       Zedd       Zy)ExprKindz6Describe which kind of expression we are dealing with.c                    | t         j                  t         j                  t         j                  t         j                  hv S rA   )rM   ORDERABLE_WINDOWWINDOWORDERABLE_AGGREGATIONORDERABLE_FILTRATIONselfs    r'   is_orderablezExprKind.is_orderable   s8     %%OO**))	
 
 	
r)   c           
        | t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  h	v S rA   )
rM   ALLCOLELEMENTWISEEXCLUDELITERALNTHSELECTORSERIES	WHEN_THENrS   s    r'   is_elementwisezExprKind.is_elementwise   s_     LLLL  LLOO

 

 
	
r)   c                d    | t         j                  t         j                  t         j                  hv S rA   )rM   AGGREGATIONr[   rQ   rS   s    r'   is_scalar_likezExprKind.is_scalar_like   s/      **
 
 	
r)   Nr5   bool)__name__
__module____qualname____doc__r   r[   rb   rQ   rY   rO   rP   
FILTRATIONrR   OVERrX   r\   rZ   rW   r]   r_   r^   propertyrU   r`   rc   r7   r)   r'   rM   rM   ]   s    @fG&KY FX&KgvHVFNJG6=6D5
&C(
&C(fG,
&C(vH>IPVF3
 
 
 
 
 
r)   rM   c                .    | j                   j                  S rA   )rB   rc   )r&   s    r'   rc   rc      s    =='''r)   c                  X    e Zd ZdZ e       Z	  e       Z	  e       Z	 ddZddZ	ddZ
y)ExpansionKindz8Describe what kind of expansion the expression performs.c                &    | t         j                  u S rA   ro   MULTI_UNNAMEDrS   s    r'   rD   zExpansionKind.is_multi_unnamed   s    }2222r)   c                F    | t         j                  t         j                  hv S rA   )ro   MULTI_NAMEDrr   rS   s    r'   is_multi_outputzExpansionKind.is_multi_output   s    11=3N3NOOOr)   c                    | t         j                  u r"|t         j                  u rt         j                  S d|  d| d}t        |      )Nz+Unsupported ExpansionKind combination, got z and z, please report a bug.)ro   rr   AssertionError)rT   othermsgs      r'   __and__zExpansionKind.__and__   sI    =...5M<W<W3W ...;D6ugMcdS!!r)   Nrd   )rx   ro   r5   z$Literal[ExpansionKind.MULTI_UNNAMED])rf   rg   rh   ri   r   SINGLErt   rr   rD   ru   rz   r7   r)   r'   ro   ro      s3    BVF9&K!FM'3P"r)   ro   c                  v    e Zd ZdZddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZ	 	 	 	 	 	 ddZdd	Z	dd
Z
y)ExprNodea  An operation to create or modify an expression.

    Parameters:
        kind: ExprKind of operation.
        name: Name of function, as defined in the compliant protocols.
        exprs: Expressifiable arguments to function.
        str_as_lit: Whether to interpret strings as literals when they
            are present in `exprs`.
        allow_multi_output: Whether to allow any of `exprs` to be multi-output.
        kwargs: Other (non-expressifiable) arguments to function.
    F)
str_as_litallow_multi_outputc              t    || _         || _        || _        || _        || _        || _        d | _        d | _        y rA   )kindnamer3   kwargsr~   r   _is_orderable_cached_is_elementwise_cached)rT   r   r   r~   r   r3   r   s          r'   __init__zExprNode.__init__   sA     #		<A
&, *(: 26!37#r)   c                   | j                   dk(  r+dj                  d | j                  d   D              }d| dS g }dj                  d | j                  D              }dj                  d | j                  j	                         D              }| j                  r|j                  |       | j                  r|j                  |       | j                    d	dj                  |       dS )
Ncolz, c              3  2   K   | ]  }t        |        y wrA   str.0rI   s     r'   	<genexpr>z$ExprNode.__repr__.<locals>.<genexpr>   s     Cc!fC   r=   zcol()c              3  2   K   | ]  }t        |        y wrA   r   r   s     r'   r   z$ExprNode.__repr__.<locals>.<genexpr>   s     9c!f9r   c              3  0   K   | ]  \  }}| d |   yw)=Nr7   )r   keyvalues      r'   r   z$ExprNode.__repr__.<locals>.<genexpr>   s     WZS%3%q 0Ws   ()r   joinr   r3   itemsappend)rT   r=   arg_str	expr_reprkwargs_reprs        r'   __repr__zExprNode.__repr__   s    99IICdkk'.BCCE%?"II9djj99	iiW4;;CTCTCVWW::NN9%;;NN;'))Adii0133r)   c                    | j                   | j                  | j                  | j                  | j                  | j
                  dS )Nr   r   r3   r   r~   r   r   rS   s    r'   as_dictzExprNode.as_dict  s:     IIIIZZkk//"&"9"9
 	
r)   c                     | j                   | j                  | j                  g| j                  d| j                  i|S )Nr~   )	__class__r   r   r3   r~   )rT   r   s     r'   _with_kwargszExprNode._with_kwargs  sB    t~~IItyy
#'::
:>//
MS
 	
r)   c                   g }|j                   d   }|j                   d   }| j                  D ]  }t        |      s|j                  |        |r=t	        d |j
                  D              r!|j                  |j                  |             _|r=t        d |j
                  D              s!|j                  |j                  |             |j                  |        || _        y )Norder_bypartition_byc              3  <   K   | ]  }|j                           y wrA   rU   r   	expr_nodes     r'   r   z9ExprNode._push_down_over_node_in_place.<locals>.<genexpr>  s      ,-6	&&(,   c              3  <   K   | ]  }|j                           y wrA   r`   r   s     r'   r   z9ExprNode._push_down_over_node_in_place.<locals>.<genexpr>!  s      4/8	((*4r   )r   r3   r(   r   any_nodes_with_over_nodeall)rT   	over_nodeover_node_without_order_byr3   over_node_order_byover_node_partition_byrE   s          r'   _push_down_over_node_in_placez&ExprNode._push_down_over_node_in_place  s     46 '--j9!*!1!1.!AJJ 	#D4=T"# ,:>++, ) T11)<=' 4<@KK4 1 T112LMN T"	# 
r)   c                    | j                   _| j                  j                  rd| _         | j                   S t        d | j                  D              rd| _         | j                   S d| _         | j                   S )NTc              3  j   K   | ]+  }t        |      rt        d  |j                  D               - yw)c              3  <   K   | ]  }|j                           y wrA   r   r   nodes     r'   r   z2ExprNode.is_orderable.<locals>.<genexpr>.<genexpr>1  s     @DD%%'@r   Nr(   r   r   r   rE   s     r'   r   z(ExprNode.is_orderable.<locals>.<genexpr>0  s.      4= @DKK@@   13F)r   r   rU   r   r3   rS   s    r'   rU   zExprNode.is_orderable*  s|    $$, yy%%,0) (((   JJ 
 -1) ((( -2)(((r)   c                    | j                   _| j                  j                  sd| _         | j                   S t        d | j                  D              rd| _         | j                   S d| _         | j                   S )NFc              3  j   K   | ]+  }t        |      rt        d  |j                  D               - yw)c              3  >   K   | ]  }|j                            y wrA   r   r   s     r'   r   z4ExprNode.is_elementwise.<locals>.<genexpr>.<genexpr>A  s     F$++--Fs   Nr   r   s     r'   r   z*ExprNode.is_elementwise.<locals>.<genexpr>@  s.      4= F$++FFr   T)r   r   r`   r   r3   rS   s    r'   r`   zExprNode.is_elementwise:  s|    &&. 99++.3+ ***   JJ 
 /4+ *** /3+***r)   N)r   rM   r   r   r3   zIntoExpr | NonNestedLiteralr~   re   r   re   r   r   r5   Noner5   r   )r5   zdict[str, Any])r   r   r5   r}   )r   r}   r   r}   r5   r   rd   )rf   rg   rh   ri   r   r   r   r   r   rU   r`   r7   r)   r'   r}   r}      s    
$ !#(88 8
 ,8 8 !8 8 
8*4	


!?G	0) +r)   r}   c                     e Zd ZdZdZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZd#d	Zd$d
Zd%dZe		 	 	 	 	 	 d&d       Z
	 	 	 	 	 	 	 	 d'dZe	d(d       Ze	d(d       Ze	d(d       Ze	d(d       Ze	d(d       Ze	d(d       Ze	d(d       Ze		 	 	 	 	 	 d&d       Zed)d       Zd*dZ	 	 	 	 	 	 d*dZ	 	 	 	 	 	 	 	 d'dZd*dZ	 	 	 	 	 	 d*dZd*dZ	 	 	 	 	 	 d*dZd*dZ	 	 	 	 	 	 d&dZ	 	 	 	 	 	 d*d Zd%d!Z y)+ExprMetadataaI  Expression metadata.

    Parameters:
        expansion_kind: What kind of expansion the expression performs.
        has_windows: Whether it already contains window functions.
        is_elementwise: Whether it can operate row-by-row without context
            of the other rows around it.
        is_literal: Whether it is just a literal wrapped in an expression.
        is_scalar_like: Whether it is a literal or an aggregation.
        n_orderable_ops: The number of order-dependent operations. In the
            lazy case, this number must be `0` by the time the expression
            is evaluated.
        preserves_length: Whether the expression preserves the input length.
        current_node: The current ExprNode in the linked list.
        prev: Reference to the previous ExprMetadata in the linked list (None for root).
    )	current_noderC   has_windowsr`   
is_literalrc   n_orderable_opspreserves_lengthprevFr   TN)r   r   r   r`   rc   r   r   c                   |r|sJ || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y rA   )	rC   r   r   r`   r   rc   r   r   r   )
rT   rC   r   r   r   r`   rc   r   r   r   s
             r'   r   zExprMetadata.__init__i  sU     !!>-;!,$3$2&6$2 *&2)-	r)   c               6    d| j                   }t        |      )NzCannot subclass )rf   	TypeError)clsargskwdsry   s       r'   __init_subclass__zExprMetadata.__init_subclass__  s      01nr)   c                   t        t        t        | j                                           }d| j                   d| j                   d| j
                   d| j                   d| j                   d| j                   d| j                   d| d	S )
Nz ExprMetadata(
  expansion_kind: z,
  has_windows: z,
  n_orderable_ops: z,
  is_elementwise: z,
  preserves_length: z,
  is_scalar_like: z,
  is_literal: z,
  nodes: z,
))
tuplereversediter_nodes_reversedrC   r   r   r`   r   rc   r   )rT   nodess     r'   r   zExprMetadata.__repr__  s    huT%=%=%?@AB!!%!4!4 5 6"../ 0""&"6"6!7 8!!%!4!4 5 6##'#8#8"9 :!!%!4!4 5 6!__- .w 		
r)   c              #  P   K   | }||j                    |j                  }|yyw)z/Iterate through all nodes from current to root.Nr   r   )rT   currents     r'   r   z ExprMetadata.iter_nodes_reversed  s.     '+!&&&llG !s   !&&c                4    t        |j                     |g| S rA   )KIND_TO_METADATA_CONSTRUCTORr   r   r   compliant_exprss      r'   	from_nodezExprMetadata.from_node  s     ,DII6tNoNNr)   c                8    t        |j                     | ||g| S rA   )KIND_TO_METADATA_UPDATERr   rT   r   compliant_exprcompliant_expr_argss       r'   	with_nodezExprMetadata.with_node  s)     (		2$
)<
 	
r)   c                :     | t         j                  ddd|d       S )NFT)r`   r   rc   r   r   ro   r{   r   r   s     r'   from_aggregationzExprMetadata.from_aggregation  s'       "
 	
r)   c           	     <     | t         j                  dddd|d       S )NTF)r`   r   r   rc   r   r   r   r   s     r'   from_literalzExprMetadata.from_literal  s*      "
 	
r)   c                4     | t         j                  |d       S Nr   r   r   s     r'   from_serieszExprMetadata.from_series  s    =''dFFr)   c                    t        |j                  d         dk(  r | t        j                  |d       S | j	                  |      S )Nr=   r0   r   lenr   ro   r{   from_selector_multi_namedr   s     r'   from_colzExprMetadata.from_col  sH    
 4;;w'(A- $$4dC	
 ..t4	
r)   c                    t        |j                  d         dk(  r | t        j                  |d       S | j	                  |      S )Nindicesr0   r   r   r   s     r'   from_nthzExprMetadata.from_nth  sH     4;;y)*a/ $$4dC	
 ..t4	
r)   c                4     | t         j                  |d       S r   )ro   rt   r   s     r'   r   z&ExprMetadata.from_selector_multi_named  s     =,,4dKKr)   c                4     | t         j                  |d       S r   rq   r   s     r'   from_selector_multi_unnamedz(ExprMetadata.from_selector_multi_unnamed  s     =..TMMr)   c                    t        |d|d dS )NTto_single_outputr   r   )combine_metadatar   s      r'   from_elementwisezExprMetadata.from_elementwise  s      t$T
 	
r)   c                :    | j                    xr | j                   S rA   )r   rc   rS   s    r'   is_filtrationzExprMetadata.is_filtration  s    (((D1D1D-DDr)   c                    | j                   rd}t        |      t        | j                  | j                  | j
                  dddd|| 	      S )N4Can't apply aggregations to scalar-like expressions.FTr   r   r   r`   rc   r   r   r   rc   r   r   rC   r   r   rT   r   _cery   s       r'   with_aggregationzExprMetadata.with_aggregation  sU    HC',,(( 00" 

 
	
r)   c                    | j                   rd}t        |      t        | j                  | j                  | j
                  dz   dddd|| 	      S )Nr  r0   FTr  r  r  s       r'   with_orderable_aggregationz'ExprMetadata.with_orderable_aggregation  s\     HC',,(( 0014" 

 
	
r)   c                8    t        |g|d||j                  dS )NFr   )r   rB   r   s       r'   with_elementwisezExprMetadata.with_elementwise  s2      
 
 #))
 	
r)   c                    | j                   rd}t        |      t        | j                  | j                  | j
                  | j                  ddd|| 	      S )Nz;Can't apply window (e.g. `rank`) to scalar-like expression.Fr  rc   r   r   rC   r   r   r   r  s       r'   with_windowzExprMetadata.with_window  s]    OC',,(( !00!22  
 	
r)   c                    | j                   rd}t        |      t        | j                  | j                  | j
                  dz   | j                  ddd|| 	      S )NzNCan't apply orderable window (e.g. `diff`, `shift`) to scalar-like expression.r0   Fr  r  r  s       r'   with_orderable_windowz"ExprMetadata.with_orderable_window2  sb     bC',,(( 0014!22  

 
	
r)   c                   | j                   rd}t        |      | j                  s| j                  rd}t        |      | j                  }|s@t        | j                               j                  t        j                  urd}t        |      t        | j                               j                  j                  r
|dkD  r|dz  }t        | j                  d|dddd|| 	      S )	NCannot nest `over` statements.oCannot use `over` on expressions which are elementwise
(e.g. `abs`) or which change length (e.g. `drop_nulls`).aP  Cannot use `order_by` in `over` on expression which isn't orderable.
If your expression is orderable, then make sure that `over(order_by=...)`
comes immediately after the order-dependent expression.

Hint: instead of
  - `(nw.col('price').diff() + 1).over(order_by='date')`
write:
  + `nw.col('price').diff().over(order_by='date') + 1`
r   r0   TFr  )r   r   r`   r   r   nextop_nodes_reversedr   rM   rP   rU   r   rC   )rT   r   r  ry   r   s        r'   with_ordered_overzExprMetadata.with_ordered_overE  s    2C',,$"4"4K  (,,..T++-.338??JK  (,,&&()..;;RS@Sq O+!  

 
	
r)   c                    | j                   rd}t        |      | j                  s| j                  rd}t        |      t	        | j
                  d| j                  dddd|| 	      S )Nr  r  TFr  )r   r   r`   r   r   rC   r   r  s       r'   with_partitioned_overz"ExprMetadata.with_partitioned_overl  sz     2C',,$"4"4K  (,, 00!  

 
	
r)   c                    |j                   d   r| j                  ||      S |j                   d   sd}t        |      | j                  ||      S )Nr   r   z?At least one of `partition_by` or `order_by` must be specified.)r   r  r   r  r  s       r'   	with_overzExprMetadata.with_over  sP    ;;z"))$44{{>*SC',,))$44r)   c                    | j                   rd}t        |      t        d |D              }t        d |D              }t	        | j
                  ||dddd|| 	      S )NECan't apply filtration (e.g. `drop_nulls`) to scalar-like expression.c              3  H   K   | ]  }|j                   j                    y wrA   )rB   r   r   s     r'   r   z/ExprMetadata.with_filtration.<locals>.<genexpr>  s      RQ!8!8 R    "c              3  H   K   | ]  }|j                   j                    y wrA   )rB   r   r   s     r'   r   z/ExprMetadata.with_filtration.<locals>.<genexpr>  s     $ZQQ[[%@%@$Zr  Fr  )rc   r   r   sumr   rC   )rT   r   r   ry   result_has_windowsresult_n_orderable_opss         r'   with_filtrationzExprMetadata.with_filtration  sm     YC',,  R/ RR!$$Z/$Z!Z*2"  

 
	
r)   c                    | j                   rd}t        |      t        | j                  | j                  | j
                  dz   dddd|| 	      S )Nr  r0   Fr  r  r  s       r'   with_orderable_filtrationz&ExprMetadata.with_orderable_filtration  s\     YC',,(( 0014"  

 
	
r)   c              #  v   K   | j                         D ]"  }|j                  j                  d      r| $ y w)N)zname.rJ   )r   r   
startswith)rT   r   s     r'   r  zExprMetadata.op_nodes_reversed  s9     ,,. 	Dyy##$67J		s   79)rC   ro   r   re   r   intr   re   r`   re   rc   re   r   re   r   r}   r   ExprMetadata | Noner5   r   )r   r   r   r   r5   r   r   )r5   zIterator[ExprNode])r   r}   r   r   r5   r   )r   r}   r   r   r   r   r5   r   )r   r}   r5   r   rd   )r   r}   r  r   r5   r   )!rf   rg   rh   ri   	__slots__r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   r   rl   r   r  r	  r  r  r  r  r  r  r#  r%  r  r7   r)   r'   r   r   K  s   "
I  " !%#$ $(.%. 	.
 . . . . . . ". 
.2
# OO/?O	O O


 )
 /	

 

 
 
 	
 	
 G G 
 
 
 
 L L N N 

/?
	
 
 E E
 

#3
	
&

 )
 /	

 


&

#3
	
&%
N

#3
	
05

0@
	
(

#3
	
$r)   r   z2dict[ExprKind, Callable[[ExprNode], ExprMetadata]]r   z+dict[ExprKind, Callable[..., ExprMetadata]]r   c                >   d}t         j                  }d}d}d}d}	d}
d}t        |      D ]  \  }}|j                  }|J |j                  j                         r|j                  }| s|dkD  r||z  n|}||j                  z  }||j                  z  }||j                  z  }|	|j                  z  }	|
|j                  z  }
||j                  z  }|t        |j                        z  } |dkD  rd}t        |      |r|rd}t        |      t        |||||	|
|||	      S )aI  Combine metadata from `args`.

    Arguments:
        compliant_exprs: Expression arguments.
        to_single_output: Whether the result is always single-output, regardless
            of the inputs (e.g. `nw.sum_horizontal`).
        current_node: The current node being added.
        prev: ExprMetadata of previous node.
    r   FTr0   zXLength-changing expressions can only be used in isolation, or followed by an aggregationzVCannot combine length-changing expressions with length-preserving ones or aggregationsr  )ro   r{   	enumeraterB   rC   ru   r   r   r   r`   rc   r   r(  r   r   r   )r   r   r   r   n_filtrationsresult_expansion_kindr!  r"  result_preserves_lengthresult_is_elementwiseresult_is_scalar_likeresult_is_literalicemetadatarC   ry   s                    r'   r   r     sp    M)00#  ?+ 52<<###""224%44N#>?!e)N: & 	h222(":"::8#<#<<!8!88!8!88X000X3344!5" qh#C((=f#C((&.0,,$!
 
r)   c                J    t        d |D              sd|  d}t        |      y )Nc              3  H   K   | ]  }|j                   j                    y wrA   )rB   r   r   s     r'   r   z4check_expressions_preserve_length.<locals>.<genexpr>  s     :q{{++:r  zBExpressions which aggregate or change length cannot be passed to 'z'.)r   r   )function_namer   ry   s      r'   !check_expressions_preserve_lengthr:    s3     :T::RS`Raacd#C(( ;r)   FNT)r~   backendallow_literalc               2   ddl m}m}m} t	        | t
              r
|s ||       S t        |       r |d| |      j                         S t        |       r| j                         S t        |       r| S |st        j                  t        |              ||       S )Nr   )r   lit
new_series )r;  )narwhals.functionsr   r>  r?  r%   r   r   _to_exprr,   r(   r   from_invalid_typetype)argr~   r;  r<  r   r>  r?  s          r'   _parse_into_exprrF    s     87#sJ3x"c73<<>>~||~s|
"44T#Y??s8Or)   c              '     K   |D ]`  }t        ||| j                        j                  |       }|s1|j                  j                  j                         rd}t        |      | b y w)N)r~   r;  z9Multi-output expressions are not allowed in this context.)rF  _implementation_to_compliant_exprrB   rC   ru   r   )nsr~   r   r3   rE   retry   s          r'   evaluate_into_exprsrL  4  sk       Z1C1C


R
  	 "cmm&B&B&R&R&TMC,S11	s   A'A)c                     t        d | D              }g }| D ]S  }|r>t        |      r3|j                         }|j                  |_        |j                  |       C|j                  |       U |S )Nc              3  4   K   | ]  }t        |         y wrA   )rc   )r   r5  s     r'   r   z&maybe_broadcast_ces.<locals>.<genexpr>E  s     Err**Es   )r   rc   	broadcastrB   _opt_metadatar   )r   rO  resultsr   _compliant_exprs        r'   maybe_broadcast_cesrS  D  sk    E_EEI&(G) +70>0H0H0JO,:,D,DO)NN?+NN>*+ Nr)   c           	        | j                   dv r) t        || j                         | j                  d    }g }nd| j                   v r5| j                   j                  d      \  }}t        t        ||      |      }nt        || j                         }t	        t        | j                  || j                  | j                  d }t        d ||i | j                        }t        j                  | g| }||_        |S )N>   r   rF   r=   .rJ  r~   r   r   )r   getattrr   splitrS  rL  r3   r~   r   r
   r   r   rP  )r   rJ  r5  cesmodulemethodfuncmds           r'   evaluate_root_noder^  R  s    yy&& $WR#T[[%9:$))!YY__S1NFF72v.7D2tyy)D! ??#'#:#:	
 $dC&?4;;&?@				+s	+BBIr)   c           
        | j                   }t        | gt        |j                  ||j                  |j
                  d ^} } |j                  || g| }d|j                  v r5|j                  j                  d      \  }}t        t        | |      |      }nt        | |j                        }t        d ||i |j                        }||_        |S )NrV  rU  r   )rB   rS  rL  r3   r~   r   r   r   rX  rW  r
   r   rP  )	r   r   rJ  r]  r   accessorr[  r\  rK  s	            r'   evaluate_nodera  l  s     &//B+>,	ZZ#66	

,(N( 
dN	A-@	AB
dii99??3/&w~x8&A~tyy1
!4)<#L#L
MCCJr)   c                R    t        | d   |      }| dd  D ]  }t        |||      } |S r/   )r^  ra  )r   rJ  r5  r   s       r'   evaluate_nodesrc    s<     
E!Hb	)Bab	 )2tR()Ir)   )r&   r   r5   zTypeIs[Expr])r&   r   r5   zTypeIs[Series[Any]])r3   z#CompliantExpr[CompliantFrameT, Any]r5   zEvalNames[CompliantFrameT])r3   r   r5   zAliasNames | None)rE   r   r2   r   rF   r6   r5   z#tuple[Sequence[str], Sequence[str]])r&   r   r5   re   )
r   r   r   re   r   r}   r   r)  r5   r   )r   r   r9  r   r5   r   )
rE  &IntoExpr | NonNestedLiteral | _1DArrayr~   re   r;  r   r<  re   r5   r   )
r3   rd  rJ  r   r~   re   r   re   r5   zIterator[CompliantExprAny])r   r   r5   zlist[CompliantExprAny])r   r}   rJ  r   r5   r   )r   r   r   r}   rJ  r   r5   r   )r   zSequence[ExprNode]rJ  r   r5   r   )]
__future__r   enumr   r   typingr   r   r   r	   r
   narwhals._utilsr   narwhals.dependenciesr   narwhals.exceptionsr   r   r   collections.abcr   r   typing_extensionsr   r   narwhals._compliantr   r   narwhals._compliant.typingr   r   r   r   r   r$   r   r+   r   narwhals.typingr   r    r!   r(   r,   r8   r?   rK   rM   rc   ro   r}   r   rb   r   rW   r   rY   r   rZ   r^   r   rX   r   r[   r   r\   r   r]   r   __annotations__r  r  rj   r#  rQ   r	  rR   r%  rk   r  rO   r  rP   r  r   r   r:  rF  rL  rS  r^  ra  rc  r7   r)   r'   <module>rq     s  
 #  > > & 3  2/B  #&DD!#!/!!	!
! 1!<I!(!(T
t T
n("D "6u+ u+pl l` ,77LL,::,77l>>OO\--LL,''l//LL,''|??
T P 
 ,77,7755""L$K$K!!<#I#IMM<))|AAOO\--	I E 	=&== = 	=
 =@	)	),/	)		) 	/  	
  
,2  	
   4$,4:O0#8r)   