
    O3j.                    T   U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZmZ erPddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddl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+ ddl,m-Z- g dZ. e	dd      Z/ e	dd      Z0 e	dd      Z1 e	dd      Z2 e	dd      Z3 e	dd      Z4dZ5d e6d!<    G d" d#ee2e/f         Z7 G d$ d%e7e3e0f   ee3e0f         Z8 G d& d'e7e4e1f   ee4e1f         Z9 G d( d)ee2e/f   ee2e/f         Z:	 	 	 	 	 	 	 	 d+d*Z;y),z=Almost entirely complete, generic `selectors` implementation.    )annotationsN)partial)TYPE_CHECKINGProtocolTypeVaroverload)CompliantExpr)_parse_time_unit_and_time_zone%dtype_matches_time_unit_and_time_zoneget_column_namesis_compliant_dataframe)
CollectionIterableIteratorSequence)timezone)	TypeAlias)SelfTypeIs)
NativeExpr)CompliantDataFrameAnyCompliantExprAnyCompliantFrameAnyCompliantLazyFrameAnyCompliantSeriesAnyCompliantSeriesOrNativeExprAny	EvalNames
EvalSeries)ImplementationVersion_LimitedContext)DType)TimeUnit)CompliantSelectorCompliantSelectorNamespaceEagerSelectorNamespaceLazySelectorNamespaceSeriesOrExprTr   )boundSeriesTr   ExprTr   FrameTr   
DataFrameTr   
LazyFrameTr   zOCompliantSelector[FrameT, SeriesOrExprT] | CompliantExpr[FrameT, SeriesOrExprT]r   SelectorOrExprc                      e Zd ZU ded<   ded<   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y) r%   r   _implementationr    _versionc                     y N selfs    J/DATA/.local/lib/python3.12/site-packages/narwhals/_compliant/selectors.py	_selectorz$CompliantSelectorNamespace._selector?   s    KN    c               l    | j                  |       }|j                  |_        |j                  |_        |S r4   )__new__r1   r2   )clscontextobjs      r8   from_namespacez)CompliantSelectorNamespace.from_namespaceA   s0    kk#%55''
r:   c                    y r4   r5   r7   dfs     r8   _iter_columnsz(CompliantSelectorNamespace._iter_columnsH   s    sr:   c                    y r4   r5   rB   s     r8   _iter_schemaz'CompliantSelectorNamespace._iter_schemaI   s    #r:   c                    y r4   r5   rB   s     r8   _iter_columns_dtypesz/CompliantSelectorNamespace._iter_columns_dtypesJ   s    03r:   c             #  n   K   t        | j                  |      |j                  d      E d {    y 7 wNTstrict)ziprD   columnsrB   s     r8   _iter_columns_namesz.CompliantSelectorNamespace._iter_columns_namesM   s'     t))"-rzz$GGGs   +535c               ^     d fd}d fd} j                   j                  ||       S )Nc                r    j                  |       D cg c]  \  }}t        |      s| c}}S c c}}w r4   )rH   
isinstance)rC   sertpdtyper7   s      r8   seriesz4CompliantSelectorNamespace._is_dtype.<locals>.seriesS   s>    #'#<#<R#@#@RJrSXDY#@     33c                r    j                  |       D cg c]  \  }}t        |      s| c}}S c c}}w r4   )rF   rR   )rC   namerT   rU   r7   s      r8   namesz3CompliantSelectorNamespace._is_dtype.<locals>.namesX   s6    )-):):2)>X)>XT2*RQVBWD)>XXXrW   r>   rC   r,   returnzSequence[SeriesOrExprT]rC   r,   r]   zSequence[str]r9   from_callables)r7   rU   rV   rZ   s   ``  r8   	_is_dtypez$CompliantSelectorNamespace._is_dtypeP   s,    	
	Y ~~,,VUD,IIr:   c                ^     d fd}d fd} j                   j                  ||       S )Nc                b    j                  |       D cg c]  \  }}|v s| c}}S c c}}w r4   rH   )rC   rS   rT   dtypesr7   s      r8   rV   z3CompliantSelectorNamespace.by_dtype.<locals>.seriesa   s2    '+'@'@'DU'DGCfC'DUUU   ++c                b    j                  |       D cg c]  \  }}|v s| c}}S c c}}w r4   rF   )rC   rY   rT   re   r7   s      r8   rZ   z2CompliantSelectorNamespace.by_dtype.<locals>.namesd   s2    )-):):2)>O)>XT2",D)>OOOrf   r[   r\   r^   r_   )r7   re   rV   rZ   s   ``  r8   by_dtypez#CompliantSelectorNamespace.by_dtype^   s-    	V	P ~~,,VUD,IIr:   c                     t        j                  |      d fd}dfd} j                  j                  ||       S )Nc                z   t        |       roj                  j                         sUj                  j                         s;| j                  D cg c]%  }j                  |      s| j                  |      ' c}S j                  |       D cg c]  \  }}j                  |      s| c}}S c c}w c c}}w r4   )r   r1   	is_duckdbis_ibisrN   search
