
    .im                    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     Y/opt/house_gps_flutter/.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                  x} ||      n|}|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alias_fnaliasesxaliass           r'   !evaluate_output_names_and_aliasesrL   I   s     ..r2L 000H= 	 
 4>>00AAC * !+< AAuG# E
!
g   s   $B
c                  X   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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   )rN   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   )
rN   ALLCOLELEMENTWISEEXCLUDELITERALNTHSELECTORSERIES	WHEN_THENrT   s    r'   is_elementwisezExprKind.is_elementwise   s_     LLLL  LLOO

 

 
	
r)   c                b    | j                   xs" | t        j                  t        j                  hv S rA   )ra   rN   rQ   rP   rT   s    r'   preserves_lengthzExprKind.preserves_length   s'    ""Zdx@Y@Y.Z&ZZr)   c                d    | t         j                  t         j                  t         j                  hv S rA   )rN   AGGREGATIONr\   rR   rT   s    r'   is_scalar_likezExprKind.is_scalar_like   s/      **
 
 	
r)   Nr5   bool)__name__
__module____qualname____doc__r   r\   re   rR   rZ   rP   rQ   
FILTRATIONrS   OVERrY   r]   r[   rX   r^   r`   r_   propertyrV   ra   rc   rf   r7   r)   r'   rN   rN   ]   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)   rN   c                .    | j                   j                  S rA   )rB   rf   )r&   s    r'   rf   rf      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   rr   MULTI_UNNAMEDrT   s    r'   rD   zExpansionKind.is_multi_unnamed   s    }2222r)   c                F    | t         j                  t         j                  hv S rA   )rr   MULTI_NAMEDru   rT   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.)rr   ru   AssertionError)rU   othermsgs      r'   __and__zExpansionKind.__and__   sI    =...5M<W<W3W ...;D6ugMcdS!!r)   Nrg   )r{   rr   r5   z$Literal[ExpansionKind.MULTI_UNNAMED])ri   rj   rk   rl   r   SINGLErw   ru   rD   rx   r}   r7   r)   r'   rr   rr      s3    BVF9&K!FM'3P"r)   rr   c                  x    e Zd ZdZd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.
    r7   F)r3   
str_as_litallow_multi_outputc              t    || _         || _        || _        || _        || _        || _        d | _        d | _        y rA   )kindnamer3   kwargsr   r   _is_orderable_cached_is_elementwise_cached)rU   r   r   r3   r   r   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.0rJ   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)rU   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   rT   s    r'   as_dictzExprNode.as_dict  s:     IIIIZZkk//"&"9"9
 	
r)   c                     | j                   | j                  | j                  f| j                  | j                  d|S )N)r3   r   )	__class__r   r   r3   r   )rU   r   s     r'   _with_kwargszExprNode._with_kwargs  s<    t~~IItyy
(,

t
RX
 	
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   rV   r   	expr_nodes     r'   r   z9ExprNode._push_down_over_node_in_place.<locals>.<genexpr>"  s      ,-6	&&(,   c              3  <   K   | ]  }|j                           y wrA   ra   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)rU   	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>6  s     @DD%%'@r   Nr(   r   r   r   rE   s     r'   r   z(ExprNode.is_orderable.<locals>.<genexpr>5  s.      4= @DKK@@   13F)r   r   rV   r   r3   rT   s    r'   rV   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>F  s     F$++--Fs   Nr   r   s     r'   r   z*ExprNode.is_elementwise.<locals>.<genexpr>E  s.      4= F$++FFr   T)r   r   ra   r   r3   rT   s    r'   ra   zExprNode.is_elementwise?  s|    &&. 99++.3+ ***   JJ 
 /4+ *** /3+***r)   N)r   rN   r   r   r3   z%Sequence[IntoExpr | NonNestedLiteral]r   rh   r   rh   r   r   r5   Noner5   r   )r5   zdict[str, Any])r   r   r5   r   )r   r   r   r   r5   r   rg   )ri   rj   rk   rl   r   r   r   r   r   rV   ra   r7   r)   r'   r   r      s    
$ 8: #(88 8 5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_windowsra   
is_literalrf   n_orderable_opsrc   prevFr   TN)r   r   rc   ra   rf   r   r   c                   |r|sJ || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y rA   )	rC   r   r   ra   rc   rf   r   r   r   )
rU   rC   r   r   rc   ra   rf   r   r   r   s
             r'   r   zExprMetadata.__init__n  sU     !!>-;!,$3$2&6$2 *&2)-	r)   c               6    d| j                   }t        |      )NzCannot subclass )ri   	TypeError)clsargskwdsr|   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   ra   rc   rf   r   )rU   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   )rU   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   rU   r   compliant_exprcompliant_expr_argss       r'   	with_nodezExprMetadata.with_node  s)     (		2$
)<
 	
r)   c                    t        |d|d dS NTto_single_outputr   r   combine_metadatar   s      r'   from_aggregationzExprMetadata.from_aggregation        t$T
 	
r)   c           	     <     | t         j                  dddd|d       S )NTF)ra   rc   r   rf   r   r   rr   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   rr   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   )rr   rw   r   s     r'   r   z&ExprMetadata.from_selector_multi_named  s     =,,4dKKr)   c                4     | t         j                  |d       S r   rt   r   s     r'   from_selector_multi_unnamedz(ExprMetadata.from_selector_multi_unnamed  s     =..TMMr)   c                    t        |d|d dS r   r   r   s      r'   from_elementwisezExprMetadata.from_elementwise  r   r)   c                :    | j                    xr | j                   S rA   )rc   rf   rT   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   rc   ra   rf   r   r   r   rf   r   r   rC   r   r   rU   r   _cer|   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  rf   r   r   rC   r   r   rc   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_window4  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   ra   r  r   nextop_nodes_reversedr   rN   rQ   rV   r   rC   )rU   r   r  r|   r   s        r'   with_ordered_overzExprMetadata.with_ordered_overG  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   ra   r  r   rC   r   r
  s       r'   with_partitioned_overz"ExprMetadata.with_partitioned_overn  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  )rf   r   r   sumr   rC   )rU   r   r   r|   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.rK   )r   r   
startswith)rU   r   s     r'   r  zExprMetadata.op_nodes_reversed  s9     ,,. 	Dyy##$67J		s   79)rC   rr   r   rh   r   intrc   rh   ra   rh   rf   rh   r   rh   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   rg   )r   r   r  r   r5   r   )!ri   rj   rk   rl   	__slots__r   r   r   r   classmethodr   r   r   r   r   r   r   r   r  r  ro   r  r  r  r  r  r  r  r  r  r(  r*  r  r7   r)   r'   r   r   P  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}d}t         j                  }d}d}|j                  j                  }	d}
t	        |      D ]  \  }}|j
                  }|J |j                  j                         r|j                  }| s|dkD  r||z  n|}||j                  z  }||j                  z  }|	|j                  z  }	|
|j                  z  }
|t        |j                        z  }|t        |j                        z  } |j                  j                  xs |t        |      k(  }|j                  j                  xr
 |dk(  xr | }|r#|dkD  s||z   t        |      k  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 aggregationr  )rr   r~   r   ra   	enumeraterB   rC   rx   r   r   r   r-  r  rf   r   rc   r   r   )r   r   r   r   n_filtrationsn_scalar_likeresult_expansion_kindr&  r'  result_is_elementwiseresult_is_literalicemetadatarC   result_is_scalar_likeresult_preserves_lengthr|   s                     r'   r   r     s    MM)00(--<<?+ 62<<###""224%44N#>?!e)N: & 	h222(":"::!8!88X000X3344X44556$ )--<< _--  	** 	&Q	&%%  		 =O@T Th#C((&.0,,$!
 
r)   c                J    t        d |D              sd|  d}t        |      y )Nc              3  H   K   | ]  }|j                   j                    y wrA   )rB   rc   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   r|   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 )rA  )narwhals.functionsr   rD  rE  r%   r   r   _to_exprr,   r(   r   from_invalid_typetype)argr   rA  rB  r   rD  rE  s          r'   _parse_into_exprrL  +  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   rA  z9Multi-output expressions are not allowed in this context.)rL  _implementation_to_compliant_exprrB   rC   rx   r   )nsr   r   r3   rE   retr|   s          r'   evaluate_into_exprsrR  A  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   )rf   )r   r9  s     r'   r   z&maybe_broadcast_ces.<locals>.<genexpr>R  s     Err**Es   )r   rf   	broadcastrB   _opt_metadatar   )r   rU  resultsr   _compliant_exprs        r'   maybe_broadcast_cesrY  Q  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=   .rP  r   r   r   )r   getattrr   splitrY  rR  r3   r   r   r
   r   r   rV  )r   rP  r9  cesmodulemethodfuncmds           r'   evaluate_root_noderd  _  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 )Nr\  r[  r   )rB   rY  rR  r3   r   r   r   r   r^  r]  r
   r   rV  )	r   r   rP  rc  r   accessorra  rb  rQ  s	            r'   evaluate_noderg  y  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/   )rd  rg  )r   rP  r9  r   s       r'   evaluate_nodesri    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   rh   )
r   r   r   rh   r   r   r   r.  r5   r   )r   r   r?  r   r5   r   )
rK  &IntoExpr | NonNestedLiteral | _1DArrayr   rh   rA  r   rB  rh   r5   r   )
r3   rj  rP  r   r   rh   r   rh   r5   zIterator[CompliantExprAny])r   r   r5   zlist[CompliantExprAny])r   r   rP  r   r5   r   )r   r   r   r   rP  r   r5   r   )r   zSequence[ExprNode]rP  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?   rL   rN   rf   rr   r   r   re   r   rX   r  rZ   r  r[   r_   r   rY   r   r\   r   r]   r   r^   r   __annotations__r  r  rm   r(  rR   r  rS   r*  rn   r  rP   r  rQ   r  r   r   r@  rL  rR  rY  rd  rg  ri  r7   r)   r'   <module>rw     s  
 #  > > & 3  2/B  #&DD!#!/!!	!
! 1!<I!(!(X
t X
v("D "6v+ v+ri iZ ,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 	H&HH H 	H
 HV	)	),/	)		) 	/  	
  
,2  	
   4$,4:O0#8r)   