
    hh0.                       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mZ erLddlmZmZmZ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!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          Z0 e	dd          Z1 e	dd          Z2 e	dd          Z3 e	dd          Z4 e	dd          Z5dZ6de7d <    G d! d"ee3e0f                   Z8 G d# d$e8e4e1f         ee4e1f                   Z9 G d% d&e8e5e2f         ee5e2f                   Z: G d' d(ee3e0f         ee3e0f                   Z;d0d/Z<dS )1z=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
zip_strict)
CollectionIterableIteratorSequence)timezone)Self	TypeAlias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d0dZ	d1dZ
d2dZd3dZd4dZd5d!Zd6d"Zd6d#Zd6d$Zd6d%Zd6d&Zd7d+Zd,S )8r&   r    _implementationr!   _versionreturn.type[CompliantSelector[FrameT, SeriesOrExprT]]c                    d S N selfs    T/var/www/histauto/venv/lib/python3.11/site-packages/narwhals/_compliant/selectors.py	_selectorz$CompliantSelectorNamespace._selector?   s    KN3    contextr"   r   c               `    |                      |           }|j        |_        |j        |_        |S r7   )__new__r2   r3   )clsr>   objs      r;   from_namespacez)CompliantSelectorNamespace.from_namespaceA   s-    kk#%5'
r=   dfr-   Iterator[SeriesOrExprT]c                   d S r7   r8   r:   rD   s     r;   _iter_columnsz(CompliantSelectorNamespace._iter_columnsH         r=   Iterator[tuple[str, DType]]c                   d S r7   r8   rG   s     r;   _iter_schemaz'CompliantSelectorNamespace._iter_schemaI   rI   r=   %Iterator[tuple[SeriesOrExprT, DType]]c                   d S r7   r8   rG   s     r;   _iter_columns_dtypesz/CompliantSelectorNamespace._iter_columns_dtypesJ   s    03r=   #Iterator[tuple[SeriesOrExprT, str]]c             #  f   K   t          |                     |          |j                  E d {V  d S r7   )r   rH   columnsrG   s     r;   _iter_columns_namesz.CompliantSelectorNamespace._iter_columns_namesM   s>      d0044bjAAAAAAAAAAAr=   r:   1CompliantSelectorNamespace[FrameT, SeriesOrExprT]dtypetype[DType](CompliantSelector[FrameT, SeriesOrExprT]c               \     d	 fd}d
 fd} j                             ||           S )NrD   r-   r4   Sequence[SeriesOrExprT]c                F    fd                     |           D             S )Nc                :    g | ]\  }}t          |          |S r8   
isinstance).0sertprU   s      r;   
<listcomp>zHCompliantSelectorNamespace._is_dtype.<locals>.series.<locals>.<listcomp>T   s=       RJrSXDYDY  r=   rO   rD   rU   r:   s    r;   seriesz4CompliantSelectorNamespace._is_dtype.<locals>.seriesS   s<       #'#<#<R#@#@   r=   Sequence[str]c                F    fd                     |           D             S )Nc                :    g | ]\  }}t          |          |S r8   r\   )r^   namer`   rU   s      r;   ra   zGCompliantSelectorNamespace._is_dtype.<locals>.names.<locals>.<listcomp>Y   s-    XXXXT2*RQVBWBWXDXXXr=   rL   rc   s    r;   namesz3CompliantSelectorNamespace._is_dtype.<locals>.namesX   s+    XXXX):):2)>)>XXXXr=   r>   rD   r-   r4   rY   rD   r-   r4   re   r<   from_callables)r:   rU   rd   rj   s   ``  r;   	_is_dtypez$CompliantSelectorNamespace._is_dtypeP   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 )NrD   r-   r4   rY   c                F    fd                     |           D             S )Nc                "    g | ]\  }}|v 	|S r8   r8   )r^   r_   r`   rq   s      r;   ra   zGCompliantSelectorNamespace.by_dtype.<locals>.series.<locals>.<listcomp>b   s"    UUUGCfCr=   rb   rD   rq   r:   s    r;   rd   z3CompliantSelectorNamespace.by_dtype.<locals>.seriesa   s+    UUUUt'@'@'D'DUUUUr=   re   c                F    fd                     |           D             S )Nc                "    g | ]\  }}|v 	|S r8   r8   )r^   rh   r`   rq   s      r;   ra   zFCompliantSelectorNamespace.by_dtype.<locals>.names.<locals>.<listcomp>e   s"    OOOXT2",,D,,,r=   ri   rv   s    r;   rj   z2CompliantSelectorNamespace.by_dtype.<locals>.namesd   s+    OOOO):):2)>)>OOOOr=   rk   rl   rm   rn   )r:   rq   rd   rj   s   ``  r;   by_dtypez#CompliantSelectorNamespace.by_dtype^   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 )NrD   r-   r4   rY   c                     t                     rFj                                        s-j                                        s fd j        D             S fd                               D             S )Nc                d    g | ],}                     |                              |          -S r8   )search
get_column)r^   colrD   ps     r;   ra   zFCompliantSelectorNamespace.matches.<locals>.series.<locals>.<listcomp>r   s4    RRRsAHHSMMRc**RRRr=   c                D    g | ]\  }}                     |          |S r8   r   )r^   r_   rh   r   s      r;   ra   zFCompliantSelectorNamespace.matches.<locals>.series.<locals>.<listcomp>t   s-    XXXICRVXCXXXr=   )r   r2   	is_duckdbis_ibisrR   rS   )rD   r   r:   s   `r;   rd   z2CompliantSelectorNamespace.matches.<locals>.seriesl   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=   re   c                *    fd| j         D             S )Nc                >    g | ]}                     |          |S r8   r   )r^   r   r   s     r;   ra   zECompliantSelectorNamespace.matches.<locals>.names.<locals>.<listcomp>w   s(    ???C#?C???r=   )rR   )rD   r   s    r;   rj   z1CompliantSelectorNamespace.matches.<locals>.namesv   s    ????2:????r=   rk   rl   rm   )recompiler<   ro   )r:   rz   rd   rj   r   s   `   @r;   matchesz"CompliantSelectorNamespace.matchesi   s    Jw	Y 	Y 	Y 	Y 	Y 	Y 	Y	@ 	@ 	@ 	@ 	@ 	@ ~,,VUD,IIIr=   c                V     d	 fd}d
 fd} j                             ||           S )NrD   r-   r4   rY   c                B    d                      |           D             S )Nc                @    g | ]\  }}|                                 |S r8   
