
    .i,                       U d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
mZ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 er=d dlmZmZmZmZm Z  d dl!m"Z"m#Z# d d	l$m%Z% d d
lm&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ eZ0de1d<   g dZ2 G d deee
f         Z3 G d deeef         Z4 G d de3eef   eeef         Z5 G d de3eef   eeeef         Z6 G d de5eef   eeeeeef         Z7y)    )annotations)partial)TYPE_CHECKINGAnyProtocoloverload)CompliantExprTCompliantExprT_coCompliantFrameTCompliantLazyFrameTDepthTrackingExprTEagerDataFrameT
EagerExprTEagerSeriesT_co	LazyExprTNativeFrameTNativeSeriesT)exclude_column_namesget_column_namespassthrough_column_names)is_numpy_array_2d)
CollectionIterableIteratorKeysViewSequence)	TypeAliasTypeIs)CompliantSelectorNamespace)ImplementationVersion)ConcatMethodCorrelationMethodInto1DArray	IntoDType
IntoSchemaNonNestedLiteral_2DArrayr   
Incomplete)CompliantNamespaceDepthTrackingNamespaceEagerNamespaceLazyNamespacec                  "   e Zd ZU ded<   ded<   edd       ZddZddZddZdd	Z		 	 	 	 	 	 	 	 dd
Z
ddZd dZ	 	 	 	 	 	 d!dZ	 	 	 	 	 	 d!dZd"dZd"dZd"dZd"dZ	 	 	 	 	 	 d#dZ	 	 	 	 	 	 	 	 d$dZed%d       Zd"dZd"dZd&dZd'dZy)(r*   r    _implementationr!   _versionc                     y N selfs    Z/opt/house_gps_flutter/.venv/lib/python3.12/site-packages/narwhals/_compliant/namespace.py_exprzCompliantNamespace._expr:   s    -0    c                D    | j                   j                  t        |       S Ncontextr7   from_column_namesr   r4   s    r6   allzCompliantNamespace.all=       zz++,<d+KKr8   c                N    | j                   j                  t        |      |       S r:   r7   r>   r   r5   namess     r6   colzCompliantNamespace.col@   #    zz++,DU,KUY+ZZr8   c                Z    | j                   j                  t        t        |      |       S N)rD   r;   r7   r>   r   r   rC   s     r6   excludezCompliantNamespace.excludeC   +    zz++(6 , 
 	
r8   c                :     | j                   j                  |d| iS )Nr<   )r7   from_column_indices)r5   indicess     r6   nthzCompliantNamespace.nthH   s    -tzz--wEEEr8   c                    y r2   r3   )r5   abmethods       r6   corrzCompliantNamespace.corrK       r8   c                     y r2   r3   r4   s    r6   lenzCompliantNamespace.lenN       r8   c                     y r2   r3   r5   valuedtypes      r6   litzCompliantNamespace.litO   rX   r8   c                    y r2   r3   r5   ignore_nullsexprss      r6   all_horizontalz!CompliantNamespace.all_horizontalP   rU   r8   c                    y r2   r3   r_   s      r6   any_horizontalz!CompliantNamespace.any_horizontalS   rU   r8   c                     y r2   r3   r5   ra   s     r6   sum_horizontalz!CompliantNamespace.sum_horizontalV   rX   r8   c                     y r2   r3   rf   s     r6   mean_horizontalz"CompliantNamespace.mean_horizontalW   rX   r8   c                     y r2   r3   rf   s     r6   min_horizontalz!CompliantNamespace.min_horizontalX   rX   r8   c                     y r2   r3   rf   s     r6   max_horizontalz!CompliantNamespace.max_horizontalY   rX   r8   c                    y r2   r3   )r5   itemshows      r6   concatzCompliantNamespace.concatZ   s    r8   c                    y r2   r3   )r5   	separatorr`   ra   s       r6   
concat_strzCompliantNamespace.concat_str]   rU   r8   c                     y r2   r3   r4   s    r6   	selectorszCompliantNamespace.selectors`   s    ADr8   c                     y r2   r3   rf   s     r6   structzCompliantNamespace.structb   rX   r8   c                     y r2   r3   rf   s     r6   coalescezCompliantNamespace.coalescec   rX   r8   c                    y r2   r3   r5   datas     r6   from_nativezCompliantNamespace.from_nativee   rX   r8   c                    y)z6Return `True` if `obj` can be passed to `from_native`.Nr3   r5   objs     r6   	is_nativezCompliantNamespace.is_nativef   s    r8   N)returnztype[CompliantExprT])r   r	   )rD   strr   r	   )rN   zSequence[int]r   r	   )rQ   r	   rR   r	   rS   r#   r   r	   )r[   r'   r\   IntoDType | Noner   r	   )ra   r	   r`   boolr   r	   )ra   r	   r   r	   )ro   Iterable[CompliantFrameT]rp   r"   r   r   )ra   r	   rs   r   r`   r   r   r	   )r   z$CompliantSelectorNamespace[Any, Any])r}   r   r   r   )r   r   r   zTypeIs[Any])__name__
__module____qualname____annotations__propertyr7   r?   rE   rJ   rO   rT   rW   r]   rb   rd   rg   ri   rk   rm   rq   rt   rv   rx   rz   r~   r   r3   r8   r6   r*   r*   5   s	   ##0 0L[

