
    -Ph.                       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
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mZmZ erBd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!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Z0 edd          Z1 edd          Z2 edd          Z3 edd          Z4 edd          Z5 edd          Z6dZ7de8d <    G d! d"ee4e1f                   Z9 G d# d$e9e5e2f         ee5e2f                   Z: G d% d&e9e6e3f         ee6e3f                   Z; G d' d(ee4e1f         ee4e1f                   Z<d0d/Z=dS )1z=Almost entirely complete, generic `selectors` implementation.    )annotationsN)partial)TYPE_CHECKING
CollectionIterableIteratorProtocolSequenceTypeVaroverload)CompliantExpr)
Protocol38)_parse_time_unit_and_time_zone%dtype_matches_time_unit_and_time_zoneget_column_namesis_compliant_dataframe)timezone)Self	TypeAliasTypeIs)
NativeExpr)	CompliantDataFrameAnyCompliantExprAnyCompliantFrameAnyCompliantLazyFrameAnyCompliantSeriesAnyCompliantSeriesOrNativeExprAny	EvalNames
EvalSeriesScalarKwargs)ImplementationVersion_FullContext)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<   ded<   ed/d            Zed0d            Zd1dZd2dZ	d3dZ
d4dZd5dZd6d Zd7d#Zd8d$Zd8d%Zd8d&Zd8d'Zd8d(Zd9d-Zd.S ):r'   r!   _implementationtuple[int, ...]_backend_versionr"   _versioncontextr#   returnr   c               x    |                      |           }|j        |_        |j        |_        |j        |_        |S N)__new__r3   r5   r6   )clsr7   objs      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/narwhals/_compliant/selectors.pyfrom_namespacez)CompliantSelectorNamespace.from_namespaceH   s8    kk#%5&7'
    .type[CompliantSelector[FrameT, SeriesOrExprT]]c                    d S r:    selfs    r>   	_selectorz$CompliantSelectorNamespace._selectorP   s    KN3r@   dfr.   Iterator[SeriesOrExprT]c                   d S r:   rC   rE   rG   s     r>   _iter_columnsz(CompliantSelectorNamespace._iter_columnsS         r@   Iterator[tuple[str, DType]]c                   d S r:   rC   rJ   s     r>   _iter_schemaz'CompliantSelectorNamespace._iter_schemaU   rL   r@   %Iterator[tuple[SeriesOrExprT, DType]]c                   d S r:   rC   rJ   s     r>   _iter_columns_dtypesz/CompliantSelectorNamespace._iter_columns_dtypesW   s    03r@   #Iterator[tuple[SeriesOrExprT, str]]c             #  f   K   t          |                     |          |j                  E d {V  d S r:   )ziprK   columnsrJ   s     r>   _iter_columns_namesz.CompliantSelectorNamespace._iter_columns_names[   s>      t))"--rz:::::::::::r@   rE   1CompliantSelectorNamespace[FrameT, SeriesOrExprT]dtypetype[DType](CompliantSelector[FrameT, SeriesOrExprT]c               \     d	 fd}d
 fd} j                             ||           S )NrG   r.   r8   Sequence[SeriesOrExprT]c                F    fd                     |           D             S )Nc                :    g | ]\  }}t          |          |S rC   
