
    .i/              
      :   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
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 d d
lmZ d dlmZ d dlmZmZ d dlmZ er"d dl m!Z!m"Z" d dl#m$Z$m%Z%m&Z& d dlm'Z' d dl(m)Z)m*Z*m+Z+  G d deeeeejX                  df         Z-y)    )annotationsN)reduce)chain)TYPE_CHECKINGLiteralArrowDataFrame	ArrowExpr)ArrowSelectorNamespaceArrowSeries)cast_to_comparable_string_types)EagerNamespace)combine_alias_output_namescombine_evaluate_output_names)Implementation)IteratorSequence)ChunkedArrayAny
Incomplete	ScalarAny)Version)CorrelationMethod	IntoDTypePythonLiteralc                  &   e Zd Zej                  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d!dZd!dZed"d       Z	 	 	 	 	 	 	 	 d#dZd dZd dZ	 d$	 	 	 	 	 	 	 d%dZd&dZy)'ArrowNamespacec                    t         S Nr   selfs    V/opt/house_gps_flutter/.venv/lib/python3.12/site-packages/narwhals/_arrow/namespace.py
_dataframezArrowNamespace._dataframe$   s        c                    t         S r    r
   r!   s    r#   _exprzArrowNamespace._expr(   s    r%   c                    t         S r    r   r!   s    r#   _serieszArrowNamespace._series,   s    r%   c                   || _         y r    )_version)r"   versions     r#   __init__zArrowNamespace.__init__0   s	    r%   c                    d |D        S )Nc              3  j   K   | ]+  }|j                   r|j                  d    n|j                   - yw)r   N)
_broadcastnative.0ss     r#   	<genexpr>z0ArrowNamespace.extract_native.<locals>.<genexpr>6   s'     Jaq||9Js   13 )r"   seriess     r#   extract_nativezArrowNamespace.extract_native3   s     K6JJr%   c                J      j                   fdd d  j                        S )Nc                ^    t        j                  t        | j                        gd      gS )Nlen)namecontext)r   from_iterabler;   r1   )dfr"   s    r#   <lambda>z$ArrowNamespace.len.<locals>.<lambda>;   s(    ))3ryy>*:PTU r%   c                    dgS )Nr;   r6   _dfs    r#   r@   z$ArrowNamespace.len.<locals>.<lambda>>   s    ug r%   evaluate_output_namesalias_output_namesr,   r'   r+   r!   s   `r#   r;   zArrowNamespace.len8   s-    zz #6#MM  
 	
r%   c                `     d fd j                  fdd d  j                        S )Nc                `    t        j                  gd      }r|j                        S |S )Nliteraldatar<   r=   )r   r>   cast)_arrow_seriesdtyper"   values     r#   _lit_arrow_seriesz-ArrowNamespace.lit.<locals>._lit_arrow_seriesD   s8    &44W9dL #((//r%   c                     |       gS r    r6   )r?   rR   s    r#   r@   z$ArrowNamespace.lit.<locals>.<lambda>M   s    )"-. r%   c                    dgS )NrJ   r6   rB   s    r#   r@   z$ArrowNamespace.lit.<locals>.<lambda>N   s    yk r%   rD   )rN   r	   returnr   rG   )r"   rQ   rP   rR   s   ```@r#   litzArrowNamespace.litC   s0    	  zz."9#MM	  
 	
r%   c               j    dfd}| j                   j                  |t         t         |       S )Nc                     t        j                   fdD              }r	d |D        }t        t        j                  |      gS )Nc              3  .   K   | ]  } |        y wr    r6   r3   er?   s     r#   r5   z>ArrowNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>U        ?U!"?U   c              3  B   K   | ]  }|j                  d dd        yw)TN	fill_nullr2   s     r#   r5   z>ArrowNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>W   s     HA!++dD$7H   )r   r>   r   operatorand_r?   r7   exprsignore_nullss   ` r#   funcz+ArrowNamespace.all_horizontal.<locals>.funcT   s:    ,1,?,??Uu?U,UFHH8==&122r%   rg   rE   rF   r=   r?   r	   rU   zlist[ArrowSeries]r'   _from_callabler   r   r"   rf   re   rg   s    `` r#   all_horizontalzArrowNamespace.all_horizontalS   s<    	3 zz(("?"G95A	 ) 
 	
