
    }i              	      N   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c mZ d dlmZ d dlmZmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZ d dlm Z  d dl!m"Z"m#Z# erd dl$m%Z%m&Z&m'Z' d dl!m(Z( d dl)m*Z*m+Z+m,Z,m-Z-  G d de eeddf         eeef                   Z.dS )    )annotationsN)reduce)chain)TYPE_CHECKINGAny)AlignDiagonal)combine_alias_output_namescombine_evaluate_output_names!evaluate_output_names_and_aliasesIbisLazyFrameIbisExpr)IbisSelectorNamespace)functionlitnarwhals_to_native_dtype)SQLNamespace)Implementation
zip_strict)IterableMappingSequence)Version)ConcatMethodCorrelationMethod	IntoDTypePythonLiteralc                      e Zd ZU ej        Zded<   d5dZed6d	            Z	ed7d            Z
ed8d            Zd9dZd:dZ	 d;d<dZd=dZd>d#Zd?d(Zd@d)ZdAd-ZdBd.ZdCd3Zd@d4ZdS )DIbisNamespacer   _implementationversionr   returnNonec                   || _         d S N)_version)selfr"   s     L/home/jrussi/.local/lib/python3.11/site-packages/narwhals/_ibis/namespace.py__init__zIbisNamespace.__init__%   s        r   c                *    t          j        |           S r&   )r   from_namespacer(   s    r)   	selectorszIbisNamespace.selectors(   s    $3D999r+   type[IbisExpr]c                    t           S r&   r   r.   s    r)   _exprzIbisNamespace._expr,   s    r+   type[IbisLazyFrame]c                    t           S r&   r   r.   s    r)   
_lazyframezIbisNamespace._lazyframe0   s    r+   namestrargsir.Value | PythonLiteralir.Valuec                    t          |g|R  S r&   )r   )r(   r6   r8   s      r)   	_functionzIbisNamespace._function4   s    $t$$$$r+   valuer   c                     t          |          S r&   )r   )r(   r=   s     r)   _litzIbisNamespace._lit7   s    5zzr+   N	condition	otherwiseir.Expr | Nonec                b    |t          j        ||f          S t          j        ||f|          S )N)else_)ibiscases)r(   r@   r=   rA   s       r)   _whenzIbisNamespace._when:   s9     :y%0111z9e,I>>>>r+   exprsc                    t          j        | S r&   )rE   coalesce)r(   rH   s     r)   	_coalescezIbisNamespace._coalesceA   s    }e$$r+   itemsIterable[IbisLazyFrame]howr   r   c               n   t          |          }|dk    r|                     |          }	 t          j        d |D              }nV# t          j        $ rD |d         j        t          fd|dd          D                       sd}t          |          d  w xY w|d                             |          S )Ndiagonalc              3  $   K   | ]}|j         V  d S r&   )native).0lfs     r)   	<genexpr>z'IbisNamespace.concat.<locals>.<genexpr>K   s$      !=!=")!=!=!=!=!=!=r+   r   c              3  .   K   | ]}|j         k    V  d S r&   )schema)rS   xfirsts     r)   rU   z'IbisNamespace.concat.<locals>.<genexpr>N   s*      ==Qqx5(======r+      z&inputs should all have the same schema)	tuplealign_diagonalrE   union	IbisErrorrW   all	TypeError_with_native)r(   rL   rN   framesresultmsgrY   s         @r)   concatzIbisNamespace.concatD   s     +0,,*((00F	Z!=!=f!=!=!=>FF~ 	 	 	1I$E====&*===== />nn$.	 ay%%f---s   A ABr   	separatorignore_nullsboolc               p    dfd}|                      |t           t           | j                  S )Ndfr   r#   list[ir.Value]c                     t          j         fdD                       }d |D             }r#t                                        |          }n"t	          fd|dd          |d                   }|gS )Nc              3  .   K   | ]} |          V  d S r&    )rS   exprrj   s     r)   rU   z9IbisNamespace.concat_str.<locals>.func.<locals>.<genexpr>X   s+      &B&BDttBxx&B&B&B&B&B&Br+   c                8    g | ]}|                     d           S )string)cast)rS   ss     r)   
<listcomp>z:IbisNamespace.concat_str.<locals>.func.<locals>.<listcomp>Y   s$    :::166(++:::r+   c                0    |                      |          S r&   )re   )acccolrf   s     r)   <lambda>z8IbisNamespace.concat_str.<locals>.func.<locals>.<lambda>_   s    SZZ	3%?%? r+   rZ   r   )r   from_iterabler   joinr   )rj   colscols_castedrc   rH   rg   rf   s   `   r)   funcz&IbisNamespace.concat_str.<locals>.funcW   s    &&B&B&B&BE&B&B&BBBD::T:::K Y,,[99????ON  8Or+   callevaluate_output_namesalias_output_namesr"   rj   r   r#   rk   )r2   r
   r	   r'   )r(   rf   rg   rH   r}   s    ``` r)   
