
    -Ph                     |   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	m
Z
mZmZ d dlZd dlmc mZ d dlmZmZ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! d dl"m#Z#m$Z$ erd dl"m%Z% d dl&m'Z'm(Z(  G d deeedf                   Z) G d deddef                   Z* G d deddef         e          Z+dS )    )annotationsNreduce)chain)TYPE_CHECKINGAnyIterableSequencecast)LazyNamespaceLazyThenLazyWhen)combine_alias_output_namescombine_evaluate_output_namesIbisLazyFrameIbisExpr)IbisSelectorNamespace)litnarwhals_to_native_dtype)Implementationrequires)Version)ConcatMethod	IntoDTypec                      e Zd ZU ej        Zded<   d.d	Zed/d            Z	ed0d            Z
ed1d            Zd2dZd3dZd4dZd4dZd4dZd4d Zd4d!Zd4d"Z ej        d#          d5d&            Zd6d+Zd7d,Zd-S )8IbisNamespacer   _implementationbackend_versiontuple[int, ...]versionr   returnNonec               "    || _         || _        d S N)_backend_version_version)selfr    r"   s      X/var/www/html/test/jupyter/venv/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&       r,   type[IbisLazyFrame]c                    t           S r&   r   r/   s    r*   
_lazyframezIbisNamespace._lazyframe*   s    r,   itemsIterable[IbisLazyFrame]howr   r   c               :   |dk    rd}t          |          t          |          }d |D             }|d         j        t          fd|dd          D                       sd}t	          |          | j                            t          j        | |           S )	Ndiagonalz<diagonal concat not supported for Ibis. Please join instead.c                    g | ]	}|j         
S  )native).0items     r*   
<listcomp>z(IbisNamespace.concat.<locals>.<listcomp>6   s    666666r,   r   c              3  .   K   | ]}|j         k    V  d S r&   )schema)r@   xrD   s     r*   	<genexpr>z'IbisNamespace.concat.<locals>.<genexpr>8   s*      99!18v%999999r,      z&inputs should all have the same schemacontext)	NotImplementedErrorlistrD   all	TypeErrorr7   from_nativeibisunion)r)   r8   r:   msgnative_itemsrD   s        @r*   concatzIbisNamespace.concat.   s     *PC%c***U66666q9999uQRRy99999 	!:CC.. **4:|+Dd*SSSr,   exprsr   	separatorstrignore_nullsboolc               |    dfd}|                      |t           t           | j        | j                  S )Ndfr   r#   list[ir.Value]c                "    t          t          j         fdD                                 }d |D             }s|d         }|dd          D ]
}|z   |z   }n2t          dt	                              }|                    |          }|gS )Nc              3  .   K   | ]} |          V  d S r&   r>   r@   exprrZ   s     r*   rF   z9IbisNamespace.concat_str.<locals>.func.<locals>.<genexpr>A   s+      +G+GDDHH+G+G+G+G+G+Gr,   c                8    g | ]}|                     d           S )string)r   )r@   ss     r*   rB   z:IbisNamespace.concat_str.<locals>.func.<locals>.<listcomp>B   s$    :::166(++:::r,   r   rG   zir.StringValue)rK   r   from_iterabler   r   join)	rZ   colscols_castedresultcolseprT   rW   rU   s	   `     r*   funcz&IbisNamespace.concat_str.<locals>.func@   s    ++G+G+G+G+G+G+GGGHHD::T:::K /$Q&qrr? 6 6C#i/#5FF6 +S^^<<+..8Or,   callevaluate_output_namesalias_output_namesr    r"   rZ   r   r#   r[   r3   r   r   r'   r(   )r)   rU   rW   rT   rj   s    ``` r*   
concat_strzIbisNamespace.concat_str=   sh    	 	 	 	 	 	 	 	 zz"?"G95A 1M  
 
 	
r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                |     t          j         fdD                       }t          t          j        |          gS )Nc              3  .   K   | ]} |          V  d S r&   r>   r^   s     r*   rF   z=IbisNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>X   +      &B&BDttBxx&B&B&B&B&B&Br,   )r   rc   r   operatorand_rZ   re   rT   s   ` r*   rj   z*IbisNamespace.all_horizontal.<locals>.funcW   s>    &&B&B&B&BE&B&B&BBBD8=$//00r,   rk   ro   rp   r)   rT   rj   s    ` r*   all_horizontalzIbisNamespace.all_horizontalV   s\    	1 	1 	1 	1 	1 	1 zz"?"G95A 1M  
 
 	
r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                |     t          j         fdD                       }t          t          j        |          gS )Nc              3  .   K   | ]} |          V  d S r&   r>   r^   s     r*   rF   z=IbisNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>e   ru   r,   )r   rc   r   rv   or_rx   s   ` r*   rj   z*IbisNamespace.any_horizontal.<locals>.funcd   s>    &&B&B&B&BE&B&B&BBBD8<..//r,   rk   ro   rp   ry   s    ` r*   any_horizontalzIbisNamespace.any_horizontalc   \    	0 	0 	0 	0 	0 	0 zz"?"G95A 1M  
 
 	
r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                d     t          j         fdD                       }t          j        | gS )Nc              3  .   K   | ]} |          V  d S r&   r>   r^   s     r*   rF   z=IbisNamespace.max_horizontal.<locals>.func.<locals>.<genexpr>r   ru   r,   )r   rc   rO   greatestrx   s   ` r*   rj   z*IbisNamespace.max_horizontal.<locals>.funcq   s9    &&B&B&B&BE&B&B&BBBDM4())r,   rk   ro   rp   ry   s    ` r*   max_horizontalzIbisNamespace.max_horizontalp   s\    	* 	* 	* 	* 	* 	* zz"?"G95A 1M  
 
 	
r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                d     t          j         fdD                       }t          j        | gS )Nc              3  .   K   | ]} |          V  d S r&   r>   r^   s     r*   rF   z=IbisNamespace.min_horizontal.<locals>.func.<locals>.<genexpr>   ru   r,   )r   rc   rO   leastrx   s   ` r*   rj   z*IbisNamespace.min_horizontal.<locals>.func~   s9    &&B&B&B&BE&B&B&BBBDJ%&&r,   rk   ro   rp   ry   s    ` r*   min_horizontalzIbisNamespace.min_horizontal}   s\    	' 	' 	' 	' 	' 	' zz"?"G95A 1M  
 
 	
r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                X      fdD             }t          t          j        |          gS )Nc                p    g | ]2} |          D ]$}|                     t          d                     %3S )r   )	fill_nullr   r@   r3   erZ   s      r*   rB   z>IbisNamespace.sum_horizontal.<locals>.func.<locals>.<listcomp>   s@    NNNEEE"IINNqAKKA''NNNNr,   )r   rv   addrx   s   ` r*   rj   z*IbisNamespace.sum_horizontal.<locals>.func   s2    NNNNUNNND8<..//r,   rk   ro   rp   ry   s    ` r*   sum_horizontalzIbisNamespace.sum_horizontal   r   r,   c                t    dfd}|                      |t           t           | j        | j                  S )NrZ   r   r#   r[   c                      fdD             } fdD             }t          d |          t          d |          z  gS )Nc           
   3     K   | ]B} |          D ]4}t          d |                    t          d                              V  5CdS )ir.NumericColumnr   N)r   r   r   r   s      r*   rF   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   ss        r   'SVV)<)<==      r,   c              3     K   | ]b} |          D ]T}t          d |                                                    t          d          t          d                              V  UcdS )r   r   rG   N)r   isnullifelser   r   s      r*   rF   z>IbisNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   s        r   '):):3q663q66)J)JKK      r,   c                    | |z   S r&   r>   rE   ys     r*   <lambda>z=IbisNamespace.mean_horizontal.<locals>.func.<locals>.<lambda>   s
    QU r,   c                    | |z   S r&   r>   r   s     r*   r   z=IbisNamespace.mean_horizontal.<locals>.func.<locals>.<lambda>   s
    A r,   r   )rZ   r_   non_nullrT   s   `  r*   rj   z+IbisNamespace.mean_horizontal.<locals>.func   s       "  D
   "  H **D11F;M;Mx4X4XX r,   rk   ro   rp   ry   s    ` r*   mean_horizontalzIbisNamespace.mean_horizontal   s\    	 	 	 	 	 	  zz"?"G95A 1M  
 
 	
