o
    $&]i~.                     @  s  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rd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dZ0e	dddZ1e	dddZ2e	dddZ3e	dddZ4e	dddZ5dZ6de7d < G d!d" d"ee3e0f Z8G d#d$ d$e8e4e1f ee4e1f Z9G d%d& d&e8e5e2f ee5e2f Z:G d'd( d(ee3e0f ee3e0f Z;d1d/d0Z<dS )2z=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                   @  s   e Zd ZU ded< ded< ed<ddZed=ddZd>ddZd?ddZ	d@ddZ
dAddZdBd!d"ZdCd%d&ZdDd)d*ZdEd+d,ZdEd-d.ZdEd/d0ZdEd1d2ZdEd3d4ZdFd9d:Zd;S )Gr%   r   _implementationr    _versionreturn.type[CompliantSelector[FrameT, SeriesOrExprT]]c                 C     d S N selfr6   r6   [/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/narwhals/_compliant/selectors.py	_selector?      z$CompliantSelectorNamespace._selectorcontextr!   r   c                C  s   |  | }|j|_|j|_|S r5   )__new__r0   r1   )clsr<   objr6   r6   r9   from_namespaceA   s   
z)CompliantSelectorNamespace.from_namespacedfr,   Iterator[SeriesOrExprT]c                C  r4   r5   r6   r8   rA   r6   r6   r9   _iter_columnsH       z(CompliantSelectorNamespace._iter_columnsIterator[tuple[str, DType]]c                C  r4   r5   r6   rC   r6   r6   r9   _iter_schemaI   rE   z'CompliantSelectorNamespace._iter_schema%Iterator[tuple[SeriesOrExprT, DType]]c                C  r4   r5   r6   rC   r6   r6   r9   _iter_columns_dtypesJ   s   z/CompliantSelectorNamespace._iter_columns_dtypes#Iterator[tuple[SeriesOrExprT, str]]c                c  s    t | ||jE d H  d S r5   )r   rD   columnsrC   r6   r6   r9   _iter_columns_namesM   s   z.CompliantSelectorNamespace._iter_columns_namesr8   1CompliantSelectorNamespace[FrameT, SeriesOrExprT]dtypetype[DType](CompliantSelector[FrameT, SeriesOrExprT]c                  2   d fdd}d fdd	}j j||d
S )NrA   r,   r2   Sequence[SeriesOrExprT]c                       fdd | D S )Nc                      g | ]\}}t | r|qS r6   
isinstance.0sertprN   r6   r9   
<listcomp>T   s
    zHCompliantSelectorNamespace._is_dtype.<locals>.series.<locals>.<listcomp>rI   rA   rN   r8   r6   r9   seriesS   s   