get_columnrO   )rC   colrS   rY   pr7   s       r8   rV   z2CompliantSelectorNamespace.matches.<locals>.seriesl   s    &r*,,668,,44668jjRjsAHHSMc*jRR)-)A)A")EX)EICRVC)EXX SXs   B2&B2B7*B7c                f    | j                   D cg c]  }j                  |      s| c}S c c}w r4   )rN   rn   )rC   rp   rq   s     r8   rZ   z1CompliantSelectorNamespace.matches.<locals>.namesv   s)    #%::?:C#C:???s   ..r[   r\   r^   )recompiler9   r`   )r7   patternrV   rZ   rq   s   `   @r8   matchesz"CompliantSelectorNamespace.matchesi   s;    JJw	Y	@ ~~,,VUD,IIr:   c                X     d fd}d fd} j                   j                  ||       S )Nc                z    j                  |       D cg c]  \  }}|j                         s| c}}S c c}}w r4   )rH   
is_numeric)rC   rS   rT   r7   s      r8   rV   z2CompliantSelectorNamespace.numeric.<locals>.series|   s4    '+'@'@'DX'DGCC'DXXX   77c                z    j                  |       D cg c]  \  }}|j                         s| c}}S c c}}w r4   )rF   ry   )rC   rY   rT   r7   s      r8   rZ   z1CompliantSelectorNamespace.numeric.<locals>.names   s4    )-):):2)>R)>XT2"--/D)>RRRrz   r[   r\   r^   r_   )r7   rV   rZ   s   `  r8   numericz"CompliantSelectorNamespace.numeric{   s-    	Y	S ~~,,VUD,IIr:   c                `    | j                  | j                  j                  j                        S r4   )ra   r2   re   Categoricalr6   s    r8   categoricalz&CompliantSelectorNamespace.categorical   s!    ~~dmm22>>??r:   c                `    | j                  | j                  j                  j                        S r4   )ra   r2   re   Stringr6   s    r8   stringz!CompliantSelectorNamespace.string   s!    ~~dmm2299::r:   c                `    | j                  | j                  j                  j                        S r4   )ra   r2   re   Booleanr6   s    r8   booleanz"CompliantSelectorNamespace.boolean   s!    ~~dmm22::;;r:   c                T     d fd} j                   j                  |t               S )Nc                8    t        j                  |             S r4   )listrD   )rC   r7   s    r8   rV   z.CompliantSelectorNamespace.all.<locals>.series   s    **2.//r:   r[   r\   )r9   r`   r   )r7   rV   s   ` r8   allzCompliantSelectorNamespace.all   s'    	0 ~~,,V5Et,TTr:   c                     t        ||      \  }}t        t         j                  j                  ||      d fd}d fd} j
                  j                  ||       S )N)re   
time_units
time_zonesc                j    j                  |       D cg c]  \  }} |      s| c}}S c c}}w r4   rd   )rC   rS   rT   rv   r7   s      r8   rV   z3CompliantSelectorNamespace.datetime.<locals>.series   s3    '+'@'@'DT'DGCPRC'DTTT   //c                j    j                  |       D cg c]  \  }} |      s| c}}S c c}}w r4   rh   )rC   rY   rT   rv   r7   s      r8   rZ   z2CompliantSelectorNamespace.datetime.<locals>.names   s2    )-):):2)>N)>XT2'"+D)>NNNr   r[   r\   r^   )r
   r   r   r2   re   r9   r`   )r7   	time_unit	time_zoner   r   rV   rZ   rv   s   `      @r8   datetimez#CompliantSelectorNamespace.datetime   sa    
 "@	9!U
J1==''!!	
	U	O ~~,,VUD,IIr:   N)r]   z.type[CompliantSelector[FrameT, SeriesOrExprT]])r>   r!   r]   r   )rC   r,   r]   zIterator[SeriesOrExprT])rC   r,   r]   Iterator[tuple[str, DType]])rC   r,   r]   z%Iterator[tuple[SeriesOrExprT, DType]])rC   r,   r]   z#Iterator[tuple[SeriesOrExprT, str]])r7   1CompliantSelectorNamespace[FrameT, SeriesOrExprT]rU   ztype[DType]r]   (CompliantSelector[FrameT, SeriesOrExprT])re   zCollection[DType | type[DType]]r]   r   )ru   strr]   r   r]   r   )r   z$TimeUnit | Iterable[TimeUnit] | Noner   z7str | timezone | Iterable[str | timezone | None] | Noner]   r   )__name__
__module____qualname____annotations__propertyr9   classmethodr@   rD   rF   rH   rO   ra   ri   rv   r|   r   r   r   r   r   r5   r:   r8   r%   r%   :   s    ##N N  KM44	.4HJ?JHSJ	1J	J5	J	1	JJ$J@;<UJ7J KJ 
2	Jr:   r%   c                  $    e Zd ZddZddZddZy)r&   c             #  l   K   | j                  |      D ]  }|j                  |j                  f  y wr4   )rD   rY   rU   r7   rC   rS   s      r8   rF   z#EagerSelectorNamespace._iter_schema   s.     %%b)C((CII%% *s   24c             #  @   K   |j                         E d {    y 7 wr4   )iter_columnsrB   s     r8   rD   z$EagerSelectorNamespace._iter_columns   s     ??$$$   c             #  X   K   | j                  |      D ]  }||j                  f  y wr4   )rD   rU   r   s      r8   rH   z+EagerSelectorNamespace._iter_columns_dtypes   s)     %%b)Csyy.  *s   (*N)rC   r-   r]   r   )rC   r-   r]   zIterator[SeriesT])rC   r-   r]   zIterator[tuple[SeriesT, DType]]r   r   r   rF   rD   rH   r5   r:   r8   r&   r&      s    &%!r:   r&   c                  $    e Zd ZddZddZddZy)r'   c              #  T   K   |j                   j                         E d {    y 7 wr4   )schemaitemsrB   s     r8   rF   z"LazySelectorNamespace._iter_schema   s     99??$$$s   (&(c              #  @   K   |j                         E d {    y 7 wr4   )rD   rB   s     r8   rD   z#LazySelectorNamespace._iter_columns   s     ##%%%r   c             #     K   t        | j                  |      |j                  j                         d      E d {    y 7 wrJ   )rM   rD   r   valuesrB   s     r8   rH   z*LazySelectorNamespace._iter_columns_dtypes   s0     t))"-ryy/?/?/A$OOOs   9AAAN)rC   r.   r]   r   )rC   r.   r]   zIterator[ExprT])rC   r.   r]   zIterator[tuple[ExprT, DType]]r   r5   r:   r8   r'   r'      s    %&Pr:   r'   c                  >   e Zd ZU ded<   ded<   ded<   ded<   e	 	 	 	 	 	 	 	 dd	       Zedd
       ZddZ	 	 	 	 ddZ	e
dd       Ze
	 	 	 	 dd       Z	 	 	 	 ddZe
dd       Ze
	 	 	 	 dd       Z	 	 	 	 ddZe
dd       Ze
	 	 	 	 dd       Z	 	 	 	 ddZddZy) r$   !EvalSeries[FrameT, SeriesOrExprT]_callr   _function_namer   r1   r    r2   c                   | j                  |       }||_        ||_        d |_        |j                  |_        |j
                  |_        |S r4   )r<   r   _evaluate_output_names_alias_output_namesr1   r2   )r=   callevaluate_output_namesr>   r?   s        r8   r`   z CompliantSelector.from_callables   sI     kk#	%:""&%55''