r,   )
   r   	predicateIbisWhenc                :    t                               ||           S )NrH   )r   	from_expr)r)   r   s     r*   whenzIbisNamespace.when   s    !!)T!:::r,   valuer   dtypeIntoDType | Nonec                b     d fd}                      |d d  j         j                  S )	N_dfr   r#   r[   c                X    rt          j                  nd }t          |          gS r&   )r   r(   r   )r   
ibis_dtyper   r)   r   s     r*   rj   zIbisNamespace.lit.<locals>.func   s3    KPZ1%GGGVZJz**++r,   c                    dgS )Nliteralr>   r   s    r*   r   z#IbisNamespace.lit.<locals>.<lambda>   s    yk r,   )rm   rn   r    r"   r   r   r#   r[   r3   r'   r(   )r)   r   r   rj   s   ``` r*   r   zIbisNamespace.lit   sa    	, 	, 	, 	, 	, 	, 	, 	, zz"9"9# 1M  
 
 	
r,   c                T    dd}|                      |d d | j        | j                  S )	Nr   r   r#   r[   c                6    | j                                         gS r&   )r?   countr   s    r*   rj   zIbisNamespace.len.<locals>.func   s    J$$&&''r,   c                    dgS )Nlenr>   r   s    r*   r   z#IbisNamespace.len.<locals>.<lambda>   s    ug r,   rk   r   r   )r)   rj   s     r*   r   zIbisNamespace.len   sJ    	( 	( 	( 	( zz"5"5# 1M  
 
 	
r,   N)r    r!   r"   r   r#   r$   )r#   r   )r#   r1   )r#   r5   )r8   r9   r:   r   r#   r   )rT   r   rU   rV   rW   rX   r#   r   )rT   r   r#   r   )r   r   r#   r   )r   r   r   r   r#   r   )r#   r   )__name__
__module____qualname__r   IBISr   __annotations__r+   propertyr0   r3   r7   rS   rq   rz   r   r   r   r   r   r   r    r   r   r   r>   r,   r*   r   r      s        &4&9O9999        : : : X:    X    XT T T T
 
 
 