z4CompliantSelectorNamespace._is_dtype.<locals>.seriesSequence[str]c                   rS   )Nc                   rT   r6   rU   rX   namerZ   r[   r6   r9   r\   Y       zGCompliantSelectorNamespace._is_dtype.<locals>.names.<locals>.<listcomp>rG   r^   r_   r6   r9   namesX      z3CompliantSelectorNamespace._is_dtype.<locals>.namesr<   rA   r,   r2   rR   rA   r,   r2   ra   r:   from_callables)r8   rN   r`   rf   r6   r_   r9   	_is_dtypeP   s   z$CompliantSelectorNamespace._is_dtypedtypesCollection[DType | type[DType]]c                   rQ   )NrA   r,   r2   rR   c                   rS   )Nc                      g | ]
\}}| v r|qS r6   r6   rW   rn   r6   r9   r\   b       zGCompliantSelectorNamespace.by_dtype.<locals>.series.<locals>.<listcomp>r]   r^   rn   r8   r6   r9   r`   a   rg   z3CompliantSelectorNamespace.by_dtype.<locals>.seriesra   c                   rS   )Nc                   rp   r6   r6   rb   rq   r6   r9   r\   e   rr   zFCompliantSelectorNamespace.by_dtype.<locals>.names.<locals>.<listcomp>re   r^   rs   r6   r9   rf   d   rg   z2CompliantSelectorNamespace.by_dtype.<locals>.namesrh   ri   rj   rk   )r8   rn   r`   rf   r6   rs   r9   by_dtype^   s   z#CompliantSelectorNamespace.by_dtypepatternstrc                   s:   t | d fdd}d fdd	}jj||d
S )NrA   r,   r2   rR   c                   sJ   t  rj sj s fdd jD S fdd D S )Nc                   s    g | ]} |r |qS r6   )search
get_columnrX   col)rA   pr6   r9   r\   r   s     zFCompliantSelectorNamespace.matches.<locals>.series.<locals>.<listcomp>c                   s   g | ]\}}  |r|qS r6   rw   )rX   rY   rc   r{   r6   r9   r\   t   rd   )r   r0   	is_duckdbis_ibisrK   rL   r^   r{   r8   r^   r9   r`   l   s   z2CompliantSelectorNamespace.matches.<locals>.seriesra   c                   s    fdd| j D S )Nc                   s   g | ]	}  |r|qS r6   r|   ry   r}   r6   r9   r\   w   s    zECompliantSelectorNamespace.matches.<locals>.names.<locals>.<listcomp>)rK   r^   r}   r6   r9   rf   v      z1CompliantSelectorNamespace.matches.<locals>.namesrh   ri   rj   )recompiler:   rl   )r8   ru   r`   rf   r6   r   r9   matchesi   s   

z"CompliantSelectorNamespace.matchesc                   s.   d fdd}d fdd	} j j|| d
S )NrA   r,   r2   rR   c                      dd   | D S )Nc                 S     g | ]
\}}|  r|qS r6   
is_numericrW   r6   r6   r9   r\   }   rr   zFCompliantSelectorNamespace.numeric.<locals>.series.<locals>.<listcomp>r]   r^   r7   r6   r9   r`   |   r   z2CompliantSelectorNamespace.numeric.<locals>.seriesra   c                   r   )Nc                 S  r   r6   r   rb   r6   r6   r9   r\      rr   zECompliantSelectorNamespace.numeric.<locals>.names.<locals>.<listcomp>re   r^   r7   r6   r9   rf      r   z1CompliantSelectorNamespace.numeric.<locals>.namesrh   ri   rj   rk   )r8   r`   rf   r6   r7   r9   numeric{   s   z"CompliantSelectorNamespace.numericc                 C     |  | jjjS r5   )rm   r1   rn   Categoricalr7   r6   r6   r9   categorical      z&CompliantSelectorNamespace.categoricalc                 C  r   r5   )rm   r1   rn   Stringr7   r6   r6   r9   string   r   z!CompliantSelectorNamespace.stringc                 C  r   r5   )rm   r1   rn   Booleanr7   r6   r6   r9   boolean   r   z"CompliantSelectorNamespace.booleanc                   s    d fdd} j j|t dS )	NrA   r,   r2   rR   c                   s   t  | S r5   )listrD   r^   r7   r6   r9   r`         z.CompliantSelectorNamespace.all.<locals>.seriesrh   ri   )r:   rl   r   )r8   r`   r6   r7   r9   all   s   zCompliantSelectorNamespace.all	time_unit$TimeUnit | Iterable[TimeUnit] | None	time_zone7str | timezone | Iterable[str | timezone | None] | Nonec                   sT   t ||\}}ttjj||d d fdd}d fd	d
}jj||dS )N)rn   
time_units
time_zonesrA   r,   r2   rR   c                   rS   )Nc                      g | ]
\}} |r|qS r6   r6   rW   r   r6   r9   r\      rr   zGCompliantSelectorNamespace.datetime.<locals>.series.<locals>.<listcomp>r]   r^   r   r8   r6   r9   r`      rg   z3CompliantSelectorNamespace.datetime.<locals>.seriesra   c                   rS   )Nc                   r   r6   r6   rb   r   r6   r9   r\      rr   zFCompliantSelectorNamespace.datetime.<locals>.names.<locals>.<listcomp>re   r^   r   r6   r9   rf      rg   z2CompliantSelectorNamespace.datetime.<locals>.namesrh   ri   rj   )r	   r   r
   r1   rn   r:   rl   )r8   r   r   r   r   r`   rf   r6   r   r9   datetime   s   z#CompliantSelectorNamespace.datetimeN)r2   r3   )r<   r!   r2   r   )rA   r,   r2   rB   )rA   r,   r2   rF   )rA   r,   r2   rH   )rA   r,   r2   rJ   )r8   rM   rN   rO   r2   rP   )rn   ro   r2   rP   )ru   rv   r2   rP   r2   rP   )r   r   r   r   r2   rP   )__name__
__module____qualname____annotations__propertyr:   classmethodr@   rD   rG   rI   rL   rm   rt   r   r   r   r   r   r   r   r6   r6   r6   r9   r%   :   s(   
 








	


r%   c                   @  *   e Zd ZdddZddd	ZdddZdS )r&   rA   r-   r2   rF   c                c  s$    |  |D ]	}|j|jfV  qd S r5   )rD   rc   rN   r8   rA   rY   r6   r6   r9   rG      s   z#EagerSelectorNamespace._iter_schemaIterator[SeriesT]c                c      |  E d H  d S r5   )iter_columnsrC   r6   r6   r9   rD         z$EagerSelectorNamespace._iter_columnsIterator[tuple[SeriesT, DType]]c                c  s"    |  |D ]}||jfV  qd S r5   )rD   rN   r   r6   r6   r9   rI      s   z+EagerSelectorNamespace._iter_columns_dtypesN)rA   r-   r2   rF   )rA   r-   r2   r   )rA   r-   r2   r   r   r   r   rG   rD   rI   r6   r6   r6   r9   r&      s    

r&   c                   @  r   )r'   rA   r.   r2   rF   c                 c  s    |j  E d H  d S r5   )schemaitemsrC   r6   r6   r9   rG      s   z"LazySelectorNamespace._iter_schemaIterator[ExprT]c                 c  r   r5   )rD   rC   r6   r6   r9   rD      r   z#LazySelectorNamespace._iter_columnsIterator[tuple[ExprT, DType]]c                c  s"    t | ||j E d H  d S r5   )r   rD   r   valuesrC   r6   r6   r9   rI      s    z*LazySelectorNamespace._iter_columns_dtypesN)rA   r.   r2   rF   )rA   r.   r2   r   )rA   r.   r2   r   r   r6   r6   r6   r9   r'      s    

r'   c                   @  s   e Zd ZU ded< ded< ded< ded< ed.ddZed/ddZd0ddZd1ddZ	e
d2ddZe
d3ddZd4d!dZe
d2d"d#Ze
d3d$d#Zd4d%d#Ze
d2d&d'Ze
d3d(d'Zd4d)d'Zd5d+d,Zd-S )6r$   !EvalSeries[FrameT, SeriesOrExprT]_callrv   _function_namer   r0   r    r1   callevaluate_output_namesEvalNames[FrameT]r<   r!   r2   r   c                C  s0   |  | }||_||_d |_|j|_|j|_|S r5   )r=   r   _evaluate_output_names_alias_output_namesr0   r1   )r>   r   r   r<   r?   r6   r6   r9   rl      s   
z CompliantSelector.from_callablesrM   c                 C  s
   |   jS r5   )__narwhals_namespace__	selectorsr7   r6   r6   r9   r      s   
zCompliantSelector.selectors$CompliantExpr[FrameT, SeriesOrExprT]c                 C  r4   r5   r6   r7   r6   r6   r9   _to_expr   rE   zCompliantSelector._to_exprother+Self | CompliantExpr[FrameT, SeriesOrExprT]0TypeIs[CompliantSelector[FrameT, SeriesOrExprT]]c                 C  s   t |t| S r5   )rV   typer8   r   r6   r6   r9   _is_selector   s   zCompliantSelector._is_selectorc                 C  r4   r5   r6   r   r6   r6   r9   __sub__   r;   zCompliantSelector.__sub__c                 C  r4   r5   r6   r   r6   r6   r9   r         %SelectorOrExpr[FrameT, SeriesOrExprT]c                   sJ     rd fdd}d fdd	}jjj||d
S    S )NrA   r,   r2   rR   c                   ,   t | \}  fddt| |D S )Nc                   s   g | ]
\}}| vr|qS r6   r6   rX   xrc   	rhs_namesr6   r9   r\      s
    z=CompliantSelector.__sub__.<locals>.series.<locals>.<listcomp>_eval_lhs_rhsr   rA   	lhs_namesr   r8   r   r9   r`      s   