is_numeric)r^   r_   r`   s      r;   ra   zFCompliantSelectorNamespace.numeric.<locals>.series.<locals>.<listcomp>}   s)    XXXGCXCXXXr=   rb   rD   r:   s    r;   rd   z2CompliantSelectorNamespace.numeric.<locals>.series|   s%    XXt'@'@'D'DXXXXr=   re   c                B    d                      |           D             S )Nc                @    g | ]\  }}|                                 |S r8   r   )r^   rh   r`   s      r;   ra   zECompliantSelectorNamespace.numeric.<locals>.names.<locals>.<listcomp>   s)    RRRXT2"--//RDRRRr=   ri   r   s    r;   rj   z1CompliantSelectorNamespace.numeric.<locals>.names   s%    RR):):2)>)>RRRRr=   rk   rl   rm   rn   )r:   rd   rj   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 r7   )rp   r3   rq   Categoricalr9   s    r;   categoricalz&CompliantSelectorNamespace.categorical   s    ~~dm2>???r=   c                J    |                      | j        j        j                  S r7   )rp   r3   rq   Stringr9   s    r;   stringz!CompliantSelectorNamespace.string   s    ~~dm29:::r=   c                J    |                      | j        j        j                  S r7   )rp   r3   rq   Booleanr9   s    r;   booleanz"CompliantSelectorNamespace.boolean   s    ~~dm2:;;;r=   c                T     d fd} j                             |t                     S )NrD   r-   r4   rY   c                H    t                              |                     S r7   )listrH   r   s    r;   rd   z.CompliantSelectorNamespace.all.<locals>.series   s    **2..///r=   rk   rl   )r<   ro   r   )r:   rd   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)rq   
time_units
time_zonesrD   r-   r4   rY   c                F    fd                     |           D             S )Nc                0    g | ]\  }} |          |S r8   r8   )r^   r_   r`   r   s      r;   ra   zGCompliantSelectorNamespace.datetime.<locals>.series.<locals>.<listcomp>   s+    TTTGCPRTCTTTr=   rb   rD   r   r:   s    r;   rd   z3CompliantSelectorNamespace.datetime.<locals>.series   s+    TTTTt'@'@'D'DTTTTr=   re   c                F    fd                     |           D             S )Nc                0    g | ]\  }} |          |S r8   r8   )r^   rh   r`   r   s      r;   ra   zFCompliantSelectorNamespace.datetime.<locals>.names.<locals>.<listcomp>   s*    NNNXT2''"++NDNNNr=   ri   r   s    r;   rj   z2CompliantSelectorNamespace.datetime.<locals>.names   s+    NNNN):):2)>)>NNNNr=   rk   rl   rm   )r
   r   r   r3   rq   r<   ro   )r:   r   r   r   r   rd   rj   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)r4   r5   )r>   r"   r4   r   )rD   r-   r4   rE   )rD   r-   r4   rJ   )rD   r-   r4   rM   )rD   r-   r4   rP   )r:   rT   rU   rV   r4   rW   )rq   rr   r4   rW   )rz   r{   r4   rW   r4   rW   )r   r   r   r   r4   rW   )__name__