isinstance).0sertprY   s      r>   
<listcomp>zHCompliantSelectorNamespace._is_dtype.<locals>.series.<locals>.<listcomp>b   s=       RJrSXDYDY  r@   rR   rG   rY   rE   s    r>   seriesz4CompliantSelectorNamespace._is_dtype.<locals>.seriesa   s<       #'#<#<R#@#@   r@   Sequence[str]c                F    fd                     |           D             S )Nc                :    g | ]\  }}t          |          |S rC   r`   )rb   namerd   rY   s      r>   re   zGCompliantSelectorNamespace._is_dtype.<locals>.names.<locals>.<listcomp>g   s-    XXXXT2*RQVBWBWXDXXXr@   rO   rg   s    r>   namesz3CompliantSelectorNamespace._is_dtype.<locals>.namesf   s+    XXXX):):2)>)>XXXXr@   r7   rG   r.   r8   r]   rG   r.   r8   ri   rF   from_callables)rE   rY   rh   rn   s   ``  r>   	_is_dtypez$CompliantSelectorNamespace._is_dtype^   sp    	 	 	 	 	 	 	
	Y 	Y 	Y 	Y 	Y 	Y 	Y ~,,VUD,IIIr@   dtypesCollection[DType | type[DType]]c                \     d	 fd}d
 fd} j                             ||           S )NrG   r.   r8   r]   c                F    fd                     |           D             S )Nc                "    g | ]\  }}|v 	|S rC   rC   )rb   rc   rd   ru   s      r>   re   zGCompliantSelectorNamespace.by_dtype.<locals>.series.<locals>.<listcomp>o   s"    UUUGCfCr@   rf   rG   ru   rE   s    r>   rh   z3CompliantSelectorNamespace.by_dtype.<locals>.seriesn   s+    UUUUt'@'@'D'DUUUUr@   ri   c                F    fd                     |           D             S )Nc                "    g | ]\  }}|v 	|S rC   rC   )rb   rl   rd   ru   s      r>   re   zFCompliantSelectorNamespace.by_dtype.<locals>.names.<locals>.<listcomp>r   s"    OOOXT2",,D,,,r@   rm   rz   s    r>   rn   z2CompliantSelectorNamespace.by_dtype.<locals>.namesq   s+    OOOO):):2)>)>OOOOr@   ro   rp   rq   rr   )rE   ru   rh   rn   s   ``  r>   by_dtypez#CompliantSelectorNamespace.by_dtypek   sw    	V 	V 	V 	V 	V 	V 	V	P 	P 	P 	P 	P 	P 	P ~,,VUD,IIIr@   patternstrc                     t          j        |          d	 fd}d
fd} j                            ||           S )NrG   r.   r8   r]   c                     t                     rFj                                        s-j                                        s fd j        D             S fd                               D             S )Nc                d    g | ],}                     |                              |          -S rC   )search
get_column)rb   colrG   ps     r>   re   zFCompliantSelectorNamespace.matches.<locals>.series.<locals>.<listcomp>   s4    RRRsAHHSMMRc**RRRr@   c                D    g | ]\  }}                     |          |S rC   r   )rb   rc   rl   r   s      r>   re   zFCompliantSelectorNamespace.matches.<locals>.series.<locals>.<listcomp>   s-    XXXICRVXCXXXr@   )r   r3   	is_duckdbis_ibisrV   rW   )rG   r   rE   s   `r>   rh   z2CompliantSelectorNamespace.matches.<locals>.seriesy   s    &r**S,6688S ,4466S
 SRRRRbjRRRRXXXX)A)A")E)EXXXXr@   ri   c                *    fd| j         D             S )Nc                >    g | ]}                     |          |S rC   r   )rb   r   r   s     r>   re   zECompliantSelectorNamespace.matches.<locals>.names.<locals>.<listcomp>   s(    ???C#?C???r@   )rV   )rG   r   s    r>   rn   z1CompliantSelectorNamespace.matches.<locals>.names   s    ????2:????r@   ro   rp   rq   )recompilerF   rs   )rE   r~   rh   rn   r   s   `   @r>   matchesz"CompliantSelectorNamespace.matchesv   s    Jw	Y 	Y 	Y 	Y 	Y 	Y 	Y	@ 	@ 	@ 	@ 	@ 	@ ~,,VUD,IIIr@   c                V     d	 fd}d
 fd} j                             ||           S )NrG   r.   r8   r]   c                B    d                      |           D             S )Nc                @    g | ]\  }}|                                 |S rC   
is_numeric)rb   rc   rd   s      r>   re   zFCompliantSelectorNamespace.numeric.<locals>.series.<locals>.<listcomp>   s)    XXXGCXCXXXr@   rf   rG   rE   s    r>   rh   z2CompliantSelectorNamespace.numeric.<locals>.series   s%    XXt'@'@'D'DXXXXr@   ri   c                B    d                      |           D             S )Nc                @    g | ]\  }}|                                 |S rC   r   )rb   rl   rd   s      r>   re   zECompliantSelectorNamespace.numeric.<locals>.names.<locals>.<listcomp>   s)    RRRXT2"--//RDRRRr@   rm   r   s    r>   rn   z1CompliantSelectorNamespace.numeric.<locals>.names   s%    RR):):2)>)>RRRRr@   ro   rp   rq   rr   )rE   rh   rn   s   `  r>   numericz"CompliantSelectorNamespace.numeric   sj    	Y 	Y 	Y 	Y 	Y 	Y	S 	S 	S 	S 	S 	S ~,,VUD,IIIr@   c                J    |                      | j        j        j                  S r:   )rt   r6   ru   CategoricalrD   s    r>   categoricalz&CompliantSelectorNamespace.categorical   s    ~~dm2>???r@   c                J    |                      | j        j        j                  S r:   )rt   r6   ru   StringrD   s    r>   stringz!CompliantSelectorNamespace.string   s    ~~dm29:::r@   c                J    |                      | j        j        j                  S r:   )rt   r6   ru   BooleanrD   s    r>   booleanz"CompliantSelectorNamespace.boolean   s    ~~dm2:;;;r@   c                T     d fd} j                             |t                     S )NrG   r.   r8   r]   c                H    t                              |                     S r:   )listrK   r   s    r>   rh   z.CompliantSelectorNamespace.all.<locals>.series   s    **2..///r@   ro   rp   )rF   rs   r   )rE   rh   s   ` r>   allzCompliantSelectorNamespace.all   sA    	0 	0 	0 	0 	0 	0 ~,,V5Et,TTTr@   	time_unit$TimeUnit | Iterable[TimeUnit] | None	time_zone7str | timezone | Iterable[str | timezone | None] | Nonec                     t          ||          \  }}t          t           j        j        ||          d
 fd}d fd} j                            || 	          S )N)ru   