r:   c                6    | j                         j                  S r4   )__narwhals_namespace__	selectorsr6   s    r8   r   zCompliantSelector.selectors   s    **,666r:   c                     y r4   r5   r6   s    r8   _to_exprzCompliantSelector._to_expr   s    r:   c                ,    t        |t        |             S r4   )rR   typer7   others     r8   _is_selectorzCompliantSelector._is_selector   s     %d,,r:   c                     y r4   r5   r   s     r8   __sub__zCompliantSelector.__sub__       ,/r:   c                     y r4   r5   r   s     r8   r   zCompliantSelector.__sub__        03r:   c                      j                        r6d fd}d fd} j                  j                  j                  ||       S  j	                         z
  S )Nc                    t        |       \  }}t         |       |d      D cg c]  \  }}||vr| c}}S c c}}w rJ   _eval_lhs_rhsrM   rC   	lhs_names	rhs_namesxrY   r   r7   s        r8   rV   z)CompliantSelector.__sub__.<locals>.series   sV    '4Ru'E$	9 $'tBx4#H#H49, #H     =c                X    t        |       \  }}|D cg c]	  }||vs| c}S c c}w r4   r   rC   r   r   r   r   r7   s       r8   rZ   z(CompliantSelector.__sub__.<locals>.names   s5    '4Ru'E$	9#,C9a0B9CCC   	''r[   r\   r^   r   r   r9   r`   r   r7   r   rV   rZ   s   ``  r8   r   zCompliantSelector.__sub__   sT     U#D >>++::65RV:WW}}&&r:   c                     y r4   r5   r   s     r8   __or__zCompliantSelector.__or__  s    +.r:   c                     y r4   r5   r   s     r8   r   zCompliantSelector.__or__  r   r:   c                      j                        r6d fd}d fd} j                  j                  j                  ||       S  j	                         z  S )Nc                t    t        |       \  }g fdt         |       |d      D         |       S )Nc              3  0   K   | ]  \  }}|vr|  y wr4   r5   ).0r   rY   r   s      r8   	<genexpr>z;CompliantSelector.__or__.<locals>.series.<locals>.<genexpr>  s%      'LGAty0 'Ls   TrK   r   rC   r   r   r   r7   s     @r8   rV   z(CompliantSelector.__or__.<locals>.series  sM    '4Ru'E$	9'*48Yt'L 2Y r:   c                D    t        |       \  }g fd|D        S )Nc              3  ,   K   | ]  }|vs|  y wr4   r5   )r   r   r   s     r8   r   z:CompliantSelector.__or__.<locals>.names.<locals>.<genexpr>  s     EY!92D!Ys   	r   r   s     @r8   rZ   z'CompliantSelector.__or__.<locals>.names  s,    '4Ru'E$	9REYER	RRr:   r[   r\   r^   r   r   s   ``  r8   r   zCompliantSelector.__or__  sT     U#	S >>++::65RV:WW}}&&r:   c                     y r4   r5   r   s     r8   __and__zCompliantSelector.__and__  r   r:   c                     y r4   r5   r   s     r8   r   zCompliantSelector.__and__!  r   r:   c                      j                        r6d fd}d fd} j                  j                  j                  ||       S  j	                         z  S )Nc                    t        |       \  }}t         |       |d      D cg c]  \  }}||v r| c}}S c c}}w rJ   r   r   s        r8   rV   z)CompliantSelector.__and__.<locals>.series*  sV    '4Ru'E$	9 $'tBx4#H#H4y( #H  r   c                X    t        |       \  }}|D cg c]	  }||v s| c}S c c}w r4   r   r   s       r8   rZ   z(CompliantSelector.__and__.<locals>.names2  s4    '4Ru'E$	9#,?9aY9???r   r[   r\   r^   r   r   s   ``  r8   r   zCompliantSelector.__and__%  sT     U#@ >>++::65RV:WW}}&&r:   c                <    | j                   j                         | z
  S r4   )r   r   r6   s    r8   