__module____qualname____annotations__propertyr<   classmethodrC   rH   rL   rO   rS   rp   ry   r   r   r   r   r   r   r   r8   r=   r;   r&   r&   :   s{        ####NNN XN   [ KJJJMMMM4 4 4 4B B B B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'   rD   r.   r4   rJ   c             #  Z   K   |                      |          D ]}|j        |j        fV  d S r7   )rH   rh   rU   r:   rD   r_   s      r;   rL   z#EagerSelectorNamespace._iter_schema   sE      %%b)) 	& 	&C(CI%%%%%	& 	&r=   Iterator[SeriesT]c             #  >   K   |                                 E d {V  d S r7   )iter_columnsrG   s     r;   rH   z$EagerSelectorNamespace._iter_columns   s.      ??$$$$$$$$$$$r=   Iterator[tuple[SeriesT, DType]]c             #  P   K   |                      |          D ]}||j        fV  d S r7   )rH   rU   r   s      r;   rO   z+EagerSelectorNamespace._iter_columns_dtypes   sB      %%b)) 	! 	!Csy.    	! 	!r=   N)rD   r.   r4   rJ   )rD   r.   r4   r   )rD   r.   r4   r   r   r   r   rL   rH   rO   r8   r=   r;   r'   r'      sP        & & & &% % % %! ! ! ! ! !r=   r'   c                  &    e Zd ZddZddZdd	Zd
S )r(   rD   r/   r4   rJ   c              #  H   K   |j                                         E d {V  d S r7   )schemaitemsrG   s     r;   rL   z"LazySelectorNamespace._iter_schema   s0      9??$$$$$$$$$$$r=   Iterator[ExprT]c              #  >   K   |                                 E d {V  d S r7   )rH   rG   s     r;   rH   z#LazySelectorNamespace._iter_columns   s0      ##%%%%%%%%%%%r=   Iterator[tuple[ExprT, DType]]c             #     K   t          |                     |          |j                                                  E d {V  d S r7   )r   rH   r   valuesrG   s     r;   rO   z*LazySelectorNamespace._iter_columns_dtypes   sJ      d0044bi6F6F6H6HIIIIIIIIIIIr=   N)rD   r/   r4   rJ   )rD   r/   r4   r   )rD   r/   r4   r   r   r8   r=   r;   r(   r(      sV        % % % %& & & &J J J J J J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d%S ).r%   !EvalSeries[FrameT, SeriesOrExprT]_callr{   _function_namer    r2   r!   r3   callevaluate_output_namesEvalNames[FrameT]r>   r"   r4   r   c                   |                      |           }||_        ||_        d |_        |j        |_        |j        |_        |S r7   )r@   r   _evaluate_output_names_alias_output_namesr2   r3   )rA   r   r   r>   rB   s        r;   ro   z CompliantSelector.from_callables   sF     kk#	%:""&%5'
r=   rT   c                4    |                                  j        S r7   )__narwhals_namespace__	selectorsr9   s    r;   r   zCompliantSelector.selectors   s    **,,66r=   $CompliantExpr[FrameT, SeriesOrExprT]c                    d S r7   r8   r9   s    r;   _to_exprzCompliantSelector._to_expr   rI   r=   other+Self | CompliantExpr[FrameT, SeriesOrExprT]0TypeIs[CompliantSelector[FrameT, SeriesOrExprT]]c                <    t          |t          |                     S r7   )r]   typer:   r   s     r;   _is_selectorzCompliantSelector._is_selector   s     %d,,,r=   c                    d S r7   r8   r   s     r;   __sub__zCompliantSelector.__sub__       ,/Cr=   c                    d S r7   r8   r   s     r;   r   zCompliantSelector.__sub__   	     03sr=   %SelectorOrExpr[FrameT, SeriesOrExprT]c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z
  S )NrD   r-   r4   rY   c                x    t          |           \  }fdt           |           |          D             S )Nc                "    g | ]\  }}|v	|S r8   r8   r^   xrh   	rhs_namess      r;   ra   z=CompliantSelector.__sub__.<locals>.series.<locals>.<listcomp>   s2       49,, ,,,r=   _eval_lhs_rhsr   rD   	lhs_namesr   r   r:   s     @r;   rd   z)CompliantSelector.__sub__.<locals>.series   sW    '4Ru'E'E$	9   #-dd2hh	#B#B   r=   re   c                J    t          |           \  }fd|D             S )Nc                    g | ]}|v|	S r8   r8   r^   r   r   s     r;   ra   z<CompliantSelector.__sub__.<locals>.names.<locals>.<listcomp>   s#    CCCa0B0B0B0B0Br=   r   r   s     @r;   rj   z(CompliantSelector.__sub__.<locals>.names   s4    '4Ru'E'E$	9CCCC9CCCCr=   rk   rl   rm   r   r   r<   ro   r   r:   r   rd   rj   s   ``  r;   r   zCompliantSelector.__sub__   s     U## 	X      D D D D D D D >+::65RV:WWW}}&&r=   c                    d S r7   r8   r   s     r;   __or__zCompliantSelector.__or__  s    +.3r=   c                    d S r7   r8   r   s     r;   r   zCompliantSelector.__or__  r   r=   c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z  S )NrD   r-   r4   rY   c                    t          |           \  }g fdt           |           |          D              |           S )Nc              3  *   K   | ]\  }}|v	|V  d S r7   r8   r   s      r;   	<genexpr>z;CompliantSelector.__or__.<locals>.series.<locals>.<genexpr>  s>        #Aty00 0000 r=   r   r   s     @r;   rd   z(CompliantSelector.__or__.<locals>.series  ss    '4Ru'E'E$	9   '1$$r((I'F'F   U2YY r=   re   c                R    t          |           \  }g fd|D             S )Nc              3  $   K   | ]
}|v|V  d S r7   r8   r   s     r;   r   z:CompliantSelector.__or__.<locals>.names.<locals>.<genexpr>  s-      EE!92D2D!2D2D2D2DEEr=   r   r   s     @r;   rj   z'CompliantSelector.__or__.<locals>.names  s?    '4Ru'E'E$	9REEEEYEEER	RRr=   rk   rl   rm   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 r7   r8   r   s     r;   __and__zCompliantSelector.__and__  r   r=   c                    d S r7   r8   r   s     r;   r   zCompliantSelector.__and__!  r   r=   c                                                     r0d	 fd}d
 fd} j        j                            ||           S                                  z  S )NrD   r-   r4   rY   c                x    t          |           \  }fdt           |           |          D             S )Nc                "    g | ]\  }}|v 	|S r8   r8   r   s      r;   ra   z=CompliantSelector.__and__.<locals>.series.<locals>.<listcomp>,  s/       !!TPYHYHYAHYHYHYr=   r   r   s     @r;   rd   z)CompliantSelector.__and__.<locals>.series*  sW    '4Ru'E'E$	9   %/R)%D%D   r=   re   c                J    t          |           \  }fd|D             S )Nc                    g | ]}|v |	S r8   r8   r   s     r;   ra   z<CompliantSelector.__and__.<locals>.names.<locals>.<listcomp>2  s    ???aYr=   r   r   s     @r;   rj   z(CompliantSelector.__and__.<locals>.names0  s4    '4Ru'E'E$	9????9????r=   rk   rl   rm   r   r   s   ``  r;   r   zCompliantSelector.__and__%  s     U## 	X      @ @ @ @ @ @ @ >+::65RV:WWW}}&&r=   rW   c                :    | j                                         | z
  S r7   )r   r   r9   s    r;   