r%   c               j    dfd}| j                   j                  |t         t         |       S )Nc                     t        j                   fdD              }r	d |D        }t        t        j                  |      gS )Nc              3  .   K   | ]  } |        y wr    r6   rZ   s     r#   r5   z>ArrowNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>c   r\   r]   c              3  B   K   | ]  }|j                  d dd        yw)FNr_   r2   s     r#   r5   z>ArrowNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>e   s     IQ!++eT48Ira   )r   r>   r   rb   or_rd   s   ` r#   rg   z+ArrowNamespace.any_horizontal.<locals>.funcb   s:    ,1,?,??Uu?U,UFI&I8<<011r%   rh   ri   rj   rl   s    `` r#   any_horizontalzArrowNamespace.any_horizontala   s<    	2 zz(("?"G95A	 ) 
 	
r%   c                f    dfd}| j                   j                  |t         t         |       S )Nc                     t        j                   fdD              }d |D        }t        t        j                  |      gS )Nc              3  .   K   | ]  } |        y wr    r6   r3   exprr?   s     r#   r5   z>ArrowNamespace.sum_horizontal.<locals>.func.<locals>.<genexpr>q   s     $@$T"X$@r]   c              3  D   K   | ]  }|j                  d dd        yw)r   Nstrategylimitr_   r2   s     r#   r5   z>ArrowNamespace.sum_horizontal.<locals>.func.<locals>.<genexpr>r   s     LAakk!d$k?Ls    )r   r>   r   rb   add)r?   itr7   re   s   `  r#   rg   z+ArrowNamespace.sum_horizontal.<locals>.funcp   s7    $$$@%$@@BLLF8<<011r%   rh   ri   rj   r"   re   rg   s    ` r#   sum_horizontalzArrowNamespace.sum_horizontalo   s<    	2
 zz(("?"G95A	 ) 
 	
r%   c                    | j                   j                  j                         dfd}| j                  j	                  |t         t         |       S )Nc                t    t        t        j                   fdD                    }|D cg c]  }|j                  dd d        }}|D cg c]$  }d|j	                         j                        z
  & }}t        t        j                  |      t        t        j                  |      z  gS c c}w c c}w )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z?ArrowNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   s     4P$T"X4Pr]   r   rz      )	tupler   r>   r`   is_nullrM   r   rb   r}   )r?   expr_resultsr4   r7   non_nare   int_64s   `    r#   rg   z,ArrowNamespace.mean_horizontal.<locals>.func   s     !4!44P%4P!PQLIUVAakk!d$k?VFV<HIqa!))+**622IFI8<<06(,,3OOPP WIs   B0)B5rh   ri   )r+   dtypesInt64r'   rk   r   r   )r"   re   rg   r   s    ` @r#   mean_horizontalzArrowNamespace.mean_horizontal|   sU    %%++-	Q zz(("?"G95A	 ) 
 	
r%   c                j     d fd} j                   j                  |t         t                S )Nc                "    t        t        j                   fdD                    ^}}t        t        j
                  |D cg c]  }|j                   c}|j                        }t        ||j                  j                        gS c c}w )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z>ArrowNamespace.min_horizontal.<locals>.func.<locals>.<genexpr>        <X$T"X<Xr]   r<   r,   )
r   r   r>   r   pcmin_element_wiser1   r   r<   r+   r?   init_seriesr7   r4   native_seriesre   r"   s   `    r#   rg   z+ArrowNamespace.min_horizontal.<locals>.func   x    #()<)<<XRW<X)X#Y K&"##%?1ahh%?ASASM M0@0@$--X  &@   B
rh   ri   rj   r   s   `` r#   min_horizontalzArrowNamespace.min_horizontal   <    	 zz(("?"G95A	 ) 
 	
r%   c                j     d fd} j                   j                  |t         t                S )Nc                "    t        t        j                   fdD                    ^}}t        t        j
                  |D cg c]  }|j                   c}|j                        }t        ||j                  j                        gS c c}w )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z>ArrowNamespace.max_horizontal.<locals>.func.<locals>.<genexpr>   r   r]   r   )
