
    ei/'              
      6   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*  G d deeeeejV                  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)	IntoDTypeNonNestedLiteralc                     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#dZy)$ArrowNamespacec                    t         S Nr   selfs    [/var/www/html/glpi_dashboard/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:   r0   )dfr!   s    r"   <lambda>z$ArrowNamespace.len.<locals>.<lambda>;   s(    ))3ryy>*:PTU r$   c                    dgS )Nr:   r5   _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   r5   )r>   rP   s    r"   r?   z$ArrowNamespace.lit.<locals>.<lambda>M   s    )"-. r$   c                    dgS )NrI   r5   rA   s    r"   r?   z$ArrowNamespace.lit.<locals>.<lambda>N   s    yk r$   rC   )rL   r	   returnr   rF   )r!   rO   rN   rP   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   r5   r2   er>   s     r"   r4   z>ArrowNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>U        ?U!"?U   c              3  B   K   | ]  }|j                  d dd        yw)TN	fill_nullr1   s     r"   r4   z>ArrowNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>W   s     HA!++dD$7H   )r   r=   r   operatorand_r>   r6   exprsignore_nullss   ` r"   funcz+ArrowNamespace.all_horizontal.<locals>.funcT   s:    ,1,?,??Uu?U,UFHH8==&122r$   re   rD   rE   r<   r>   r	   rS   zlist[ArrowSeries]r&   _from_callabler   r   r!   rd   rc   re   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   r5   rX   s     r"   r4   z>ArrowNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>c   rZ   r[   c              3  B   K   | ]  }|j                  d dd        yw)FNr]   r1   s     r"   r4   z>ArrowNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>e   s     IQ!++eT48Ir_   )r   r=   r   r`   or_rb   s   ` r"   re   z+ArrowNamespace.any_horizontal.<locals>.funcb   s:    ,1,?,??Uu?U,UFI&I8<<011r$   rf   rg   rh   rj   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   r5   r2   exprr>   s     r"   r4   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]   r1   s     r"   r4   z>ArrowNamespace.sum_horizontal.<locals>.func.<locals>.<genexpr>r   s     LAakk!d$k?Ls    )r   r=   r   r`   add)r>   itr6   rc   s   `  r"   re   z+ArrowNamespace.sum_horizontal.<locals>.funcp   s7    $$$@%$@@BLLF8<<011r$   rf   rg   rh   r!   rc   re   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   r5   ru   s     r"   r4   z?ArrowNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   s     4P$T"X4Pr[   r   rx      )	tupler   r=   r^   is_nullrK   r   r`   r{   )r>   expr_resultsr3   r6   non_narc   int_64s   `    r"   re   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rf   rg   )r*   dtypesInt64r&   ri   r   r   )r!   rc   re   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   r5   ru   s     r"   r4   z>ArrowNamespace.min_horizontal.<locals>.func.<locals>.<genexpr>        <X$T"X<Xr[   r;   r+   )
r   r   r=   r   pcmin_element_wiser0   r   r;   r*   r>   init_seriesr6   r3   native_seriesrc   r!   s   `    r"   re   z+ArrowNamespace.min_horizontal.<locals>.func   x    #()<)<<XRW<X)X#Y K&"##%?1ahh%?ASASM M0@0@$--X  &@   B
rf   rg   rh   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   r5   ru   s     r"   r4   z>ArrowNamespace.max_horizontal.<locals>.func.<locals>.<genexpr>   r   r[   r   )
r   r   r=   r   r   max_element_wiser0   r   r;   r*   r   s   `    r"   re   z+ArrowNamespace.max_horizontal.<locals>.func   r   r   rf   rg   rh   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r2   r>   s     r"   r4   z4ArrowNamespace._concat_horizontal.<locals>.<genexpr>   s     (GR(G   c              3  <   K   | ]  }|j                           y wr   )itercolumnsr   s     r"   r4   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                   }||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??Lv%))/ 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   r5   ru   s     r"   r4   z:ArrowNamespace.concat_str.<locals>.func.<locals>.<genexpr>   s     -I4d2h-Ir[   r   skip	emit_null	separatornull_handlingr   )
r   r   r=   r;   r   r7   r   binary_join_element_wiser(   r*   )r>   r6   r;   r   r|   separator_scalar
concat_str	compliantrc   rd   r!   r   s   `       r"   re   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$   rf   rg   rh   )r!   r   rd   rc   re   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   r5   ru   s     r"   r4   z8ArrowNamespace.coalesce.<locals>.func.<locals>.<genexpr>   s     =Y4d2h=Yr[   c              3  4   K   | ]  }|j                     y wr   )r0   r1   s     r"   r4   z8ArrowNamespace.coalesce.<locals>.func.<locals>.<genexpr>   s     5O1ahh5Or   r   )
r(   _align_full_broadcastr   r=   r   r   coalescer0   r;   r*   )r>   alignr   r6   rc   r!   s   `   r"   re   z%ArrowNamespace.coalesce.<locals>.func   sr    LL66E#(%*=*==YSX=Y*Y#Z K&KK 2 2P5O5OP$)) MM r$   rf   rg   rh   r}   s   `` r"   r   zArrowNamespace.coalesce   s<    		 zz(("?"G95A	 ) 
 	
r$   Nc                    |)t        j                  t        |      |j                        n|}t	        j
                  |||      S r   )r   nullsr:   typer   if_else)r!   whenthen	otherwises       r"   _if_then_elsezArrowNamespace._if_then_else   s7     7@6GBHHSY		2Y	zz$i00r$   )rS   ztype[ArrowDataFrame])rS   ztype[ArrowExpr])rS   ztype[ArrowSeries])r+   r   rS   None)r6   r   rS   z%Iterator[ChunkedArrayAny | ScalarAny])rS   r   )rO   r   rN   zIntoDType | NonerS   r   )rc   r   rd   boolrS   r   )rc   r   rS   r   )r   zSequence[pa.Table]rS   zpa.Table)rS   r   )rc   r   r   strrd   r   rS   r   r   )r   r   r   r   r   zChunkedArrayAny | NonerS   r   )__name__
__module____qualname__r   PYARROW_implementationpropertyr#   r&   r(   r,   r7   r:   rT   rk   rq   r~   r   r   r   r   r   r   r   r   r   r   r5   r$   r"   r   r      s    %,,O      K"K	.K
	

 



 
"
"3
9
% ; ;

,/
?C
	
:
. -1	11 1 *	1
 
1r$   r   r   )-
__future__r   r`   	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   r5   r$   r"   <module>r      sl    "    )   4 * < . A . +2MM';a1>;	288EVVWa1r$   