z)CompliantSelector.__sub__.<locals>.seriesra   c                   "   t | \}  fdd|D S )Nc                   s   g | ]}| vr|qS r6   r6   rX   r   r   r6   r9   r\          z<CompliantSelector.__sub__.<locals>.names.<locals>.<listcomp>r   r   r   r   r9   rf         z(CompliantSelector.__sub__.<locals>.namesrh   ri   rj   r   r   r:   rl   r   r8   r   r`   rf   r6   r   r9   r      s
   
c                 C  r4   r5   r6   r   r6   r6   r9   __or__  r;   zCompliantSelector.__or__c                 C  r4   r5   r6   r   r6   r6   r9   r     r   c                   sJ     rd fdd}d fdd	}jjj||d
S   B S )NrA   r,   r2   rR   c                   s8   t | \} g  fddt| |D | S )Nc                 3  s     | ]\}}| vr|V  qd S r5   r6   r   r   r6   r9   	<genexpr>  s    z;CompliantSelector.__or__.<locals>.series.<locals>.<genexpr>r   r   r   r   r9   r`     s   
z(CompliantSelector.__or__.<locals>.seriesra   c                   s*   t | \} g  fdd|D  S )Nc                 3  s    | ]	}| vr|V  qd S r5   r6   r   r   r6   r9   r     s    z:CompliantSelector.__or__.<locals>.names.<locals>.<genexpr>r   r   r   r   r9   rf     s   z'CompliantSelector.__or__.<locals>.namesrh   ri   rj   r   r   r6   r   r9   r     s
   
c                 C  r4   r5   r6   r   r6   r6   r9   __and__  r;   zCompliantSelector.__and__c                 C  r4   r5   r6   r   r6   r6   r9   r   !  r   c                   sJ     rd fdd}d fdd	}jjj||d
S   @ S )NrA   r,   r2   rR   c                   r   )Nc                   rp   r6   r6   r   r   r6   r9   r\   ,  s    z=CompliantSelector.__and__.<locals>.series.<locals>.<listcomp>r   r   r   r   r9   r`   *  s   
z)CompliantSelector.__and__.<locals>.seriesra   c                   r   )Nc                   s   g | ]}| v r|qS r6   r6   r   r   r6   r9   r\   2  r   z<CompliantSelector.__and__.<locals>.names.<locals>.<listcomp>r   r   r   r   r9   rf   0  r   z(CompliantSelector.__and__.<locals>.namesrh   ri   rj   r   r   r6   r   r9   r   %  s
   
rP   c                 C  s   | j  |  S r5   )r   r   r7   r6   r6   r9   
__invert__7  r   zCompliantSelector.__invert__N)r   r   r   r   r<   r!   r2   r   )r2   rM   )r2   r   )r   r   r2   r   )r   r   r2   r   )r   r   r2   r   )r   r   r2   r   r   )r   r   r   r   r   rl   r   r   r   r   r   r   r   r   r   r6   r6   r6   r9   r$      s6   
 




r$   rA   lhsr   rhsr2   #tuple[Sequence[str], Sequence[str]]c                 C  s   | | | | fS r5   )r   )rA   r   r   r6   r6   r9   r   ;  s   r   )rA   r   r   r   r   r   r2   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.   r/   r   r%   r&   r'   r$   r   r6   r6   r6   r9   <module>   sH    (


o

v