
    Mh:                    j    S r SSKJr  SSKJr  SSKJr  SSKrSSK	J
r
Jr  SSKJr  SSS jjrS	 rS
 rg)z/Common utility functions for rolling operations    )annotations)defaultdict)castN)ABCDataFrame	ABCSeries)
MultiIndexc                  ^^^ [        U [        5      (       a+  [        T[        5      (       a  [        U T5      u  pEU" XE5      $ [        U [        5      (       Ga  SSKJm  SU4S jjn0 n[        T[        5      (       Ga  USL Ga&  U TL aZ  [        [        U R                  5      5       H0  nU" U R                  S S 2U4   TR                  S S 2U4   5      Xx'   M2     U" Xp5      $ U R                  R                  (       d  [        S5      eTR                  R                  (       d  [        S5      eU R                  TSS9u  pE[        XE5      u  pEU R                  R                  TR                  5      n	U	 H   n
X;   d  M
  X;   d  M  U" XJ   XZ   5      Xz'   M"     T" XtR                  U	S	9$ US
L Ga  [        [         5      n[        [        U R                  5      5       Hv  n[        [        TR                  5      5       HQ  nX:  a  TU L a  X{   U   Xx   U'   M  U" [        U R                  S S 2U4   TR                  S S 2U4   5      6 Xx   U'   MS     Mx     SSKJn  U R                  R                  TR                  5      n[        U5      (       GaM  U" [        [        U R                  5      5       VVs/ s H<  nU" [        [        TR                  5      5       Vs/ s H
  oU   U   PM     snS
S9PM>     snnS
SS9mU R                  Tl        TR                  R$                  S:  Ga  ['        [(        TR                  5      Tl        [*        R,                  " U[        T5      [        U5      -  5      nUU4S j[        TR                  R$                  5       5       n[/        TR                  R0                  5      UR2                  /-   n[(        R4                  " / UQUPUS9Tl        [        TR                  R6                  5      nUS-
  /[/        [        US-
  5      5      -   nTR9                  U5      R;                  5       mO[(        R<                  " [        [        TR                  5      5      [        [        U5      5      /5      Tl        TR?                  SS5      R;                  5       m[(        R<                  " U/TR                  /-   5      Tl        O2T" [)        U R                  TR                  // / /S9TR                  SS9mTR                  RA                  U R                  R0                  5      Tl        TR                  RA                  UR0                  TR                  R0                  -   5      Tl        T$ g [        [        U R                  5      5       Vs0 s H#  nX" [        U R                  S S 2U4   T5      6 _M%     nnU" Xp5      $ [C        TX5      $ s  snf s  snnf s  snf )Nr   )	DataFramec                   > T" XR                   S9n[        UR                  5      S:  a   UR                  UR                     Ul        U$ UR                  R                  5       Ul        U$ )N)indexr   )r   lencolumnscopy)dataframe_templateresultr
   s      K/var/www/html/env/lib/python3.13/site-packages/pandas/core/window/common.pydataframe_from_int_dict3flex_binary_moment.<locals>.dataframe_from_int_dict   s^    t+?+?@F6>>"Q&!/!7!7!G M "0!7!7!<!<!>M    Fz'arg1' columns are not uniquez'arg2' columns are not uniqueouter)join)r   r   T)concat)ignore_index   )r   axisc              3     >#    U  HT  n[         R                  " TR                  R                  U5      [	        T5      [	        TR                  5      -  5      v   MV     g 7f)N)nprepeatr   get_level_valuesr   ).0iarg2r   s     r   	<genexpr>%flex_binary_moment.<locals>.<genexpr>`   sS      '
 &A	 II $ = =a @ #Fs4<</@ @  &As   AA)names)levelscodesfloat64)r   r   dtype)returnr
   )"
isinstancer   prep_binaryr   pandasr
   ranger   r   iloc	is_unique
ValueErroralignunionr   r   dictr   nlevelsr   r   r   tilelistr&   namefrom_arraysr'   reorder_levels
sort_indexfrom_product	swaplevel	set_namesflex_binary_moment)arg1r#   fpairwiseXYr   resultsr"   res_columnscoljr   result_indexresult_levelarg2_levelsresult_names
num_levels	new_orderr
   r   s    `                 @@r   r@   r@      s
   $	""z$	'B'B4&w	D,	'	'$	 dL))5 4<"3t||#45%&tyyA		!Q$%H
 627AA<<11()HII<<11()HII::d:9DA&q,DA"&,,"4"4T\\"BK*8+,QVQV+<GL  + %WGG[QQT!%d+s4<<01A"3t||#455TT\,3JqMGJqM,-!,TYYq!t_dii1o!N-GJqM 6 2 *#zz//

;|$$# &+3t||+<%=
 &>	 #8=c$,,>O8P Q8P1A8P Q-1 &> &*
F &*\\FN ||++a/ (,J'E (*ww(#f+\9J*J('
 &+4<<+?+?%@' (,DLL,>,>'?<CTCTBU'U'1'='=8k8<8( &))<)<%=
%/!^$4tE*q.<Q7R$R	!'!6!6y!A!L!L!N'1'>'>"3t||#45uS=N7OP( "(!1!1!Q!7!B!B!D'1'>'>)Ndll^;(
 '($(JJ#=b"X !%'F "(!9!9$,,:L:L!M%||55 &&););;  i "p s4<<011A 1k$))AqD/48991   +799 "$00S !RHs   8(W1
 W,1
W1
,*W7,W1
c                B   [         R                  " SS9   [         R                  " U 5      nU S:  nS S S 5        [        U [        5      (       a&  WR
                  R                  5       (       a  SWU'   W$ WR                  5       (       a  SWU'   W$ ! , (       d  f       Ne= f)Nignore)allr   )r   errstatesqrtr,   r   _valuesany)xr   masks      r   zsqrtrY      s    		"1u 
# !\""<<F4L
 M 88::F4LM 
#	"s   B
Bc                (    U SU-  -   nUSU -  -   nX#4$ )Nr    )rA   r#   rD   rE   s       r   r-   r-      s#    q4xAq4xA4Kr   )F)rC   bool)__doc__
__future__r   collectionsr   typingr   numpyr   pandas.core.dtypes.genericr   r   pandas.core.indexes.apir   r@   rY   r-   r[   r   r   <module>rd      s/    5 " #  
 /A1Hr   