time_units
time_zonesrG   r.   r8   r]   c                F    fd                     |           D             S )Nc                0    g | ]\  }} |          |S rC   rC   )rb   rc   rd   r   s      r>   re   zGCompliantSelectorNamespace.datetime.<locals>.series.<locals>.<listcomp>   s+    TTTGCPRTCTTTr@   rf   rG   r   rE   s    r>   rh   z3CompliantSelectorNamespace.datetime.<locals>.series   s+    TTTTt'@'@'D'DTTTTr@   ri   c                F    fd                     |           D             S )Nc                0    g | ]\  }} |          |S rC   rC   )rb   rl   rd   r   s      r>   re   zFCompliantSelectorNamespace.datetime.<locals>.names.<locals>.<listcomp>   s*    NNNXT2''"++NDNNNr@   rm   r   s    r>   rn   z2CompliantSelectorNamespace.datetime.<locals>.names   s+    NNNN):):2)>)>NNNNr@   ro   rp   rq   )r   r   r   r6   ru   rF   rs   )rE   r   r   r   r   rh   rn   r   s   `      @r>   datetimez#CompliantSelectorNamespace.datetime   s    
 "@	9!U!U
J1='!!	
 
 
	U 	U 	U 	U 	U 	U 	U	O 	O 	O 	O 	O 	O 	O ~,,VUD,IIIr@   N)r7   r#   r8   r   )r8   rA   )rG   r.   r8   rH   )rG   r.   r8   rM   )rG   r.   r8   rP   )rG   r.   r8   rS   )rE   rX   rY   rZ   r8   r[   )ru   rv   r8   r[   )r~   r   r8   r[   r8   r[   )r   r   r   r   r8   r[   )__name__