F$2?P	 )Z$48	$48	 LLKK.8D	$14DH	 D DCE3r8   r*   c                  L    e Zd ZdZ	 	 	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZy)	AlignDiagonalz2Mixin to help support `"diagonal*"` concatenation.c                     y r2   r3   rZ   s      r6   r]   zAlignDiagonal.litn   s    r8   c               *   |D cg c]  }|j                          }}t        |      }t        t        |            }|j	                         |D ]*  }|j                  fd|j                         D               , | j                  |||      S c c}w )a7  Prepare frames with differing schemas for vertical concatenation.

        Adapted from [`convert_diagonal_concat`].

        [`convert_diagonal_concat`]: https://github.com/pola-rs/polars/blob/c2412600210a21143835c9dfcb0a9182f462b619/crates/polars-plan/src/plans/conversion/dsl_to_ir/concat.rs#L10-L68
        c              3  6   K   | ]  \  }}|vs||f  y wr2   r3   ).0nmr\   seens      r6   	<genexpr>z/AlignDiagonal.align_diagonal.<locals>.<genexpr>   s      WURV"eWs   	)collect_schemaiterdictnextkeysupdatero   _align_diagonal)r5   framesframeschemas
it_schemasunionschemar   s          @r6   align_diagonalzAlignDiagonal.align_diagonalq   s     8>>e5'')>> ']
T*%&zz|  	XFLLWfllnWW	X##FGU;; ?s   Bc           	         	 j                         	i d fdd	fd}t        ||      D cg c]  \  }} |||j                                c}}S c c}}w )Nc              3     K   | D ]D  }j                  |      x}+|   }j                  d |      j                  |      x}|<   | F y wr2   )getr]   alias)missingnameexprr\   
null_exprsr5   union_schemas       r6   iter_missing_exprsz9AlignDiagonal._align_diagonal.<locals>.iter_missing_exprs   s^      &NN400D9(.E.2hhtU.C.I.I$.OOD:d+
	s   AAc                Z    |z
  x}r | j                    |       }  | j                   S r2   )with_columnssimple_select)dfcolumnsr   r   union_namess      r6   alignz,AlignDiagonal._align_diagonal.<locals>.align   s<    %//w/$R__&8&AB#2##[11r8   )r   zIterable[str]r   zIterator[CompliantExprT_co])r   r   r   zKeysView[str]r   r   )r   zip)
r5   r   r   r   r   r   r   r   r   r   s
   `  `   @@@r6   r   zAlignDiagonal._align_diagonal   sR     #'')35
		2 BEVWAUVveV[[]+VVVs   !AN)r[   r'   r\   r   r   r
   )r   zCollection[CompliantFrameT]r   Sequence[CompliantFrameT])r   r   r   zIterable[IntoSchema]r   r&   r   r   )r   r   r   __doc__r]   r   r   r3   r8   r6   r   r   k   sg    < % .> 	 <1<	"<&W)W &W !	W
 