2
 
 
 

 
 
 

 
 
 

 
 
 

 
 
 

 
 
 
2 Xg&&; ; ; '&;
 
 
 


 

 

 

 

 

r,   r   zir.Tablec                  2    e Zd ZeZed	d            Zd
dZdS )r   r#   type[IbisThen]c                    t           S r&   )IbisThenr/   s    r*   _thenzIbisWhen._then   r4   r,   rZ   r   Sequence[ir.Value]c                   | j         j        }|                    | j                   }| j        } ||          r|                    |          nt	          |          }| j        }|t          j        ||f          }nG ||          r|                    |          nt	          |          }t          j        ||f|          }|gS )N)else_)
_condition_is_expr_evaluate_expr_then_valuer   _otherwise_valuerO   cases)	r)   rZ   is_expr	conditionthen_thenother_rg   	otherwises	            r*   __call__zIbisWhen.__call__   s    /*%%do66	 +275>>Ir  '''s5zz&>ZD 122FF5<WV__U))&111#f++IZD 1CCCFxr,   N)r#   r   )rZ   r   r#   r   )r   r   r   r   r   r   r   r>   r,   r*   r   r      sK        
C   X     r,   r   r   zir.Valuec                      e Zd ZdS )r   N)r   r   r   r>   r,   r*   r   r      s          r,   r   ),
__future__r   rv   	functoolsr   	itertoolsr   typingr   r   r	   r
   r   rO   ibis.expr.typesr_   typesirnarwhals._compliantr   r   r   narwhals._expression_parsingr   r   narwhals._ibis.dataframer   narwhals._ibis.exprr   narwhals._ibis.selectorsr   narwhals._ibis.utilsr   r   narwhals._utilsr   r   r   narwhals.typingr   r   r   r   r   r>   r,   r*   <module>r      s   " " " " " "              ? ? ? ? ? ? ? ? ? ? ? ? ? ?           A A A A A A A A A A        3 2 2 2 2 2 ( ( ( ( ( ( : : : : : : > > > > > > > > 4 4 4 4 4 4 4 4 8''''''77777777p
 p
 p
 p
 p
M-:"EF p
 p
 p
f    xX=>   * O N N N NxX=> N N N N Nr,   