
    Wh              	      l   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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  d dl!m"Z"m#Z# erd dl$m%Z%m&Z& d dl!m'Z' d dl(m)Z)m*Z*m+Z+  G d deeeddf         Z, G d de ddef         Z- G d deddef   e      Z.y)    )annotationsN)reduce)chain)TYPE_CHECKINGAny)combine_alias_output_namescombine_evaluate_output_namesIbisLazyFrameIbisExpr)IbisSelectorNamespace)functionlitnarwhals_to_native_dtype)SQLNamespace)SQLThenSQLWhen)Implementationrequires)IterableSequence)Version)ConcatMethod	IntoDTypePythonLiteralc                     e Zd ZU ej                  Zded<   ddZedd       Z	edd       Z
edd       ZddZddZ	 d	 	 	 	 	 	 	 dd
ZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZddZ ej(                  d      dd       Zd dZd!dZy	)"IbisNamespacer   _implementationc                   || _         y N)_version)selfversions     R/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/_ibis/namespace.py__init__zIbisNamespace.__init__!   s	        c                ,    t        j                  |       S r!   )r   from_namespacer#   s    r%   	selectorszIbisNamespace.selectors$   s    $33D99r'   c                    t         S r!   r   r*   s    r%   _exprzIbisNamespace._expr(       r'   c                    t         S r!   r
   r*   s    r%   
_lazyframezIbisNamespace._lazyframe,   s    r'   c                    t        |g| S r!   )r   )r#   nameargss      r%   	_functionzIbisNamespace._function0   s    $t$$r'   c                    t        |      S r!   )r   )r#   values     r%   _litzIbisNamespace._lit3   s    5zr'   Nc                f    |t        j                  ||f      S t        j                  ||f|      S N)else_)ibiscases)r#   	conditionr6   	otherwises       r%   _whenzIbisNamespace._when6   s4     ::y%011zz9e,I>>r'   c                &    t        j                  | S r!   )r;   coalesce)r#   exprss     r%   	_coalescezIbisNamespace._coalesce=   s    }}e$$r'   c               :   |dk(  rd}t        |      t        |      }|D cg c]  }|j                   }}|d   j                  t	        fd|dd  D              sd}t        |      | j                  j                  t        j                  | |       S c c}w )Ndiagonalz<diagonal concat not supported for Ibis. Please join instead.r   c              3  <   K   | ]  }|j                   k(    y wr!   )schema).0xrG   s     r%   	<genexpr>z'IbisNamespace.concat.<locals>.<genexpr>J   s     9!188v%9s      z&inputs should all have the same schemacontext)
NotImplementedErrorlistnativerG   all	TypeErrorr0   from_nativer;   union)r#   itemshowmsgitemnative_itemsrG   s         @r%   concatzIbisNamespace.concat@   s     *PC%c**U05666q9uQRy99:CC. **4::|+Dd*SS 7s   Bc               n    dfd}| j                  |t         t         | j                        S )Nc                    t        t        j                   fdD                    }|D cg c]  }|j                  d       }}s|d   }|dd  D ]
  }|z   |z   } |gS t	              j                  |      }|gS c c}w )Nc              3  .   K   | ]  } |        y wr!    )rH   exprdfs     r%   rJ   z9IbisNamespace.concat_str.<locals>.func.<locals>.<genexpr>S   s     +GDH+Gs   stringr   rK   )rO   r   from_iterablecastr   join)	r`   colsscols_castedresultcolrB   ignore_nulls	separators	   `     r%   funcz&IbisNamespace.concat_str.<locals>.funcR   s    +++G+GGHD59:166(+:K:$Q&qr? 6C#i/#5F6
 8O Y,,[98O ;s   Bcallevaluate_output_namesalias_output_namesr$   )r`   r   returnlist[ir.Value])r-   r	   r   r"   )r#   rk   rj   rB   rl   s    ``` r%   
concat_strzIbisNamespace.concat_strO   s:    	 zz"?"G95AMM	  
 	
r'   c                D    dd} | j                   j                  |g| S )Nc                    t        |       } t        t        j                  d | D              t        t        j                  d | D              z  S )Nc              3  P   K   | ]  }|j                  t        d                yw)r   N)	fill_nullr   rH   ri   s     r%   rJ   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>i   s     (O3s1v)>(Os   $&c              3     K   | ]6  }|j                         j                  t        d       t        d             8 yw)r   rK   N)isnullifelser   rx   s     r%   rJ   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>j   s+     Ssszz|223q63q6BSs   <>)rO   r   operatoradd)re   s    r%   rl   z+IbisNamespace.mean_horizontal.<locals>.funcg   sA    :D(,,(O$(OPSYSdST  r'   )re   zIterable[ir.Value]rq   ir.Value)r-   _from_elementwise_horizontal_op)r#   rB   rl   s      r%   mean_horizontalzIbisNamespace.mean_horizontalf   s%    	 :tzz99$GGGr'   )
   r   c                0    t         j                  ||       S )NrL   )IbisWhen	from_expr)r#   	predicates     r%   whenzIbisNamespace.wheno   s    !!)T!::r'   c                X     d fd} j                  |d d  j                        S )Nc                R    rt        j                        nd }t        |      gS r!   )r   r"   r   )_df