concat_strzIbisNamespace.concat_strT   sb    	 	 	 	 	 	 	 	 zz"?"G95AM	  
 
 	
r+   c                0    dd} | j         j        |g|R  S )Nr{   Iterable[ir.Value]r#   r:   c                    t          |           } t          t          j        d | D                       t          t          j        d | D                       z  S )Nc              3  Z   K   | ]&}|                     t          d                     V  'dS )r   N)	fill_nullr   rS   rw   s     r)   rU   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>p   s4      (O(O3s1vv)>)>(O(O(O(O(O(Or+   c              3     K   | ]F}|                                                     t          d           t          d                    V  GdS )r   rZ   N)isnullifelser   r   s     r)   rU   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>q   sF      SSsszz||223q663q66BBSSSSSSr+   )listr   operatoradd)r{   s    r)   r}   z+IbisNamespace.mean_horizontal.<locals>.funcn   sZ    ::D(,(O(O$(O(O(OPPSYSSdSSST T  r+   )r{   r   r#   r:   )r2   _from_elementwise_horizontal_op)r(   rH   r}   s      r)   mean_horizontalzIbisNamespace.mean_horizontalm   s5    	 	 	 	 :tz9$GGGGGr+   r   dtypeIntoDType | Nonec                V     d fd}                      |d d  j                  S )	N_dfr   r#   Sequence[ir.Value]c                    rt          j                  nd }t          t                    st	          |          gS rt          j        |          gS d}t          |          )N)typez3Cannot create an empty struct type for Ibis backend)r   r'   
isinstancedictr   rE   structNotImplementedError)r   
ibis_dtyperd   r   r(   r=   s      r)   r}   zIbisNamespace.lit.<locals>.funcw   sx    KPZ1%GGGVZJeT** 0E:..// =E
;;;<<GC%c***r+   c                    dgS )Nliteralrn   r   s    r)   rx   z#IbisNamespace.lit.<locals>.<lambda>   s    yk r+   r   r   r"   )r   r   r#   r   r2   r'   )r(   r=   r   r}   s   ``` r)   r   zIbisNamespace.litv   s[    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ zz"9"9#M	  
 
 	
r+   c                H    dd}|                      |d d | j                  S )	Nr   r   r#   rk   c                6    | j                                         gS r&   )rR   countr   s    r)   r}   zIbisNamespace.len.<locals>.func   s    J$$&&''r+   c                    dgS )Nlenrn   r   s    r)   rx   z#IbisNamespace.len.<locals>.<lambda>   s    ug r+   r~   r   r   r#   rk   r   )r(   r}   s     r)   r   zIbisNamespace.len   sD    	( 	( 	( 	( zz"5"5#M	  
 
 	
r+   abmethodr   c                   |dk    rd}t          |          d	fd}|                     |t                    t                    | j                  S )
Npearsonz1Only 'pearson' correlation is supported for Ibis.r   r   r#   rk   c                    |                                }|                                }|                    |d          gS )Npop)rN   )_evaluate_single_output_exprcorr)r   a_b_r   r   s      r)   r}   z IbisNamespace.corr.<locals>.func   sB    11!44B11!44BGGBEG**++r+   r   r   )r   r2   r
   r	   r'   )r(   r   r   r   rd   r}   s    ``   r)   r   zIbisNamespace.corr   s    YEC%c***	, 	, 	, 	, 	, 	, 	,
 zz"?1"E"E9!Q??M	  
 
 	
r+   c                l    | j         }dfd}|                     |t           t           |          S )Nrj   r   r#   rk   c                L      fdD             }t          j        |          gS )Nc           
     n    i | ]1}t           |          gt          |g           R  D ]	\  }}}||
2S rn   )r   r   )rS   ro   native_expr_aliasrj   s        r)   
<dictcomp>z6IbisNamespace.struct.<locals>.func.<locals>.<dictcomp>   sv     5 5 5-7DHH.@r2NN. . .5 5 *KE {5 5 5 5r+   )rE   r   )rj   names_to_colsrH   s   ` r)   r}   z"IbisNamespace.struct.<locals>.func   sA    5 5 5 5!5 5 5M K..//r+   r~   r   )r'   r2   r
   r	   )r(   rH   r"   r}   s    `  r)   r   zIbisNamespace.struct   s[    -	0 	0 	0 	0 	0 	0 zz"?"G95A	  
 
 	
r+   )r"   r   r#   r$   )r#   r   )r#   r0   )r#   r3   )r6   r7   r8   r9   r#   r:   )r=   r   r#   r:   r&   )r@   r:   r=   r:   rA   rB   r#   r:   )rH   r:   r#   r:   )rL   rM   rN   r   r#   r   )rH   r   rf   r7   rg   rh   r#   r   )rH   r   r#   r   )r=   r   r   r   r#   r   )r#   r   )r   r   r   r   r   r   r#   r   )__name__
__module____qualname__r   IBISr!   __annotations__r*   propertyr/   r2   r5   r<   r?   rG   rK   re   r   r   r   r   r   r   rn   r+   r)   r    r       s         '5&9O9999        : : : X:    X    X% % % %    QU? ? ? ? ?% % % %. . . . 
 
 
 
2H H H H
 
 
 
"	
 	
 	
 	

 
 
 
"
 
 
 
 
 
r+   r    zir.Tabler:   )/
__future__r   r   	functoolsr   	itertoolsr   typingr   r   rE   ibis.expr.typesro   typesirnarwhals._compliant.namespacer   narwhals._expression_parsingr	   r
   r   narwhals._ibis.dataframer   narwhals._ibis.exprr   narwhals._ibis.selectorsr   narwhals._ibis.utilsr   r   r   narwhals._sql.namespacer   narwhals._utilsr   r   collections.abcr   r   r   r   narwhals.typingr   r   r   r   r    rn   r+   r)   <module>r      s   " " " " " "              % % % % % % % %           7 7 7 7 7 7         
 3 2 2 2 2 2 ( ( ( ( ( ( : : : : : : H H H H H H H H H H 0 0 0 0 0 0 6 6 6 6 6 6 6 6 Z;;;;;;;;;;''''''YYYYYYYYYYYYV
 V
 V
 V
 V
*j@A-)*V
 V
 V
 V
 V
r+   