
    Lpj`                    8	   % S SK Jr  S SKJr  S SKJrJrJr  S SKr	S SK
Jr  S SKJr  S SKJrJrJr  S SKJr  \(       a  S SKJrJrJrJr  S S	KJrJr  S S
KJr  S SKJr  S SK J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,  S SK-J.r.  S SK/J0r0  S SK1J2r2J3r3  \%r4S\5S'   SjS jr6SkS jr7SlS jr8SmS jr9SnS jr:SoS jr;SSS.         SpS jjr<OS SK
J<r<  S SK=J;r;J7r7J:r:J9r9J8r8J6r6  \R|                  R                  5       r@ SSSSS S!S"S#S$S%S&.
rAS'\5S('   \	R                  rC SqS) jrDSrS* jrESsS+ jrFStS, jrG Su     SvS- jjrHSwS. jrI Su       SxS/ jjrJSyS0 jrKSzS1 jrL\" S2S39SzS4 j5       rM\R                  R                  rO0 \OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " \	R                  " 5       \	R                  " 5       5      _\OR                  \	R                  " 5       _\OR                  \	R                  " S55      _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _\OR                  \	R                  " 5       _rrS6\5S7'   \OR                  \OR                  4ruS{S8 jrv      S|S9 jrwS}S: jrx      S~S; jryS<rzS=r{S>r|S?r}S@r~SArSBr\z \{ SC\| SC\ SD3rSErSFrSGrSHr\SI4\SJ4\SK4\SL44r\}SM4\~SN4\SO44rSSS.         SSP jjrSSQ jrSSR jrSSS jr        SST jr      SSU jr\@SV:  a  SWSX0SWSY0SWSZ0S[.rS\\5S]'   OS^S_0S^S_0S^S`0S[.r S     SSa jjr " Sb Sc\Sd   5      r      SSe jrSSf jrSSg jr        SSh jr        SSi jrg)    )annotations)	lru_cache)TYPE_CHECKINGAnycastN)EagerSeriesNamespace)ImplementationVersionisinstance_or_issubclass)ColumnNotFoundError)IterableIteratorMappingSequence)Literal	TypeAlias)TypeIsArrowSeries)ArrayAnyArrayOrScalarArrayOrScalarT1ArrayOrScalarT2ChunkedArrayAnyDictionaryArrayAny
IncompleteNativeIntervalUnitNullPlacementOrderPromoteOptions	ScalarAny)IntervalUnit)DType)	IntoDTypePythonLiteralr   ChunkedArrayStructArrayc                    g N ts    Q/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/narwhals/_arrow/utils.pyis_timestampr-   *   s    C    c                    g r(   r)   r*   s    r,   is_durationr0   +   s    Sr.   c                    g r(   r)   r*   s    r,   is_listr2   ,   s    Sr.   c                    g r(   r)   r*   s    r,   is_large_listr4   -   s    r.   c                    g r(   r)   r*   s    r,   is_fixed_size_listr6   .   s    cr.   c                    g r(   r)   r*   s    r,   is_dictionaryr8   /   s    3r.   optionsmemory_poolc                  g r(   r)   )stringspatternr:   r;   s       r,   extract_regexr?   0   s     #&r.   )r?   )r8   r0   r6   r4   r2   r-   yearquartermonthdayhourminutesecondmillisecondmicrosecond
nanosecond)
yqmodhmsmsusnsz)Mapping[IntervalUnit, NativeIntervalUnit]
UNITS_DICTc                   SSK Jn  U" U SS9$ )Nr   )maybe_extract_py_scalarT)return_py_scalar)narwhals._arrow.seriesrV   )valuerV   s     r,   extract_py_scalarrZ   X   s    >"54@@r.   c                t    [        U [        R                  [        R                  [        R                  45      $ )z-Return True for any base `pyarrow` container.)
isinstancepaChunkedArrayArrayScalar)objs    r,   is_array_or_scalarrb   ^   s"    cBOORXXryyABBr.   c                    [         S:  a*  SS Kn[        R                  " UR	                  XU5      5      $ [        R                  " XU5      $ )N)   r   )BACKEND_VERSIONnumpyr]   arrayarange)startendstepnps       r,   rh   rh   c   s8    xx		%d34499U&&r.   c                $   [        U S   5      n[        U 5      n[        SUS5      n[        SUS5      n[        SX-  S5      n[        S[        R                  " U[        U5      5      5      n[        S[        R                  " U[        R                  " U[        U5      5      5      5      n[        R                  " X65      n[        R                  " XG5      n	[        S[        R                  " [        R                  " U	[        U5      5      U5      5      n
[        R                  " [        R                  " U 5      U
5      n[        S[        SX-  S-   U5      5      n[        R                  " [        R                  R                  X5      /5      $ )Nr      pa.Int64Array)lenrh   r   pcdividelitsubtractmultiplytakeaddr]   concat_arrayschunked_array	ListArrayfrom_arrays)arraysnnum_colsijkrow_idxcol_idxi_repj_tileindicesinterleavedoffsetss                r,   build_list_arrayr   l   s"    	F1IA6{Hq!QAq(AAq!,"A?BIIaX$?@G?BKK2;;wH3V$WXGGGAEWWQ F?BFF2;;vs1v+F$NOG''"**62G<K?F1alQ.>$IJGR\\55gKLMMr.   c                   [        U [        R                  5      (       a  U $ [        U [        5      (       a  [        R                  " X5      $ [        R                  " U /U5      $ r(   )r\   r]   r^   listry   )arrdtypes     r,   ry   ry      sM     #r''
#t++SE5))r.   c                V    [         R                  " XR                  R                  5      $ )ztCreate a strongly-typed Array instance with all elements null.

Uses the type of `series`, without upseting `mypy`.
)r]   nullsnativetype)r}   seriess     r,   
nulls_liker      s    
 88A}}))**r.   c               D    [         n[        R                  " U" XS9U5      $ )z}Create an Array instance whose slots are the given scalar.

*Optionally*, casting to `dtype` **before** repeating `n` times.
r   )rs   r]   repeat)rY   r}   r   lit_s       r,   r   r      s     D99T%,a00r.   c               0    [         R                  " SU 5      $ )Nr   )r]   r   )r}   s    r,   zerosr      s    99Q?r.   c                    [        U [        R                  5      (       a  UR                  R	                  5       $ [        X5      $ r(   )r\   r]   ExtensionTypedtypesUnknown&native_non_extension_to_narwhals_dtype)r   versions     r,   native_to_narwhals_dtyper      s3    %))**~~%%''1%AAr.      )maxsizec                   UR                   n[        R                  R                  U 5      (       a  UR	                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR!                  5       $ [        R                  R#                  U 5      (       a  UR%                  5       $ [        R                  R'                  U 5      (       a  UR)                  5       $ [        R                  R+                  U 5      (       a  UR-                  5       $ [        R                  R/                  U 5      (       a  UR1                  5       $ [        R                  R3                  U 5      (       a  UR5                  5       $ [        R                  R7                  U 5      (       dK  [        R                  R9                  U 5      (       d'  [;        [        R                  SS 5      " U 5      (       a  UR=                  5       $ [        R                  R?                  U 5      (       a  URA                  5       $ [C        U 5      (       a$  URE                  U RF                  U RH                  S9$ [K        U 5      (       a  URM                  U RF                  S9$ [        R                  RO                  U 5      (       a  URQ                  5       $ [        R                  RS                  U 5      (       a  URU                  [W        U RX                  5       Vs/ s HQ  nUR[                  U R]                  U5      R^                  [a        U R]                  U5      Rb                  U5      5      PMS     sn5      $ [e        U 5      (       d  [g        U 5      (       a%  URi                  [a        U Rj                  U5      5      $ [m        U 5      (       a0  URo                  [a        U Rj                  U5      U Rp                  5      $ [        R                  Rs                  U 5      (       a$  URu                  U Rv                  U Rx                  S9$ [        R                  R{                  U 5      (       d$  [        R                  R}                  U 5      (       a  UR                  5       $ [        R                  R                  U 5      (       a  UR                  5       $ UR                  5       $ s  snf )Nis_string_viewc                    g)NFr)   )_s    r,   <lambda>8native_non_extension_to_narwhals_dtype.<locals>.<lambda>   s    r.   )	time_unit	time_zone)r   	precisionscale)Cr   r]   typesis_int64Int64is_int32Int32is_int16Int16is_int8Int8	is_uint64UInt64	is_uint32UInt32	is_uint16UInt16is_uint8UInt8
is_booleanBoolean
is_float64Float64
is_float32Float32
is_float16Float16	is_stringis_large_stringgetattrString	is_date32Dater-   Datetimeunittzr0   Durationr8   Categorical	is_structStructrange
num_fieldsFieldfieldnamer   r   r2   r4   List
value_typer6   r_   	list_sizeis_decimal128Decimalr   r   	is_time32	is_time64Time	is_binaryBinaryr   )r   r   r   r   s       r,   r   r      s   ^^F	xx||~	xx||~	xx||~	xx{{}	xx%  }}	xx%  }}	xx%  }}	xx||~	xx5!!~~	xx5!!~~	xx5!!~~	xx5!!~~ 	5!!88##E**288-?FF}}	xx%  {{}EuxxHH544	xxe$$!!##	xx%  }} u//0
 1A	 KKN'',U[[^-@-@'J 1
 	
 u~~u--{{3E4D4DgNOO%  ||$U%5%5w?
 	
 
xxe$$~~u{{~KK	xx%  BHH$6$6u$=$={{}	xx%  }}>>)s   AWrS   z!Mapping[type[DType], pa.DataType]NW_TO_PA_DTYPESc                   UR                   nU R                  5       n[        R                  U5      =n(       a  U$ [	        XR
                  5      (       aK  U R                  nU R                  =n(       a  [        R                  " XV5      $ [        R                  " U5      $ [	        XR                  5      (       a   [        R                  " U R                  5      $ [	        XR                  5      (       a&  [        R                  " [        U R                  US9S9$ [	        XR                   5      (       aO  [        R"                  " U R$                   Vs/ s H#  nUR&                  [        UR(                  US94PM%     sn5      $ [	        XR*                  5      (       a4  [        U R                  US9nU R,                  n	[        R                  " XS9$ [	        XR.                  5      (       a)  [        R0                  " U R2                  U R4                  S9$ [7        U[8        5      (       a  SUR:                   S3n
[=        U
5      eSU  3n
[?        U
5      es  snf )N)r   )r   )r   r   zConverting to z$ dtype is not supported for PyArrow.zUnknown dtype: ) r   	base_typer   getr   r   r   r   r]   	timestampr   durationr   list_narwhals_to_native_dtypeinnerr   structfieldsr   r   r_   sizer   
decimal128r   r   
issubclassUNSUPPORTED_DTYPES__name__NotImplementedErrorAssertionError)r   r   r   r   pa_typer   r   r   r   r   msgs              r,   r   r     s   ^^F!I!%%i00w07705*?"*?r||D%XbllSWFXX77{{5??++{{33xx#;EKKQX#YZZ}}55yy #\\)E 5ekk7ST)
 	
  ||44(gFJJ	xx33~~66}}uekkJJ)/00y1122VW!#&&E7
#C

s   *Ic                ,   SSK Jn  Uc   U R                  [        SU R                  S94$ [        X5      (       a  U R                  (       a,  UR                  (       d  U R                  S   UR                  4$ UR                  (       a  U R                  UR                  S   4$ U R                  UR                  4$ [        U[        5      (       a  Sn[        U5      eU R                  [        U[        R                  5      (       a  U4$ [        U5      4$ )a6  Extract native objects in binary  operation.

If the comparison isn't supported, return `NotImplemented` so that the
"right-hand-side" operation (e.g. `__radd__`) can be tried.

If one of the two sides has a `_broadcast` flag, then extract the scalar
underneath it so that PyArrow can do its own broadcasting.
r   r   Nr   z$Expected Series or scalar, got list.)rX   r   r   rs   _typer\   
_broadcastr   	TypeErrorr]   r`   )lhsrhsr   r   s       r,   extract_nativer   "  s     3
{zz3t#))444###>>#..::a=#**,,>>::szz!},,zz3::%%#t4n::jbii88sFFc#hFFr.   c          
        [         R                  " U[        SUR                  S95      n[         R                  " X![        SUR                  S95      n[        S U R                  S9n[
        R                  R                  U R                  5      (       Gaj  [
        R                  R                  UR                  5      (       Ga;  [         R                  " U[         R                  " X5      U5      n[
        R                  R                  UR                  5      (       a  [        SUR                  5      n[         R                  " [         R                  " XQ5      U 5      n[         R                  " [         R                  " X5      [        SU5      5      n[         R                  " [         R                  " Xx5      [         R                  " U[        SU5      5      U5      n	OUn	U	R                  U R                  5      n	U	$ [         R                  " U[         R                   " X5      U5      n[         R"                  " U5      n	U	$ )Nr   r   rn   zpa._lib.Int64Type)rq   	not_equalrs   r   if_elser]   r   
is_integerdivide_checkedis_signed_integerr   ru   lessbit_wise_xorand_rt   rr   floor)
leftright	safe_mask
safe_rightnon_safe_resultdivideddiv_typehas_remainderhas_one_negative_operandresults
             r,   floordiv_compatr  @  s    UC

$;<IIc!%**.EFJ$TYY/O	xx499%%"((*=*=ejj*I*I**r((:O
 88%%gll33/>HLLW)DdKM')ww,c!X.>($ ZZ@GSH%56F FTYY' M **Y		$(C_U'"Mr.   c                L   [         R                  R                  U R                  5      (       at  [         R                  R                  UR                  5      (       aF  U R	                  [         R
                  " 5       SS9UR	                  [         R
                  " 5       SS94$ X4$ )NF)safe)r]   r   r  r   r   float64)arrow_array	pa_objects     r,   cast_for_truedivr  c  s     
xx;++,,1D1DY^^1T1T 

599>>JJLu <J <
 
 	
 !!r.   z/(?P<date>\d{1,4}[-/.]\d{1,2}[-/.]\d{1,4}|\d{8})z(?P<sep>\s|T)z'(?P<time>\d{2}:\d{2}(?::\d{2})?|\d{6}?)z^(?P<hms>\d{2}:\d{2}:\d{2})$z^(?P<hm>\d{2}:\d{2})$z^(?P<hms_no_sep>\d{6})$z(?P<tz>Z|[+-]\d{2}:?\d{2})?z?$zw^(?P<year>(?:[12][0-9])?[0-9]{2})(?P<sep1>[-/.])(?P<month>0[1-9]|1[0-2])(?P<sep2>[-/.])(?P<day>0[1-9]|[12][0-9]|3[01])$zw^(?P<day>0[1-9]|[12][0-9]|3[01])(?P<sep1>[-/.])(?P<month>0[1-9]|1[0-2])(?P<sep2>[-/.])(?P<year>(?:[12][0-9])?[0-9]{2})$zw^(?P<month>0[1-9]|1[0-2])(?P<sep1>[-/.])(?P<day>0[1-9]|[12][0-9]|3[01])(?P<sep2>[-/.])(?P<year>(?:[12][0-9])?[0-9]{2})$zY^(?P<year>(?:[12][0-9])?[0-9]{2})(?P<month>0[1-9]|1[0-2])(?P<day>0[1-9]|[12][0-9]|3[01])$%Y%m%dz%Y-%m-%dz%d-%m-%Yz%m-%d-%Yz%H:%M:%Sz%H:%Mz%H%M%Sc         	     j    [         R                  " [        XX#S9R                  5      n[	        SU5      $ )Nr9   pa.StructArray)r]   rx   r?   chunksr   )r=   r>   r:   r;   rs        r,   _extract_regex_concat_arraysr    s4     	gQXX	A  !$$r.   c                L   [        U R                  5       R                  SS5      [        S9n[        R
                  " UR                  5       5      R                  5       (       d  Sn[        U5      eUR                  S5      nUR                  S5      n[        R                  " [        R                  " U5      5      R                  5       S:  a  Sn[        U5      e[        R                  " [        R                  " U5      5      R                  5       S:  a  S	n[        U5      e[        [        S
UR                  S5      5      5      n[        [        S
UR                  S5      5      5      nUS   R                  5       nUS   R                  5       (       a  SOSnU U U U 3$ )z.Try to infer datetime format from StringArray.r   
   r>   zUnable to infer datetime format, provided format is not supported. Please report a bug to https://github.com/narwhals-dev/narwhals/issuessepr   rn   z@Found multiple separator values while inferring datetime format.z?Found multiple timezone values while inferring datetime format.pc.StringArraydatetimez%z )r  	drop_nullsliceFULL_RErq   allis_validas_pyr   r   countunique
ValueError_parse_date_formatr   parse_time_format)	r   matchesr   
separatorsr   
date_value
time_value	sep_valuetz_values	            r,   parse_datetime_formatr9    sP   *3==?+@+@B+GQXYG66'""$%++--U 	 "#&&u%J	t	B 
xx		*%&,,.2Po	xx		"$$&*Oo#D)97==;P$QRJ"4(8'--:O#PQJ1##%I!u{{}}t"H\)ZL
;;r.   c                   [          GHp  u  p[        R                  " XS9nUS:X  a;  [        R                  " UR	                  5       5      R                  5       (       a  Us  $ [        R                  " UR	                  5       5      R                  5       (       d  M  [        R                  " [        R                  " UR                  S5      =n5      5      R                  5       S:X  d  M  [        R                  " [        R                  " UR                  S5      =n5      5      R                  5       S:X  d  GM3  US   R                  5       =oeS   R                  5       :X  d  GM_  UR                  SU5      s  $    Sn[        U5      e)	Nr"  r  sep1rn   sep2r   -zgUnable to infer datetime format. Please report a bug to https://github.com/narwhals-dev/narwhals/issues)DATE_FORMATSrq   r?   r+  r,  r-  r.  r/  r   replacer0  )r   date_rgxdate_fmtr3  r;  r<  date_sep_valuer   s           r,   r1  r1    s   *l""39xBFF7+;+;+=$>$D$D$F$FOFF7##%&,,..7==+@#@4ABHHJaO7==+@#@4ABHHJaO#'7==?2Aw}}F##C88 +	Q  S/r.   c                    [          HT  u  p[        R                  " XS9n[        R                  " UR	                  5       5      R                  5       (       d  MR  Us  $    g)Nr"  r'  )TIME_FORMATSrq   r?   r+  r,  r-  )r   time_rgxtime_fmtr3  s       r,   r2  r2    sJ    *""3966'""$%++--O + r.   c                   U(       d  U S4$ US-  nX1S-  S:H  -
  nU R                   R                  n[        X05      /UQ[        X@5      P7nU R                  [        R
                  " U5      5      X4-   4$ )aY  Pad series with None values on the left and/or right side, depending on the specified parameters.

Arguments:
    series: The input ArrowSeries to be padded.
    window_size: The desired size of the window.
    center: Specifies whether to center the padding or not.

Returns:
    A tuple containing the padded ArrowSeries and the offset value.
r      )r   r  r   _with_nativer]   rx   )r   window_sizecenteroffset_leftoffset_rightr  r|   s          r,   
pad_seriesrN    s{     qy"K/Q"67L]]!!F,WvWz,7WWFr//78+:TTTr.   c                   ^ [        S U 5       5      (       d  [        R                  " 5       O[        R                  " 5       mU4S jU 5       [	        U T5      4$ )Nc              3  t   #    U  H.  n[         R                  R                  UR                  5      v   M0     g 7fr(   )r]   r   r   r   ).0cas     r,   	<genexpr>2cast_to_comparable_string_types.<locals>.<genexpr>  s&     N~288++BGG44~s   68c              3  D   >#    U  H  oR                  T5      v   M     g 7fr(   )r   )rQ  rR  r   s     r,   rS  rT    s     4^rGGENN^s    )anyr]   stringlarge_stringrs   )	separatorchunked_arraysr   s     @r,   cast_to_comparable_string_typesr[    sI     N~NNN 			__ 

 5^4c)U6KKKr.   )   promote_optionsdefault
permissivenone)r^  r_  r`  z*Mapping[PromoteOptions, Mapping[str, Any]]_PROMOTEpromoteTFc                >    [         R                  " U 40 [        U   D6$ r(   )r]   concat_tablesra  )tablesr]  s     r,   rd  rd  	  s     F@h&?@@r.   c                      \ rS rSrSrg)ArrowSeriesNamespacei  r)   N)r   
__module____qualname____firstlineno____static_attributes__r)   r.   r,   rg  rg    s    TWr.   rg  )r   r   c                L   [         nUS:X  a  SU[        R                  " SS94OSU4n[        R                  " [        R
                  R                  [        R                  " U 5      [        R                  " U 5      /SS/S9R                  S5      R                  U/5      R                  S5      R                  SU 35      5      n[        R                  " [        R                  " [        R                  " U 5      [        S5      5      5      nUS:X  a'  [        R                  " UR!                  5       S S5      nO/[        R"                  " U" S UR$                  S9['        U 5      5      n[        R(                  " [        R*                  " UUR-                  S	5      U5      /5      $ )
Nsumvaluesr   )	min_countr   namesvalues_r   F)rs   rq   ScalarAggregateOptionsr]   rg   Tabler{   list_flattenlist_parent_indicesgroup_by	aggregatesort_bycolumnr   list_value_lengthr   is_nullr   r   rp   ry   replace_with_mask	fill_null)rg   funcr   aggregationaggnon_empty_mask
base_arrays          r,   list_aggr    sY    D 5= 
422Q?@ 
 ((
__U#R%;%;E%BCY' 	 	
 
)		K=	!			'$ 	!	C XXbll2+?+?+FAOPNu}ZZ 6 6 8$B
YYtDsxx8#e*E
  ((/	
 r.   c               D   [        U R                  5      (       d  U $ [        SU R                  5       R                  5      nU(       d   [        / /[        R                  " 5       5      $ US   R                  n[        R                  " USSS9nUR                  (       a@  [        R                  " [        R                  " U5      [        SUR                  5      U5      n[        R
                  " U Vs/ s H  oCR                  UR                   5      PM     sn5      $ s  snf )a  Return an array which orders like `array`, but with a type `pyarrow` can sort.

`pyarrow` has no ordering kernels for `dictionary` types
(https://github.com/apache/arrow/issues/29887), so replace the dictionary indices
with the rank of the value they point at. Ranking the (typically small) dictionary
is much cheaper than decoding every row, and gives the lexicographic order which
`polars` and `pandas` use for (unordered) categoricals.
zlist[DictionaryArrayAny]r   	ascendingmin)	sort_keys
tiebreakerN)r8   r   r   unify_dictionariesr  ry   r]   uint64
dictionaryrq   rank
null_countr   r|  rs   rv   r   )rg   r  r  rankschunks        r,   sortabler  7  s     $$,e.F.F.H.O.OPFbT299;//%%JGGJ+%HE

2::j13tUZZ3H%PFKF5ZZ6FKLLKs   2$Dc          
     &   U H  nU R                   R                  U5      nUS:X  a  SU S3n[        U5      e[        U R	                  U5      R
                  5      (       d  M`  U R                  X2[        U R                  U5      5      5      n M     U $ )zNReplace every `dictionary`-typed column named in `keys` with `sortable` ranks.zColumn 'z' not found in table.)	schemaget_field_indexr   r8   r   r   
set_columnr  rz  )tablekeysr   indexr   s        r,   sortable_tabler  N  s    ,,T2B;TF"78C%c**U+0011$$U(5<<;N2OPE  Lr.   c                    [         S:  a  [        R                  " XUS9$ U VVs/ s H	  u  p4X4U4PM     nnn[        R                  " XS9$ s  snnf )zJ`pc.sort_indices`, hiding how `null_placement` must be passed per version.)   )r  null_placement)r  )re   rq   sort_indices)r  sortingr  r   orderkeyeds         r,   r  r  Z  sP     uWW ?FFg{td>*gEF??522 Gs   Ac                   U(       a  SOSnU(       a  SOSnSu  pV[         R                  " [         R                  " U 5      [        S5      5      n[        R
                  R                  [        S[        U 5      SS9U /XV/S	9nUR                  U5      n	UR                  [         R                  " [         R                  " U5      [        S
5      5      5      n
[        R
                  R                  [         R                  " U 5      [         R                  " U 5      /Xe/S	9n[        XS4Xc4/U5      nU	R                  U5      R!                  5       R"                  n[        R$                  R                  U[        R&                  " UR)                  U5      R                  U5      5      5      n[        R
                  R                  U	R                  U5      U/XV/S	9n[        R*                  " X/5      R-                  U5      R                  U5      $ )N
descendingr  at_endat_start)idxrn  r   rn   )ri   rj   rk   rp  T)rq   greaterr{  rs   r]   rt  r{   rh   rp   filterr~  invertru  rv  r  rz  combine_chunksr   rz   rg   rv   rd  ry  )rg   r  
nulls_lastsort_directionnulls_positionr  vis_not_sortedindexednot_sorted_partpass_throughexplodedsorted_indicesr   sorted_implodedimploded_by_idxs                   r,   	list_sortr  f  s    #  AKHPZNFCJJr33E:CFCMhh""	aSZa	0%8 # G nn]3O>>",,ryy/GT"STLxx##		!7!7!>?x $ H "%':;^N $$Q'668@@Gll..(--7>>qABO hh**				$o6sh + O _;<DDSIPPQRSSr.   )r+   r   returnz"TypeIs[pa.TimestampType[Any, Any]])r+   r   r  zTypeIs[pa.DurationType[Any]])r+   r   r  zTypeIs[pa.ListType[Any]])r+   r   r  zTypeIs[pa.LargeListType[Any]])r+   r   r  z&TypeIs[pa.FixedSizeListType[Any, Any]])r+   r   r  z(TypeIs[pa.DictionaryType[Any, Any, Any]])
r>   strr=   r   r:   r   r;   r   r  r&   )rY   r   r  r   )ra   r   r  zTypeIs[ArrayOrScalar])ri   intrj   r  rk   r  r  r   )r|   zlist[pa.Array[Any]]r  zpa.ChunkedArray[Any]r(   )r   z#ArrayOrScalar | list[Iterable[Any]]r   pa.DataType | Noner  r   )r}   r  r   r   r  r   )r   r  rY   zPythonLiteral | ScalarAnyr}   r  r  r   )r}   r  r  ro   )r   pa.DataTyper   r
   r  r#   )r   r$   r   r
   r  r  )r   r   r   z'ArrowSeries | PythonLiteral | ScalarAnyr  z3tuple[ChunkedArrayAny, ChunkedArrayAny | ScalarAny])r  r   r	  r   r  r   )r  r   r  r   r  z'tuple[ArrayOrScalarT1, ArrayOrScalarT2])
r>   r  r=   r   r:   r   r;   r   r  r  )r   r   r  r  )r   r$  r  r  )r   r   rJ  r  rK  boolr  ztuple[ArrowSeries, int])rZ  zChunkedArrayAny | ScalarAnyrY  r  r  z7tuple[Iterator[ChunkedArrayAny | ScalarAny], ScalarAny])r`  )re  zIterable[pa.Table]r]  r    r  pa.Table)rg   r   r  z:Literal['min', 'max', 'mean', 'approximate_median', 'sum']r  r   )rg   r   r  r   )r  r  r  zIterable[str]r  r  )r  r  r  zSequence[tuple[str, Order]]r  r   r  zpa.UInt64Array)rg   r   r  r  r  r  r  r   )
__future__r   	functoolsr   typingr   r   r   pyarrowr]   pyarrow.computecomputerq   narwhals._compliantr   narwhals._utilsr	   r
   r   narwhals.exceptionsr   collections.abcr   r   r   r   r   r   typing_extensionsr   rX   r   narwhals._arrow.typingr   r   r   r   r   r   r   r   r   r   r    r!   narwhals._durationr"   narwhals.dtypesr#   narwhals.typingr$   r%   r&   __annotations__r-   r0   r2   r4   r6   r8   r?   pyarrow.typesPYARROW_backend_versionre   rT   scalarrs   rZ   rb   rh   r   ry   r   r   r   r   r   MAINr   r   r  r   float32r   float16r   binaryr   rW  r   bool_r   r  uint32r   date32r   time64r   int8r   int16r   int32r   int64r   uint8r   uint16r   r   r  r   ObjectEnumr   r   r   r  r  DATE_RESEP_RETIME_REHMS_REHM_REHMS_RE_NO_SEPTZ_REr*  YMD_REDMY_REMDY_REYMD_RE_NO_SEPr>  rD  r  r9  r1  r2  rN  r[  ra  rd  rg  r  r  r  r  r  r)   r.   r,   <module>r     s   "  + +   4 M M 3EE)(2    0%8 *9Y8G@8CQN & & &
 & & 
!& .  !((99; + 
	
				


9
5  	ii !AC
'N* KO*	,*5G**+ NR18J1$1),11B 2@ @F 
		6
NNBJJL6
NNBJJL6 NNBJJL6 MM299;	6
 MM299;6 NNBHHJ6 biik299;?6 KK6 KK46 KK6 LL"((*6 LL"((*6 LL"((*6 LL"((*6 MM299;6  MM299;!6" MM299;#62 & mmV[[1 @G	GBG8G< F" "-<","$ =	
4	( *%Yvhay%
3 
D 
D 
Dl HZZZ	 $ug&68QR % %%
 % % %<>(UU),U6:UU.	L0	L=@	L<	L e &y1(,7"F+<H8  t$ $'E"H CIAA1?AA X/0PQ W""
D" "JM.		3	39	3KX	3	3TT+/T=ATTr.   