__invert__zCompliantSelector.__invert__7  s    ~!!##d**r=   N)r   r   r   r   r>   r"   r4   r   )r4   rT   )r4   r   )r   r   r4   r   )r   r   r4   r   )r   r   r4   r   )r   r   r4   r   r   )r   r   r   r   r   ro   r   r   r   r   r   r   r   r   r  r8   r=   r;   r%   r%      s         -,,,####   [ 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%   rD   lhsr   rhsr4   #tuple[Sequence[str], Sequence[str]]c                V    |                     |           |                     |           fS r7   )r   )rD   r  r	  s      r;   r   r   ;  s+     %%b))3+E+Eb+I+IIIr=   )rD   r   r  r   r	  r   r4   r
  )=__doc__
__future__r   r   	functoolsr   typingr   r   r   r   narwhals._compliant.exprr	   narwhals._utilsr
   r   r   r   r   collections.abcr   r   r   r   r   r   typing_extensionsr   r   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/   r0   r   r&   r'   r(   r%   r   r8   r=   r;   <module>r     s   C C C " " " " " " 				       = = = = = = = = = = = = 2 2 2 2 2 2               )HHHHHHHHHHHH!!!!!!9999999999333333	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 IHHHHHHHHH%%%%%%((((((   /OPPP
')#7
8
8
8|,,,	!4	5	5	5W\)@AAA
W\)@AAA
U     
lJ lJ lJ lJ lJ&-*?!@ lJ lJ lJ^! ! ! ! !z723Xj'>Q5R! ! !
J 
J 
J 
J 
Jz5018J<M3N
J 
J 
Js+ s+ s+ s+ s+&-'((6=3H*Is+ s+ s+lJ J J J J Jr=   