ibis_dtypedtyper#   r6   s     r%   rl   zIbisNamespace.lit.<locals>.funct   s)    KP1%GVZJz*++r'   c                    dgS )Nliteralr^   r   s    r%   <lambda>z#IbisNamespace.lit.<locals>.<lambda>z   s    yk r'   )ro   rp   r$   )r   r   rq   Sequence[ir.Value]r-   r"   )r#   r6   r   rl   s   ``` r%   r   zIbisNamespace.lits   s0    	, zz"9#MM	  
 	
r'   c                J    dd}| j                  |d d | j                        S )Nc                8    | j                   j                         gS r!   )rP   countr   s    r%   rl   zIbisNamespace.len.<locals>.func   s    JJ$$&''r'   c                    dgS )Nlenr^   r   s    r%   r   z#IbisNamespace.len.<locals>.<lambda>   s    ug r'   rm   )r   r   rq   rr   r   )r#   rl   s     r%   r   zIbisNamespace.len   s/    	( zz"5#MM	  
 	
r'   )r$   r   rq   None)rq   r   )rq   ztype[IbisExpr])rq   ztype[IbisLazyFrame])r2   strr3   zir.Value | PythonLiteralrq   r~   )r6   r   rq   r~   r!   )r=   r~   r6   r~   r>   zir.Expr | Nonerq   r~   )rB   r~   rq   r~   )rU   zIterable[IbisLazyFrame]rV   r   rq   r   )rB   r   rk   r   rj   boolrq   r   )rB   r   rq   r   )r   r   rq   r   )r6   r   r   zIntoDType | Nonerq   r   )rq   r   )__name__
__module____qualname__r   IBISr   __annotations__r&   propertyr+   r-   r0   r4   r7   r?   rC   rZ   rs   r   r   backend_versionr   r   r   r^   r'   r%   r   r      s   &4&9&9O^9  : :    % QU?!?*2??M?	?%T,T6BT	T

+.
>B
	
.H Xg&; ';

	
r'   r   zir.Tabler~   c                  *    e Zd ZeZedd       ZddZy)r   c                    t         S r!   )IbisThenr*   s    r%   _thenzIbisWhen._then   r.   r'   c                   | j                   j                  }|j                  | j                         }| j                  } ||      r|j                  |      n
t	        |      }| j
                  }|t        j                  ||f      }|gS  ||      r|j                  |      n
t	        |      }t        j                  ||f|      }|gS r9   )
_condition_is_expr_evaluate_expr_then_valuer   _otherwise_valuer;   r<   )	r#   r`   is_exprr=   then_thenother_rh   r>   s	            r%   __call__zIbisWhen.__call__   s    //**%%doo6	  +25>r  's5z&&>ZZD 12F x 6=V_))&1#f+IZZD 1CFxr'   N)rq   ztype[IbisThen])r`   r   rq   r   )r   r   r   r   r   r   r   r^   r'   r%   r   r      s    
C r'   r   r   c                      e Zd Zy)r   N)r   r   r   r^   r'   r%   r   r      s    r'   r   )/
__future__r   r|   	functoolsr   	itertoolsr   typingr   r   r;   ibis.expr.typesr_   typesirnarwhals._expression_parsingr   r	   narwhals._ibis.dataframer   narwhals._ibis.exprr   narwhals._ibis.selectorsr   narwhals._ibis.utilsr   r   r   narwhals._sql.namespacer   narwhals._sql.when_thenr   r   narwhals._utilsr   r   collections.abcr   r   r   narwhals.typingr   r   r   r   r   r   r^   r'   r%   <module>r      s    "    %    3 ( : H H 0 4 42'FFj
L*j!PQ j
Zw
H<= * Nw
H<=x Mr'   