__module____qualname____annotations__classmethodr?   propertyrF   rK   rO   rR   rW   rt   r}   r   r   r   r   r   r   r   rC   r@   r>   r'   r'   C   s        ####%%%%   [ NNN XNJJJJMMMM4 4 4 4; ; ; ;J J J J	J 	J 	J 	JJ J J J$J J J J@ @ @ @; ; ; ;< < < <U U U UJ J J J J Jr@   r'   c                  &    e Zd ZddZddZdd	Zd
S )r(   rG   r/   r8   rM   c             #  Z   K   |                      |          D ]}|j        |j        fV  d S r:   )rK   rl   rY   rE   rG   rc   s      r>   rO   z#EagerSelectorNamespace._iter_schema   sE      %%b)) 	& 	&C(CI%%%%%	& 	&r@   Iterator[SeriesT]c             #  >   K   |                                 E d {V  d S r:   )iter_columnsrJ   s     r>   rK   z$EagerSelectorNamespace._iter_columns   s.      ??$$$$$$$$$$$r@   Iterator[tuple[SeriesT, DType]]c             #  P   K   |                      |          D ]}||j        fV  d S r:   )rK   rY   r   s      r>   rR   z+EagerSelectorNamespace._iter_columns_dtypes   sB      %%b)) 	! 	!Csy.    	! 	!r@   N)rG   r/   r8   rM   )rG   r/   r8   r   )rG   r/   r8   r   r   r   r   rO   rK   rR   rC   r@   r>   r(   r(      sP        & & & &% % % %! ! ! ! ! !r@   r(   c                  &    e Zd ZddZddZdd	Zd
S )r)   rG   r0   r8   rM   c              #  H   K   |j                                         E d {V  d S r:   )schemaitemsrJ   s     r>   rO   z"LazySelectorNamespace._iter_schema   s0      9??$$$$$$$$$$$r@   Iterator[ExprT]c              #  >   K   |                                 E d {V  d S r:   )rK   rJ   s     r>   rK   z#LazySelectorNamespace._iter_columns   s0      ##%%%%%%%%%%%r@   Iterator[tuple[ExprT, DType]]c             #     K   t          |                     |          |j                                                  E d {V  d S r:   )rU   rK   r   valuesrJ   s     r>   rR   z*LazySelectorNamespace._iter_columns_dtypes   sJ      t))"--ry/?/?/A/ABBBBBBBBBBBr@   N)rG   r0   r8   rM   )rG   r0   r8   r   )rG   r0   r8   r   r   rC   r@   r>   r)   r)      sV        % % % %& & & &C C C C C Cr@   r)   c                  P   e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ed.d            Zed/d            Zd0dZd1d Z	e
d2d!            Ze
d3d"            Zd4d$Ze
d2d%            Ze
d3d&            Zd4d'Ze
d2d(            Ze
d3d)            Zd4d*Zd5d,Zd-S )6r&   !EvalSeries[FrameT, SeriesOrExprT]_callNone_window_functionr   _function_nameint_depthr!   r3   r4   r5   r"   r6   r    _scalar_kwargscallevaluate_output_namesEvalNames[FrameT]r7   r#   r8   r   c                   |                      |           }||_        d |_        d|_        d|_        ||_        d |_        |j        |_        |j        |_        |j	        |_	        i |_
        |S )Nr   selector)r;   r   r   r   r   _evaluate_output_names_alias_output_namesr3   r5   r6   r   )r<   r   r   r7   r=   s        r>   rs   z CompliantSelector.from_callables   sp     kk#	#
'%:""&%5&7'
r@   rX   c                4    |                                  j        S r:   )__narwhals_namespace__	selectorsrD   s    r>   r   zCompliantSelector.selectors   s    **,,66r@   $CompliantExpr[FrameT, SeriesOrExprT]c                    d S r:   rC   rD   s    r>   _to_exprzCompliantSelector._to_expr   rL   r@   other+Self | CompliantExpr[FrameT, SeriesOrExprT]0TypeIs[CompliantSelector[FrameT, SeriesOrExprT]]c                <    t          |t          |                     S r:   )ra   typerE   r   s     r>   _is_selectorzCompliantSelector._is_selector   s     %d,,,r@   c                    d S r:   rC   r   s     r>   __sub__zCompliantSelector.__sub__       ,/Cr@   c                    d S r:   rC   r   s     r>   r   zCompliantSelector.__sub__   	     03sr@   %SelectorOrExpr[FrameT, SeriesOrExprT]c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z
  S )NrG   r.   r8   r]   c                x    t          |           \  }fdt           |           |          D             S )Nc                "    g | ]\  }}|v	|S rC   rC   rb   xrl   	rhs_namess      r>   re   z=CompliantSelector.__sub__.<locals>.series.<locals>.<listcomp>  s.       !!TYAVAVAAVAVAVr@   _eval_lhs_rhsrU   rG   	lhs_namesr   r   rE   s     @r>   rh   z)CompliantSelector.__sub__.<locals>.series	  sW    '4Ru'E'E$	9   %(b9%=%=   r@   ri   c                J    t          |           \  }fd|D             S )Nc                    g | ]}|v|	S rC   rC   rb   r   r   s     r>   re   z<CompliantSelector.__sub__.<locals>.names.<locals>.<listcomp>  s#    CCCa0B0B0B0B0Br@   r   r   s     @r>   rn   z(CompliantSelector.__sub__.<locals>.names  s4    '4Ru'E'E$	9CCCC9CCCCr@   ro   rp   rq   r   r   rF   rs   r   rE   r   rh   rn   s   ``  r>   r   zCompliantSelector.__sub__  s     U## 	X      D D D D D D D >+::65RV:WWW}}&&r@   c                    d S r:   rC   r   s     r>   __or__zCompliantSelector.__or__  s    +.3r@   c                    d S r:   rC   r   s     r>   r   zCompliantSelector.__or__  r   r@   c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z  S )NrG   r.   r8   r]   c                    t          |           \  }g fdt           |           |          D              |           S )Nc              3  *   K   | ]\  }}|v	|V  d S r:   rC   r   s      r>   	<genexpr>z;CompliantSelector.__or__.<locals>.series.<locals>.<genexpr>$  s1      YYGAt4yCXCXaCXCXCXCXYYr@   r   r   s     @r>   rh   z(CompliantSelector.__or__.<locals>.series!  sb    '4Ru'E'E$	9YYYYs4488Y'?'?YYYU2YY r@   ri   c                R    t          |           \  }g fd|D             S )Nc              3  $   K   | ]
}|v|V  d S r:   rC   r   s     r>   r  z:CompliantSelector.__or__.<locals>.names.<locals>.<genexpr>*  s-      EE!92D2D!2D2D2D2DEEr@   r   r   s     @r>   rn   z'CompliantSelector.__or__.<locals>.names(  s?    '4Ru'E'E$	9REEEEYEEER	RRr@   ro   rp   rq   r   r   s   ``  r>   r   zCompliantSelector.__or__  s     U## 	X      S S S S S S S >+::65RV:WWW}}&&r@   c                    d S r:   rC   r   s     r>   __and__zCompliantSelector.__and__/  r   r@   c                    d S r:   rC   r   s     r>   r	  zCompliantSelector.__and__1  r   r@   c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z  S )NrG   r.   r8   r]   c                x    t          |           \  }fdt           |           |          D             S )Nc                "    g | ]\  }}|v 	|S rC   rC   r   s      r>   re   z=CompliantSelector.__and__.<locals>.series.<locals>.<listcomp><  s'    WWWgaTYEVEVEVEVEVr@   r   r   s     @r>   rh   z)CompliantSelector.__and__.<locals>.series:  sF    '4Ru'E'E$	9WWWWTT"XXy)A)AWWWWr@   ri   c                J    t          |           \  }fd|D             S )Nc                    g | ]}|v |	S rC   rC   r   s     r>   re   z<CompliantSelector.__and__.<locals>.names.<locals>.<listcomp>@  s    ???aYr@   r   r   s     @r>   rn   z(CompliantSelector.__and__.<locals>.names>  s4    '4Ru'E'E$	9????9????r@   ro   rp   rq   r   r   s   ``  r>   r	  zCompliantSelector.__and__5  s     U## 
	XX X X X X X X@ @ @ @ @ @ @ >+::65RV:WWW}}&&r@   r[   c                :    | j                                         | z
  S r:   )r   r   rD   s    r>   
