
    h              	         % S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  \(       a  S SKJr  \(       d  \R6                  S:  a  S SKJr  OS SKJr  OS SKJr  / SQr\" SSSS9r \S   r!S \"S!'   \RF                  " S"5      r$S#\"S$'    " S% S&\\\4   5      r% " S' S(\%\\4   \\\4   5      r& " S) S*\%\\4   \\\\ 4   5      r' " S+ S,\'\\\(4   \&\\4   \\\4   5      r) " S- S.\%\\4   \\\\4   5      r*g)/    )annotationsN)TYPE_CHECKING)Any)Callable)ClassVar)Iterable)Iterator)Literal)Mapping)Sequence)TypeVar)CompliantDataFrameT_co)CompliantExprT_contra)CompliantFrameT_co)CompliantLazyFrameT_co)DepthTrackingExprAny)DepthTrackingExprT_contra)EagerExprT_contra)LazyExprT_contra)NativeExprT_co)	TypeAlias)   	   )Protocol)Generic)CompliantGroupByDepthTrackingGroupByEagerGroupByLazyGroupByNarwhalsAggregationNativeAggregationT_cozstr | Callable[..., Any]T)bound	covariant)
summeanmedianmaxminstdvarlenn_uniquecountr   r    z(\w+->)zre.Pattern[str]_RE_LEAF_NAMEc                  b    \ rS rSr% S\S'   S\S'   \SS j5       r        SS jrSS jrS	r	g
)r   ;   r   _compliant_frameSequence[str]_keysc                    U R                   $ N)r1   selfs    N/var/www/html/env/lib/python3.13/site-packages/narwhals/_compliant/group_by.py	compliantCompliantGroupBy.compliant?   s    $$$    c                  g r5    )r7   compliant_framekeysdrop_null_keyss       r8   __init__CompliantGroupBy.__init__C   s     r;   c                    g r5   r=   )r7   exprss     r8   aggCompliantGroupBy.aggL       r;   r=   N)returnr   )r>   r   r?   r2   r@   boolrH   None)rD   r   rH   r   )
__name__
__module____qualname____firstlineno____annotations__propertyr9   rA   rE   __static_attributes__r=   r;   r8   r   r   ;   sQ    % %+   
 Lr;   r   c                      \ rS rSrSS jrSrg)DataFrameGroupByO   c                    g r5   r=   r6   s    r8   __iter__DataFrameGroupBy.__iter__S   rG   r;   r=   N)rH   z,Iterator[tuple[Any, CompliantDataFrameT_co]])rK   rL   rM   rN   rV   rQ   r=   r;   r8   rS   rS   O   s     Lr;   rS   c                  t    \ rS rSr% SrS\S'    SS jr\SS j5       r\    SS j5       r	\SS j5       r
S	rg
)r   V   zf`CompliantGroupBy` variant, deals with `Eager` and other backends that utilize `CompliantExpr._depth`.z+ClassVar[Mapping[NarwhalsAggregation, Any]]_REMAP_AGGSc                    U HY  nU R                  U5      (       a  M  U R                  R                  R                  R	                  5       nSU< S3n[        U5      e   g )NzsNon-trivial complex aggregation found.

Hint: you were probably trying to apply a non-elementary aggregation with az table.
Please rewrite your query such that group-by aggregations are elementary. For example, instead of:

    df.group_by('a').agg(nw.col('b').round(2).mean())

use:

    df.with_columns(nw.col('b').round(2)).group_by('a').agg(nw.col('b').mean())

)
_is_simpler9   _implementationnamelower
ValueError)r7   rD   exprr^   msgs        r8   _ensure_all_simple'DepthTrackingGroupBy._ensure_all_simplec   sa    D??4((~~55::@@Bbh jj  !o% r;   c               l    UR                  5       =(       a    U R                  U5      U R                  ;   $ )zNReturn `True` is we can efficiently use `expr` in a native `group_by` context.)_is_elementary
_leaf_namerZ   clsra   s     r8   r\   DepthTrackingGroupBy._is_simples   s*     ""$P)=)PPr;   c               8    U R                   R                  X5      $ )zReplace `name`, with some native representation.

Arguments:
    name: Name of a `nw.Expr` aggregation method.

Returns:
    A native compatible representation.
)rZ   get)ri   r^   s     r8   _remap_expr_name%DepthTrackingGroupBy._remap_expr_namex   s     ""4..r;   c               B    [         R                  SUR                  5      $ )z=Return the last function name in the chain defined by `expr`. )r.   sub_function_namerh   s     r8   rg   DepthTrackingGroupBy._leaf_name   s       T%8%899r;   r=   N)rD   z#Sequence[DepthTrackingExprT_contra]rH   rJ   )ra   r   rH   rI   )r^   NarwhalsAggregation | AnyrH   r!   )ra   r   rH   rt   )rK   rL   rM   rN   __doc__rO   rc   classmethodr\   rm   rg   rQ   r=   r;   r8   r   r   V   sf     q<<&  Q Q /,/	/ / : :r;   r   c                      \ rS rSrSrg)r      r=   N)rK   rL   rM   rN   rQ   r=   r;   r8   r   r      s     r;   r   c                  0    \ rS rSrSS jr    SS jrSrg)r      c             #    #    UR                  U R                  5      nUR                  (       a  UR                  U5      OUnU" U R                  5      nUR                  5       (       a;  [	        XBU5       H*  u  pVnX`R
                  ;  d  M  UR                  U5      v   M,     g [	        XC5       H  u  pWUR                  U5      v   M     g 7fr5   )_evaluate_output_namesr9   _alias_output_names_is_multi_output_unnamedzipr3   alias)r7   ra   output_namesaliasesnative_exprsnative_exprr^   r   s           r8   _evaluate_exprLazyGroupBy._evaluate_expr   s     224>>B '' $$\2 	
 DNN+((**,/G,T(5zz)%++E22 -U '*,&@"!''.. 'As   BCA Cc             #  T   #    U H  nU R                  U5       S h  vN   M     g  N	7fr5   )r   )r7   rD   ra   s      r8   _evaluate_exprsLazyGroupBy._evaluate_exprs   s(      D**4000 0s   (&
(r=   N)ra   r   rH   Iterator[NativeExprT_co])rD   zIterable[LazyExprT_contra]rH   r   )rK   rL   rM   rN   r   r   rQ   r=   r;   r8   r   r      s    / 1/1	!1r;   r   )+
__future__r   resystypingr   r   r   r   r   r	   r
   r   r   r   narwhals._compliant.typingr   r   r   r   r   r   r   r   r   typing_extensionsr   version_infor   
Protocol38r   __all__r!   r    rO   compiler.   r   rS   r   strr   r   r=   r;   r8   <module>r      s   " 	 
            = < 9 = ; @ 8 7 5+ 
6!10 .  #=  ")S" Y 
 "$J!7 7Lz"46K"KL L(L+-BBC%'<<=L3:')BBC!#<>SST3:l/1BCGH+->>?%'8891+-==>%'7GH1r;   