#Wr8   r   c                  $    e Zd ZddZddZddZy)r+   c                D    | j                   j                  t        |       S r:   r=   r4   s    r6   r?   zDepthTrackingNamespace.all   r@   r8   c                N    | j                   j                  t        |      |       S r:   rB   rC   s     r6   rE   zDepthTrackingNamespace.col   rF   r8   c                Z    | j                   j                  t        t        |      |       S rH   rI   rC   s     r6   rJ   zDepthTrackingNamespace.exclude   rK   r8   N)r   r   )rD   r   r   r   )r   r   r   r?   rE   rJ   r3   r8   r6   r+   r+      s    L[
r8   r+   c                  @    e Zd Zedd       Zedd       ZddZd	dZy)
r-   c                6    | j                   j                         S r2   r/   _backend_versionr4   s    r6   r   zLazyNamespace._backend_version       ##4466r8   c                     y r2   r3   r4   s    r6   
_lazyframezLazyNamespace._lazyframe   s    7:r8   c               8    | j                   j                  |      S r2   )r   
_is_nativer   s     r6   r   zLazyNamespace.is_native   s    ))#..r8   c                   | j                   j                  |      r| j                   j                  ||       S dt        |      j                  }t        |      Nr;   zUnsupported type: )r   r   r~   typer   	TypeErrorr5   r}   msgs      r6   r~   zLazyNamespace.from_native   sO    ??%%d+??..tT.BB"4:#6#6"9:nr8   Nr   ztuple[int, ...])r   ztype[CompliantLazyFrameT])r   r   r   zTypeIs[NativeFrameT])r}   zNativeFrameT | Anyr   r   )r   r   r   r   r   r   r   r~   r3   r8   r6   r-   r-      s0     7 7 : :/r8   r-   c                  .   e Zd Zedd       Zedd       Zedd       Z	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZddZ	e
dd       Ze
dd	       Z	 	 	 	 dd
Ze
ddd       Ze
	 	 	 	 	 	 dd       Z	 d	 	 	 	 	 ddZd dZ	 	 	 	 d!dZd dZ	 	 	 	 	 	 d"dZy)#r,   c                6    | j                   j                         S r2   r   r4   s    r6   r   zEagerNamespace._backend_version   r   r8   c                     y r2   r3   r4   s    r6   
_dataframezEagerNamespace._dataframe   s    36r8   c                     y r2   r3   r4   s    r6   _serieszEagerNamespace._series   s    03r8   Nc                     y r2   r3   )r5   whenthen	otherwises       r6   _if_then_elsezEagerNamespace._if_then_else   s    
 r8   c           	          d fd} j                   j                  |t        dd       t        dd             S )Nc                   | j                        }|j                  }| j                  	      }2 |||      \  }}j                  |j                  |j                        }3 |||      \  }}j                  |j                  |j                        }nP| j                        } ||||      \  }}}j                  |j                  |j                  |j                        }|j	                  |      gS r2   )_evaluate_single_output_expr_align_full_broadcastr   native_with_native)
r   predicate_sr   then_sresultotherwise_sr   	predicater5   r   s
         r6   funcz&EagerNamespace.when_then.<locals>.func   s    99)DK55E44T:F &+K&@#V++K,>,>N &+K&@#V++K,>,>N ==iH38fk3Z0V[++&&{7I7I ''/00r8   _evaluate_output_namesc                    dgS )Nliteralr3   )_dfs    r6   <lambda>z*EagerNamespace.when_then.<locals>.<lambda>   s    YK r8   _alias_output_names)r   evaluate_output_namesalias_output_namesr<   )r   r   r   zSequence[EagerSeriesT_co])r7   _from_callablegetattr)r5   r   r   r   r   s   ```` r6   	when_thenzEagerNamespace.when_then   sQ    	1 	1( zz((").0G#  't-BDI ) 
 	
