o
    Lh                  	   @  s  U d dl mZ d dlmZ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mZmZmZ erUd 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 d d	lmZ g d
ZededZ ededZ!ededZ"ededZ#eZ$de%d< 	 dZ&de%d< 	 G dd dee#e"e f Z'ede'eeef ddZ(G dd de	e#e"f ee#e"e e(f Z)G dd de'eeef eeeeef Z*dS )    )annotations)TYPE_CHECKINGAnyProtocolTypeVarcast)CompliantExpr)CompliantExprAnyCompliantFrameAnyCompliantSeriesOrNativeExprAnyEagerDataFrameT
EagerExprTEagerSeriesTLazyExprAnyNativeSeriesT)Sequence)Self	TypeAlias)
EvalSeries)ImplementationVersion_LimitedContext)NonNestedLiteral)CompliantThenCompliantWhen	EagerWhenExprT)bound	LazyExprTSeriesTFrameTr   Scalarz+SeriesT | ExprT | NonNestedLiteral | ScalarIntoExprc                   @  sf   e Zd ZU ded< ded< ded< ded< d	ed
< edddZd ddZd!ddZed"ddZ	dS )#r   r   
_conditionIntoExpr[SeriesT, ExprT]_then_valuezIntoExpr[SeriesT, ExprT] | None_otherwise_valuer   _implementationr   _versionreturn1type[CompliantThen[FrameT, SeriesT, ExprT, Self]]c                 C     d S N )selfr-   r-   ^/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/narwhals/_compliant/when_then.py_then0   s   zCompliantWhen._thencompliant_framer    Sequence[SeriesT]c                C  r+   r,   r-   )r.   r1   r-   r-   r/   __call__2   s    zCompliantWhen.__call__value+CompliantThen[FrameT, SeriesT, ExprT, Self]c                C  s   | j | |S r,   )r0   	from_when)r.   r4   r-   r-   r/   then3   s   zCompliantWhen.then	conditioncontextr   r   c               C  s0   |  | }||_d |_d |_|j|_|j|_|S r,   )__new__r#   r%   r&   r'   r(   )clsr8   r9   objr-   r-   r/   	from_expr8   s   
zCompliantWhen.from_exprN)r)   r*   )r1   r    r)   r2   )r4   r$   r)   r5   )r8   r   r9   r   r)   r   )
__name__
__module____qualname____annotations__propertyr0   r3   r7   classmethodr=   r-   r-   r-   r/   r   )   s   
 

r   WhenT_contraT)r   contravariantc                   @  sF   e Zd ZU ded< ded< ded< ded< edddZdddZdS )r   zEvalSeries[FrameT, SeriesT]_callz%CompliantWhen[FrameT, SeriesT, ExprT]_when_valuer   r'   r   r(   whenrD   r7   r$   r)   r   c                C  sP   ||_ | | }||_||_t|ddd |_t|dd |_|j|_|j|_|S )N_evaluate_output_namesc                 S  s   dgS )Nliteralr-   )_dfr-   r-   r/   <lambda>W   s    z)CompliantThen.from_when.<locals>.<lambda>_alias_output_names)	r%   r:   rF   rG   getattrrI   rM   r'   r(   )r;   rH   r7   r<   r-   r-   r/   r6   P   s   

zCompliantThen.from_when	otherwiser   c                C  s   || j _td| S )Nr   )rG   r&   r   )r.   rO   r-   r-   r/   rO   ^   s   
zCompliantThen.otherwiseN)rH   rD   r7   r$   r)   r   )rO   r$   r)   r   )r>   r?   r@   rA   rC   r6   rO   r-   r-   r-   r/   r   H   s   
 r   c                   @  s    e Zd ZdddZdddZdS )r   rH   r   r7   rO   )NativeSeriesT | NonNestedLiteral | Scalarr)   c                C  r+   r,   r-   )r.   rH   r7   rO   r-   r-   r/   _if_then_elseg   s   zEagerWhen._if_then_elsedfr   Sequence[EagerSeriesT]c                C  s   | j j}|  |d }|j}|| jr| |d }n|d| j}d|_|| jrG| |d }||||\}}}| |j	|j	|j	}n|||\}}| |j	|j	| j}|
|gS )Nr   rJ   T)r#   _is_expr_align_full_broadcastr%   alias_from_scalar
_broadcastr&   rQ   native_with_native)r.   rR   is_exprrH   alignr7   rO   resultr-   r-   r/   r3   o   s   

zEagerWhen.__call__N)rH   r   r7   r   rO   rP   r)   r   )rR   r   r)   rS   )r>   r?   r@   rQ   r3   r-   r-   r-   r/   r   c   s    
r   N)+
__future__r   typingr   r   r   r   r   narwhals._compliant.exprr   narwhals._compliant.typingr	   r
   r   r   r   r   r   r   collections.abcr   typing_extensionsr   r   r   narwhals._utilsr   r   r   narwhals.typingr   __all__r   r   r   r    r!   rA   r"   r   rD   r   r   r-   r-   r-   r/   <module>   s<    (