__invert__zCompliantSelector.__invert__E  s    ~!!##d**r@   N)r   r   r   r   r7   r#   r8   r   )r8   rX   )r8   r   )r   r   r8   r   )r   r   r8   r   )r   r   r8   r   )r   r   r8   r   r   )r   r   r   r   r   rs   r   r   r   r   r   r   r   r	  r  rC   r@   r>   r&   r&      s         -,,,KKK####%%%%       [( 7 7 7 X7 DCCC- - - -
 /// X/3 3 3 X3' ' ' '$ ... X.3 3 3 X3' ' ' '& /// X/3 3 3 X3' ' ' ' + + + + + +r@   r&   rG   lhsr   rhsr8   #tuple[Sequence[str], Sequence[str]]c                V    |                     |           |                     |           fS r:   )r   )rG   r  r  s      r>   r   r   I  s+     %%b))3+E+Eb+I+IIIr@   )rG   r   r  r   r  r   r8   r  )>__doc__
__future__r   r   	functoolsr   typingr   r   r   r   r	   r
   r   r   narwhals._compliant.exprr   narwhals._typing_compatr   narwhals._utilsr   r   r   r   r   r   typing_extensionsr   r   r   r   narwhals._compliant.typingr   r   r   r   r   r   r   r   r    r!   r"   r#   narwhals.dtypesr$   narwhals.typingr%   __all__r*   r,   r-   r.   r/   r0   r1   r   r'   r(   r)   r&   r   rC   r@   r>   <module>r"     s   C C C " " " " " " 				      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 3 2 2 2 2 2 . . . . . .             )!!!!!!9999999999333333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 FEEEEEEEEE%%%%%%((((((   /OPPP
')#7
8
8
8|,,,	!4	5	5	5W\)@AAA
W\)@AAA
U     
pJ pJ pJ pJ pJ&-*?!@ pJ pJ pJf! ! ! ! !z723Xj'>Q5R! ! !
C 
C 
C 
C 
Cz5018J<M3N
C 
C 
Ct+ t+ t+ t+ t+&-'(*V]5J*Kt+ t+ t+nJ J J J J Jr@   