r   r   r>   r   r   max_element_wiser1   r   r<   r+   r   s   `    r#   rg   z+ArrowNamespace.max_horizontal.<locals>.func   r   r   rh   ri   rj   r   s   `` r#   max_horizontalzArrowNamespace.max_horizontal   r   r%   c               |    | j                   dk\  rt        j                  |d      S t        j                  |d      S )N)   default)promote_optionsT)promote)_backend_versionpaconcat_tables)r"   dfss     r#   _concat_diagonalzArrowNamespace._concat_diagonal   s6      E)##CCCT22r%   c                   t        t        j                  d |D                    }t        t        j                  d |D                    }t        j
                  j                  ||      S )Nc              3  4   K   | ]  }|j                     y wr    )column_namesr3   r?   s     r#   r5   z4ArrowNamespace._concat_horizontal.<locals>.<genexpr>   s     (GR(G   c              3  <   K   | ]  }|j                           y wr    )itercolumnsr   s     r#   r5   z4ArrowNamespace._concat_horizontal.<locals>.<genexpr>   s     *J2>>+;*Js   )names)listr   r>   r   r   Tablefrom_arrays)r"   r   r   arrayss       r#   _concat_horizontalz!ArrowNamespace._concat_horizontal   sR    U(((G3(GGHu***Jc*JJKxx##F%#88r%   c                   |d   j                   }t        |dd  d      D ]-  \  }}|j                   x}|k7  sd| d| d| d}t        |       t        j                  |      S )Nr   r   )startz>unable to vstack, column names don't match:
   - dataframe 0: z
   - dataframe z: 
)r   	enumerate	TypeErrorr   r   )r"   r   cols_0ir?   cols_currentmsgs          r#   _concat_verticalzArrowNamespace._concat_vertical   s    Q$$s12wa0 	%EAr "/F:))/ 1&&'S<.< 
  n$	% $$r%   c                ,    t        j                  |       S r    )r   from_namespacer!   s    r#   	selectorszArrowNamespace.selectors   s    %44T::r%   c               r     d fd} j                   j                  |t         t                S )Nc                ,    t        t        j                   fdD                    }|d   j                  }	rdnd}t	         
j
                  | di\  }}t        j                  }
j                   |g ||d|i|
j                        }|gS )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z:ArrowNamespace.concat_str.<locals>.func.<locals>.<genexpr>   s     -I4d2h-Ir]   r   skip	emit_null	separatornull_handlingr   )
r   r   r>   r<   r   r8   r   binary_join_element_wiser)   r+   )r?   r7   r<   r   r~   separator_scalar
concat_str	compliantre   rf   r"   r   s   `       r#   rg   z'ArrowNamespace.concat_str.<locals>.func   s    %---I5-IIJF!9>>D&K  $C$$$f-$9B$ B 
 &(%@%@JNBN 0NN % I
 ;r%   rh   ri   rj   )r"   r   rf   re   rg   s   ```` r#   r   zArrowNamespace.concat_str   sA    	 	& zz(("?"G95A	 ) 
 	
r%   c                j     d fd} j                   j                  |t         t                S )Nc                    j                   j                  } |t        j                   fdD               ^}}t	        t        j                  |j                  gd |D         |j                  j                        gS )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z8ArrowNamespace.coalesce.<locals>.func.<locals>.<genexpr>   s     =Y4d2h=Yr]   c              3  4   K   | ]  }|j                     y wr    )r1   r2   s     r#   r5   z8ArrowNamespace.coalesce.<locals>.func.<locals>.<genexpr>   s     5O1ahh5Or   r   )
r)   _align_full_broadcastr   r>   r   r   coalescer1   r<   r+   )r?   alignr   r7   re   r"   s   `   r#   rg   z%ArrowNamespace.coalesce.<locals>.func   sr    LL66E#(%*=*==YSX=Y*Y#Z K&KK 2 2P5O5OP$)) MM r%   rh   ri   rj   r   s   `` r#   r   zArrowNamespace.coalesce   s<    		 zz(("?"G95A	 ) 
 	
