
    }i,                    ,   U d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
mZmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZ er=d dlmZmZmZmZm Z  d dl!m"Z"m#Z# d d	l$m%Z% d d
lm&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ eZ0de1d<   g dZ2 G d deee
f                   Z3 G d deeef                   Z4 G d de3eef         eeef                   Z5 G d de3eef         eeeef                   Z6 G d de5eef         eeeeeef                   Z7dS )    )annotations)partial)TYPE_CHECKINGAnyProtocoloverload)CompliantExprTCompliantExprT_coCompliantFrameTCompliantLazyFrameTDepthTrackingExprTEagerDataFrameT
EagerExprTEagerSeriesT_co	LazyExprTNativeFrameTNativeSeriesT)exclude_column_namesget_column_namespassthrough_column_names)is_numpy_array_2d)
CollectionIterableIteratorKeysViewSequence)	TypeAliasTypeIs)CompliantSelectorNamespace)ImplementationVersion)ConcatMethodCorrelationMethodInto1DArray	IntoDType
IntoSchemaNonNestedLiteral_2DArrayr   
Incomplete)CompliantNamespaceDepthTrackingNamespaceEagerNamespaceLazyNamespacec                      e Zd ZU ded<   ded<   ed8d            Zd9d	Zd:dZd:dZd;dZ	d<dZ
d9d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dAd,ZedBd.            Zd?d/Zd?d0ZdCd3ZdDd6Zd7S )Er*   r    _implementationr!   _versionreturntype[CompliantExprT]c                    d S N selfs    Q/home/jrussi/.local/lib/python3.11/site-packages/narwhals/_compliant/namespace.py_exprzCompliantNamespace._expr:   s    -0S    r	   c                D    | j                             t          |           S Ncontextr9   from_column_namesr   r6   s    r8   allzCompliantNamespace.all=       z++,<d+KKKr:   namesstrc                T    | j                             t          |          |           S r<   r9   r@   r   r7   rC   s     r8   colzCompliantNamespace.col@   '    z++,DU,K,KUY+ZZZr:   c                b    | j                             t          t          |          |           S N)rC   r=   r9   r@   r   r   rG   s     r8   excludezCompliantNamespace.excludeC   4    z++(666 , 
 
 	
r:   indicesSequence[int]c                &     | j         j        |d| iS )Nr>   )r9   from_column_indices)r7   rO   s     r8   nthzCompliantNamespace.nthH   s    -tz-wEEEEr:   abmethodr#   c                   d S r4   r5   )r7   rT   rU   rV   s       r8   corrzCompliantNamespace.corrK       r:   c                    d S r4   r5   r6   s    r8   lenzCompliantNamespace.lenN         r:   valuer'   dtypeIntoDType | Nonec                    d S r4   r5   r7   r]   r^   s      r8   litzCompliantNamespace.litO   r\   r:   exprsignore_nullsboolc                   d S r4   r5   r7   rd   rc   s      r8   all_horizontalz!CompliantNamespace.all_horizontalP   rY   r:   c                   d S r4   r5   rg   s      r8   any_horizontalz!CompliantNamespace.any_horizontalS   rY   r:   c                    d S r4   r5   r7   rc   s     r8   sum_horizontalz!CompliantNamespace.sum_horizontalV   r\   r:   c                    d S r4   r5   rl   s     r8   mean_horizontalz"CompliantNamespace.mean_horizontalW   r\   r:   c                    d S r4   r5   rl   s     r8   min_horizontalz!CompliantNamespace.min_horizontalX   r\   r:   c                    d S r4   r5   rl   s     r8   max_horizontalz!CompliantNamespace.max_horizontalY   r\   r:   itemsIterable[CompliantFrameT]howr"   r   c                   d S r4   r5   )r7   rt   rv   s      r8   concatzCompliantNamespace.concatZ   s    #r:   	separatorc                   d S r4   r5   )r7   ry   rd   rc   s       r8   
concat_strzCompliantNamespace.concat_str]   rY   r:   $CompliantSelectorNamespace[Any, Any]c                    d S r4   r5   r6   s    r8   	selectorszCompliantNamespace.selectors`   s    ADr:   c                    d S r4   r5   rl   s     r8   structzCompliantNamespace.structb   r\   r:   c                    d S r4   r5   rl   s     r8   coalescezCompliantNamespace.coalescec   r\   r:   datar   c                   d S r4   r5   r7   r   s     r8   from_nativezCompliantNamespace.from_nativee   r\   r:   objTypeIs[Any]c                   dS )z6Return `True` if `obj` can be passed to `from_native`.Nr5   r7   r   s     r8   	is_nativezCompliantNamespace.is_nativef   s    r:   N)r1   r2   )r1   r	   )rC   rD   r1   r	   )rO   rP   r1   r	   )rT   r	   rU   r	   rV   r#   r1   r	   )r]   r'   r^   r_   r1   r	   )rc   r	   rd   re   r1   r	   )rc   r	   r1   r	   )rt   ru   rv   r"   r1   r   )rc   r	   ry   rD   rd   re   r1   r	   )r1   r|   )r   r   r1   r   )r   r   r1   r   )__name__
__module____qualname____annotations__propertyr9   rA   rH   rM   rS   rX   r[   rb   rh   rj   rm   ro   rq   rs   rx   r{   r~   r   r   r   r   r5   r:   r8   r*   r*   5   s        ####000 X0L L L L[ [ [ [
 
 
 

F F F F    )(((ZZZZ       LKKKLLLLKKKKKKKK       DDD XDCCCCEEEE3333     r:   r*   c                  *    e Zd ZdZddZddZddZdS )AlignDiagonalz2Mixin to help support `"diagonal*"` concatenation.r]   r'   r^   r_   r1   r
   c                    d S r4   r5   ra   s      r8   rb   zAlignDiagonal.litn   s    Cr:   framesCollection[CompliantFrameT]Sequence[CompliantFrameT]c               8   d |D             }t          |          }t          t          |                    }|                                |D ]5}|                    fd|                                D                        6|                     |||          S )a7  Prepare frames with differing schemas for vertical concatenation.

        Adapted from [`convert_diagonal_concat`].

        [`convert_diagonal_concat`]: https://github.com/pola-rs/polars/blob/c2412600210a21143835c9dfcb0a9182f462b619/crates/polars-plan/src/plans/conversion/dsl_to_ir/concat.rs#L10-L68
        c                6    g | ]}|                                 S r5   )collect_schema).0frames     r8   
<listcomp>z0AlignDiagonal.align_diagonal.<locals>.<listcomp>z   s$    >>>e5''))>>>r:   c              3  .   K   | ]\  }}|v	||fV  d S r4   r5   )r   nmr^   seens      r8   	<genexpr>z/AlignDiagonal.align_diagonal.<locals>.<genexpr>   s0      WWURV"eWWr:   )iterdictnextkeysupdatert   _align_diagonal)r7   r   schemas
it_schemasunionschemar   s         @r8   align_diagonalzAlignDiagonal.align_diagonalq   s     ?>v>>> ']]
T*%%&&zz||  	X 	XFLLWWWWfllnnWWWWWWW##FGU;;;r:   ru   r   Iterable[IntoSchema]union_schemar&   c                                                      i d fddfd
fdt          ||          D             S )NmissingIterable[str]r1   Iterator[CompliantExprT_co]c              3     K   | D ]S}                     |          x}6|         }                    d |                              |          x}|<   |V  Td S r4   )getrb   alias)r   nameexprr^   
null_exprsr7   r   s       r8   iter_missing_exprsz9AlignDiagonal._align_diagonal.<locals>.iter_missing_exprs   sw        &NN4000D9(.E.2hhtU.C.C.I.I$.O.OOD:d+



	 r:   dfr   columnsKeysView[str]c                L    |z
  x}r | j          |           }  | j         S r4   )with_columnssimple_select)r   r   r   r   union_namess      r8   alignz,AlignDiagonal._align_diagonal.<locals>.align   s@    %//w C$R_&8&8&A&AB#2#[11r:   c                R    g | ]#\  }} ||                                           $S r5   )r   )r   r   r   r   s      r8   r   z1AlignDiagonal._align_diagonal.<locals>.<listcomp>   s1    VVVveV[[]]++VVVr:   )r   r   r1   r   )r   r   r   r   r1   r   )r   zip)r7   r   r   r   r   r   r   r   s   `  `@@@@r8   r   zAlignDiagonal._align_diagonal   s     #''))35
	 	 	 	 	 	 	 		2 	2 	2 	2 	2 	2 	2 WVVVVWAUAUVVVVr:   N)r]   r'   r^   r_   r1   r
   )r   r   r1   r   )r   ru   r   r   r   r&   r1   r   )r   r   r   __doc__rb   r   r   r5   r:   r8   r   r   k   s\        <<       < < < <&W W W W W Wr:   r   c                  &    e Zd Zd	dZd
dZd
dZdS )r+   r1   r   c                D    | j                             t          |           S r<   r?   r6   s    r8   rA   zDepthTrackingNamespace.all   rB   r:   rC   rD   c                T    | j                             t          |          |           S r<   rF   rG   s     r8   rH   zDepthTrackingNamespace.col   rI   r:   c                b    | j                             t          t          |          |           S rK   rL   rG   s     r8   rM   zDepthTrackingNamespace.exclude   rN   r:   N)r1   r   )rC   rD   r1   r   )r   r   r   rA   rH   rM   r5   r:   r8   r+   r+      sX        L L L L[ [ [ [
 
 
 
 
 
r:   r+   c                  N    e Zd Zedd            Zedd            Zdd	ZddZdS )r-   r1   tuple[int, ...]c                4    | j                                         S r4   r/   _backend_versionr6   s    r8   r   zLazyNamespace._backend_version       #44666r:   type[CompliantLazyFrameT]c                    d S r4   r5   r6   s    r8   
_lazyframezLazyNamespace._lazyframe   s    7:sr:   r   r   TypeIs[NativeFrameT]c               6    | j                             |          S r4   )r   
_is_nativer   s     r8   r   zLazyNamespace.is_native   s    ))#...r:   r   NativeFrameT | Anyr   c                   | j                             |          r| j                             ||           S dt          |          j        }t          |          Nr=   zUnsupported type: )r   r   r   typer   	TypeErrorr7   r   msgs      r8   r   zLazyNamespace.from_native   sX    ?%%d++ 	C?..tT.BBB:4::#6::nnr:   Nr1   r   )r1   r   )r   r   r1   r   )r   r   r1   r   )r   r   r   r   r   r   r   r   r5   r:   r8   r-   r-      st         7 7 7 X7 ::: X:/ / / /     r:   r-   c                     e Zd Zed5d            Zed6d            Zed7d            Z	 d8d9dZ	 d8d:dZd;dZ	e
d<d            Ze
d=d            Zd>dZe
d?d@d$            Ze
dAd'            Z	 d8dBd)ZdCd,ZdDd.ZdCd/ZdEd4ZdS )Fr,   r1   r   c                4    | j                                         S r4   r   r6   s    r8   r   zEagerNamespace._backend_version   r   r:   type[EagerDataFrameT]c                    d S r4   r5   r6   s    r8   
_dataframezEagerNamespace._dataframe   s    363r:   type[EagerSeriesT_co]c                    d S r4   r5   r6   s    r8   _serieszEagerNamespace._series   s    03r:   Nwhenr   then	otherwiseNativeSeriesT | Nonec                    d S r4   r5   )r7   r   r   r   s       r8   _if_then_elsezEagerNamespace._if_then_else   s	    
 r:   	predicater   EagerExprT | Nonec           	          d
 fd} j                             |t          dd           t          dd           	          S )Nr   r   r1   Sequence[EagerSeriesT_co]c                   |                                }|j        }|                      	          }/ |||          \  }}                    |j        |j                  }0 |||          \  }}                    |j        |j                  }nL|                                } ||||          \  }}}                    |j        |j        |j                  }|                    |          gS r4   )_evaluate_single_output_expr_align_full_broadcastr   native_with_native)
r   predicate_sr   then_sresultotherwise_sr   r   r7   r   s
         r8   funcz&EagerNamespace.when_then.<locals>.func   s	   99)DDK5E44T::F &+eK&@&@#V++K,>NN &+eK&@&@#V++K,>NN ==iHH385fk3Z3Z0V[++&{7I  ''//00r:   _evaluate_output_namesc                    dgS )Nliteralr5   )_dfs    r8   <lambda>z*EagerNamespace.when_then.<locals>.<lambda>   s    YK r:   _alias_output_names)r   evaluate_output_namesalias_output_namesr>   )r   r   r1   r   )r9   _from_callablegetattr)r7   r   r   r   r   s   ```` r8   	when_thenzEagerNamespace.when_then   s    	1 	1 	1 	1 	1 	1 	1 	1 	1( z((").0G0G# #  't-BDII ) 
 
 	
r:   r   r   $TypeIs[NativeFrameT | NativeSeriesT]c               j    | j                             |          p| j                            |          S r4   )r   r   r   r   s     r8   r   zEagerNamespace.is_native   s-    ))#..N$,2I2I#2N2NNr:   r   r   r   c                   d S r4   r5   r   s     r8   r   zEagerNamespace.from_native   s    EHSr:   r   c                   d S r4   r5   r   s     r8   r   zEagerNamespace.from_native   s    FIcr:   "NativeFrameT | NativeSeriesT | Any!EagerDataFrameT | EagerSeriesT_coc               &   | j                             |          r| j                             ||           S | j                            |          r| j                            ||           S dt	          |          j        }t          |          r   )r   r   r   r   r   r   r   r   s      r8   r   zEagerNamespace.from_native   s     ?%%d++ 	C?..tT.BBB<""4(( 	@<++D$+???:4::#6::nnr:   .r   Noner$   c                   d S r4   r5   r7   r   r   s      r8   
from_numpyzEagerNamespace.from_numpy  s    WZWZr:   !IntoSchema | Sequence[str] | Noner(   c                   d S r4   r5   r  s      r8   r  zEagerNamespace.from_numpy	  s	     #r:   Into1DArray | _2DArrayc                   t          |          r| j                            |||           S | j                            ||           S )N)r   r>   r=   )r   r   r  r   r  s      r8   r  zEagerNamespace.from_numpy  sM     T"" 	Q?--d64-PPP|&&tT&:::r:   dfsSequence[NativeFrameT]c                   d S r4   r5   r7   r  s     r8   _concat_diagonalzEagerNamespace._concat_diagonal  r\   r:   Sequence[NativeFrameT | Any]c                   d S r4   r5   r  s     r8   _concat_horizontalz!EagerNamespace._concat_horizontal  s    sr:   c                   d S r4   r5   r  s     r8   _concat_verticalzEagerNamespace._concat_vertical  r\   r:   rt   Iterable[EagerDataFrameT]rv   r"   c                  d |D             }|dk    r|                      |          }n?|dk    r|                     |          }n#|dk    r|                     |          }nt          | j                            ||           S )Nc                    g | ]	}|j         
S r5   )r   )r   items     r8   r   z)EagerNamespace.concat.<locals>.<listcomp>   s    ---tt{---r:   
horizontalverticaldiagonalr=   )r  r  r  NotImplementedErrorr   r   )r7   rt   rv   r  r   s        r8   rx   zEagerNamespace.concat  s     .-u---,,,S11FFJ**3//FFJ**3//FF%%**64*@@@r:   r   )r1   r   )r1   r   r4   )r   r   r   r   r   r   r1   r   )r   r   r   r   r   r   r1   r   )r   r   r1   r  )r   r   r1   r   )r   r   r1   r   )r   r  r1   r  ).)r   r
  r   r$   r1   r   )r   r  r   r(   r1   r   )r   r  r   r  r1   r  )r  r  r1   r   )r  r  r1   r   )rt   r  rv   r"   r1   r   )r   r   r   r   r   r   r   r   r  r   r   r   r  r  r  r  rx   r5   r:   r8   r,   r,      s        7 7 7 X7 666 X6333 X3
 +/	     W[
 
 
 
 
@O O O O HHH XHIII XI    ZZZZ XZ   X 59	; ; ; ; ; TSSS    TSSSA A A A A Ar:   r,   N)8
__future__r   	functoolsr   typingr   r   r   r   narwhals._compliant.typingr	   r
   r   r   r   r   r   r   r   r   r   narwhals._utilsr   r   r   narwhals.dependenciesr   collections.abcr   r   r   r   r   typing_extensionsr   r   narwhals._compliant.selectorsr   r    r!   narwhals.typingr"   r#   r$   r%   r&   r'   r(   r)   r   __all__r*   r   r+   r-   r,   r5   r:   r8   <module>r/     sm   " " " " " " "       9 9 9 9 9 9 9 9 9 9 9 9                                  
 4 3 3 3 3 3  RRRRRRRRRRRRRR33333333HHHHHH77777777                   J  3 3 3 3 3/>"AB 3 3 3l1W 1W 1W 1W 1WH_.??@ 1W 1W 1Wh
 
 
 
 
(::;_001
 
 
     *I56 )\9:  (fA fA fA fA fA?J67_oz<VWfA fA fA fA fAr:   