__invert__zCompliantSelector.__invert__9  s    ~~!!#d**r:   N)r   r   r   zEvalNames[FrameT]r>   r!   r]   r   )r]   r   )r]   $CompliantExpr[FrameT, SeriesOrExprT])r   z+Self | CompliantExpr[FrameT, SeriesOrExprT]r]   z0TypeIs[CompliantSelector[FrameT, SeriesOrExprT]])r   r   r]   r   )r   r   r]   r   )r   %SelectorOrExpr[FrameT, SeriesOrExprT]r]   r   r   )r   r   r   r   r   r`   r   r   r   r   r   r   r   r   r   r5   r:   r8   r$   r$      s]    -,##/  1
 ! 
  7 7 D-@-	9-
 / /393	-3 3':'	.'( . .393	-3 3':'	.'. / /393	-3 3':'	.'(+r:   r$   c                F    |j                  |       |j                  |       fS r4   )r   )rC   lhsrhss      r8   r   r   =  s%     %%b)3+E+Eb+IIIr:   )rC   r   r   r   r   r   r]   z#tuple[Sequence[str], Sequence[str]])<__doc__
__future__r   rs   	functoolsr   typingr   r   r   r   narwhals._compliant.exprr	   narwhals._utilsr
   r   r   r   collections.abcr   r   r   r   r   r   r   typing_extensionsr   r   r   narwhals._compliant.typingr   r   r   r   r   r   r   r   r   r    r!   narwhals.dtypesr"   narwhals.typingr#   __all__r(   r*   r+   r,   r-   r.   r/   r   r%   r&   r'   r$   r   r5   r:   r8   <module>r      sq   C " 	  = = 2  HH! .3	 	 	 IH%( /OP
)#7
8|,	!4	5\)@A
\)@A
U 	 
lJ&-*?!@ lJ^!z723Xj'>Q5R!
Pz5018J<M3N
Pu+&-'((6=3H*Iu+pJJ 0J7GJ(Jr:   