r%   c                j     d fd} j                   j                  |t         t                S )Nc                (    t        t        j                   fdD                    }|d   j                  }t	        j
                  d |D        dt        d |D              i}t        j                  |g      }t        ||j                        gS )Nc              3  .   K   | ]  } |        y wr    r6   rw   s     r#   r5   z6ArrowNamespace.struct.<locals>.func.<locals>.<genexpr>   s     .JDtBx.Jr]   r   c              3  n   K   | ]-  }t        |      d kD  r|j                  n|j                  d    / yw)r   r   N)r;   r1   r2   s     r#   r5   z6ArrowNamespace.struct.<locals>.func.<locals>.<genexpr>   s+     Jac!fqj!((ahhqk9Js   35field_namesc              3  4   K   | ]  }|j                     y wr    )r<   r2   s     r#   r5   z6ArrowNamespace.struct.<locals>.func.<locals>.<genexpr>   s     !9Q!&&!9r   r   )
r   r   r>   r<   r   make_structr   chunked_arrayr   r+   )r?   r7   r<   struct_arrayresultre   r"   s   `    r#   rg   z#ArrowNamespace.struct.<locals>.func   s~    5...JE.JJKF!9>>D>>J6J!!9&!99L %%|n5FT4==IJJr%   rh   ri   rj   r   s   `` r#   structzArrowNamespace.struct   s=    		K zz(("?"G95A	 ) 
 	
r%   Nc                    |)t        j                  t        |      |j                        n|}t	        j
                  |j                  t        j                  d            ||      S )NF)r   nullsr;   typer   if_elser`   scalar)r"   whenthen	otherwises       r#   _if_then_elsezArrowNamespace._if_then_else  sI     7@6GBHHSY		2Y	zz$..5)9:D)LLr%   c                    |dk7  rd}t        |      d fd} j                  j                  |t              t	                     S )Npearsonz4Only 'pearson' correlation is supported for Pyarrow.c                b   | j                        }|j                  }| j                        j                  }t        j                  |      }t        j                  |      }t        j                  ||      }t        j                  ||      }t        j                  t        j
                  ||            }t        j                  |      }	t        j                  |      }
t        j                  |t        j
                  |	|
            }t        j                  |g|j                        gS )NrK   )_evaluate_single_output_exprr1   r   meansubtractmultiplystddevdivider   r>   r<   )r?   a_seriesarr1arr2mean1mean2dev1dev2
covariancestd1std2correlationabr"   s               r#   rg   z!ArrowNamespace.corr.<locals>.func  s    66q9H??D2215<<DGGDMEGGDME;;tU+D;;tU+DT4!89J99T?D99T?D))JD$0GHK))%X]]D r%   rh   ri   )NotImplementedErrorr'   rk   r   r   )r"   r   r   methodr   rg   s   ```   r#   corrzArrowNamespace.corr  sX    YHC%c**	, zz(("?1"E9!Q?	 ) 
 	
r%   )rU   ztype[ArrowDataFrame])rU   ztype[ArrowExpr])rU   ztype[ArrowSeries])r,   r   rU   None)r7   r   rU   z%Iterator[ChunkedArrayAny | ScalarAny])rU   r   )rQ   r   rP   zIntoDType | NonerU   r   )re   r   rf   boolrU   r   )re   r   rU   r   )r   zSequence[pa.Table]rU   zpa.Table)rU   r   )re   r   r   strrf   r  rU   r   r    )r   r   r   r   r   zChunkedArrayAny | NonerU   r   )r   r   r   r   r  r   rU   r   )__name__
__module____qualname__r   PYARROW_implementationpropertyr$   r'   r)   r-   r8   r;   rV   rm   rs   r   r   r   r   r   r   r   r   r   r   r   r   r  r6   r%   r#   r   r      s    %,,O      K"K	.K
	

 



 
"
"3
9

% ; ;

,/
?C
	
:
&
. -1	MM M *	M
 
M 
r%   r   r   ).
__future__r   rb   	functoolsr   	itertoolsr   typingr   r   pyarrowr   pyarrow.computecomputer   narwhals._arrow.dataframer	   narwhals._arrow.exprr   narwhals._arrow.selectorsr   narwhals._arrow.seriesr   narwhals._arrow.utilsr   narwhals._compliantr   narwhals._expression_parsingr   r   narwhals._utilsr   collections.abcr   r   narwhals._arrow.typingr   r   r   r   narwhals.typingr   r   r   r   r   r6   r%   r#   <module>r     so    "    )   4 * < . A . +2MM'KKU
>;	288EVVWU
r%   