r8   c               r    | j                   j                  |      xs | j                  j                  |      S r2   )r   r   r   r   s     r6   r   zEagerNamespace.is_native   s+    ))#.N$,,2I2I#2NNr8   c                    y r2   r3   r|   s     r6   r~   zEagerNamespace.from_native   s    EHr8   c                    y r2   r3   r|   s     r6   r~   zEagerNamespace.from_native   s    FIr8   c               (   | j                   j                  |      r| j                   j                  ||       S | j                  j                  |      r| j                  j                  ||       S dt	        |      j
                  }t        |      r   )r   r   r~   r   r   r   r   r   s      r6   r~   zEagerNamespace.from_native   s}     ??%%d+??..tT.BB<<""4(<<++D$+??"4:#6#6"9:nr8   c                    y r2   r3   r5   r}   r   s      r6   
from_numpyzEagerNamespace.from_numpy  s    WZr8   c                    y r2   r3   r   s      r6   r   zEagerNamespace.from_numpy	  s     r8   c                   t        |      r| j                  j                  |||       S | j                  j                  ||       S )N)r   r<   r;   )r   r   r   r   r   s      r6   r   zEagerNamespace.from_numpy  sB     T"??--d64-PP||&&tT&::r8   c                    y r2   r3   r5   dfss     r6   _concat_diagonalzEagerNamespace._concat_diagonal  rX   r8   c                    y r2   r3   r   s     r6   _concat_horizontalz!EagerNamespace._concat_horizontal  s    r8   c                    y r2   r3   r   s     r6   _concat_verticalzEagerNamespace._concat_vertical  rX   r8   c                  |D cg c]  }|j                    }}|dk(  r| j                  |      }n4|dk(  r| j                  |      }n|dk(  r| j                  |      }nt        | j
                  j                  ||       S c c}w )N
horizontalverticaldiagonalr;   )r   r   r   r   NotImplementedErrorr   r~   )r5   ro   rp   itemr   r   s         r6   rq   zEagerNamespace.concat  s     (--tt{{--,,,S1FJ**3/FJ**3/F%%**64*@@ .s   Br   )r   ztype[EagerDataFrameT])r   ztype[EagerSeriesT_co]r2   )r   r   r   r   r   zNativeSeriesT | Noner   r   )r   r   r   r   r   zEagerExprT | Noner   r   )r   r   r   z$TypeIs[NativeFrameT | NativeSeriesT])r}   r   r   r   )r}   r   r   r   )r}   z"NativeFrameT | NativeSeriesT | Anyr   !EagerDataFrameT | EagerSeriesT_co).)r   Noner}   r$   r   r   )r   !IntoSchema | Sequence[str] | Noner}   r(   r   r   )r   r  r}   zInto1DArray | _2DArrayr   r  )r   zSequence[NativeFrameT]r   r   )r   zSequence[NativeFrameT | Any]r   r   )ro   zIterable[EagerDataFrameT]rp   r"   r   r   )r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r   r   rq   r3   r8   r6   r,   r,      sl    7 7 6 63 3
 +/	  (	
 
 W[
#
+5
BS
	
@O H HI I6	* Z Z)J	  59	; 2	;$;
 
+; T/	 TA.A8DA	Ar8   r,   N)8
__future__r   	functoolsr   typingr   r   r   r   narwhals._compliant.typingr	   r
   r   r   r   r   r   r   r   r   r   narwhals._utilsr   r   r   narwhals.dependenciesr   collections.abcr   r   r   r   r   typing_extensionsr   r   narwhals._compliant.selectorsr   r    r!   narwhals.typingr"   r#   r$   r%   r&   r'   r(   r)   r   __all__r*   r   r+   r-   r,   r3   r8   r6   <module>r     s   "  9 9    
 4RR3H7    J	3/>"AB 3l1WH_.??@ 1Wh
(::;_001
 *I56 )\9:(fA?J67_oz<VWfAr8   