
    `Vg I                        d Z ddlmZ ddlZddlmZ ddlZddlZddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ dddddZ G d d      Zd ZddZddZddZddZddZddZddZ y)zn
Methods that can be shared by many array-like classes or subclasses:
    Series
    Index
    ExtensionArray
    )annotationsN)Any)lib)!maybe_dispatch_ufunc_to_dunder_op)find_stack_level)
ABCNDFrame)	roperatorextract_array)unpack_zerodim_and_defermaxminsumprod)maximumminimumaddmultiplyc                  .   e Zd Zd Z ed      d        Z ed      d        Z ed      d        Z ed      d	        Z ed
      d        Z	 ed      d        Z
d Z ed      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d        Z ed      d        Zd Z ed      d        Z ed      d        Z ed       d!        Z ed"      d#        Z ed$      d%        Z ed&      d'        Z ed(      d)        Z ed*      d+        Z ed,      d-        Z ed.      d/        Z ed0      d1        Z ed2      d3        Z ed4      d5        Z ed6      d7        Z  ed8      d9        Z! ed:      d;        Z"y<)=OpsMixinc                    t         S NNotImplementedselfotherops      V/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/arraylike.py_cmp_methodzOpsMixin._cmp_method%           __eq__c                B    | j                  |t        j                        S r   )r    operatoreqr   r   s     r   r#   zOpsMixin.__eq__(       x{{33r"   __ne__c                B    | j                  |t        j                        S r   )r    r%   ner'   s     r   r)   zOpsMixin.__ne__,   r(   r"   __lt__c                B    | j                  |t        j                        S r   )r    r%   ltr'   s     r   r,   zOpsMixin.__lt__0   r(   r"   __le__c                B    | j                  |t        j                        S r   )r    r%   ler'   s     r   r/   zOpsMixin.__le__4   r(   r"   __gt__c                B    | j                  |t        j                        S r   )r    r%   gtr'   s     r   r2   zOpsMixin.__gt__8   r(   r"   __ge__c                B    | j                  |t        j                        S r   )r    r%   ger'   s     r   r5   zOpsMixin.__ge__<   r(   r"   c                    t         S r   r   r   s      r   _logical_methodzOpsMixin._logical_methodC   r!   r"   __and__c                B    | j                  |t        j                        S r   )r9   r%   and_r'   s     r   r:   zOpsMixin.__and__F   s    ##E8==99r"   __rand__c                B    | j                  |t        j                        S r   )r9   r	   rand_r'   s     r   r=   zOpsMixin.__rand__J   s    ##E9??;;r"   __or__c                B    | j                  |t        j                        S r   )r9   r%   or_r'   s     r   r@   zOpsMixin.__or__N       ##E8<<88r"   __ror__c                B    | j                  |t        j                        S r   )r9   r	   ror_r'   s     r   rD   zOpsMixin.__ror__R       ##E9>>::r"   __xor__c                B    | j                  |t        j                        S r   )r9   r%   xorr'   s     r   rH   zOpsMixin.__xor__V   rC   r"   __rxor__c                B    | j                  |t        j                        S r   )r9   r	   rxorr'   s     r   rK   zOpsMixin.__rxor__Z   rG   r"   c                    t         S r   r   r   s      r   _arith_methodzOpsMixin._arith_methoda   r!   r"   __add__c                B    | j                  |t        j                        S r   )rO   r%   r   r'   s     r   rP   zOpsMixin.__add__d       !!%66r"   __radd__c                B    | j                  |t        j                        S r   )rO   r	   raddr'   s     r   rS   zOpsMixin.__radd__h       !!%88r"   __sub__c                B    | j                  |t        j                        S r   )rO   r%   subr'   s     r   rW   zOpsMixin.__sub__l   rR   r"   __rsub__c                B    | j                  |t        j                        S r   )rO   r	   rsubr'   s     r   rZ   zOpsMixin.__rsub__p   rV   r"   __mul__c                B    | j                  |t        j                        S r   )rO   r%   mulr'   s     r   r]   zOpsMixin.__mul__t   rR   r"   __rmul__c                B    | j                  |t        j                        S r   )rO   r	   rmulr'   s     r   r`   zOpsMixin.__rmul__x   rV   r"   __truediv__c                B    | j                  |t        j                        S r   )rO   r%   truedivr'   s     r   rc   zOpsMixin.__truediv__|   s    !!%)9)9::r"   __rtruediv__c                B    | j                  |t        j                        S r   )rO   r	   rtruedivr'   s     r   rf   zOpsMixin.__rtruediv__   s    !!%););<<r"   __floordiv__c                B    | j                  |t        j                        S r   )rO   r%   floordivr'   s     r   ri   zOpsMixin.__floordiv__   s    !!%):):;;r"   __rfloordivc                B    | j                  |t        j                        S r   )rO   r	   	rfloordivr'   s     r   __rfloordiv__zOpsMixin.__rfloordiv__   s    !!%)<)<==r"   __mod__c                B    | j                  |t        j                        S r   )rO   r%   modr'   s     r   rp   zOpsMixin.__mod__   rR   r"   __rmod__c                B    | j                  |t        j                        S r   )rO   r	   rmodr'   s     r   rs   zOpsMixin.__rmod__   rV   r"   
__divmod__c                .    | j                  |t              S r   )rO   divmodr'   s     r   rv   zOpsMixin.__divmod__   s    !!%00r"   __rdivmod__c                B    | j                  |t        j                        S r   )rO   r	   rdivmodr'   s     r   ry   zOpsMixin.__rdivmod__   s    !!%):):;;r"   __pow__c                B    | j                  |t        j                        S r   )rO   r%   powr'   s     r   r|   zOpsMixin.__pow__   rR   r"   __rpow__c                B    | j                  |t        j                        S r   )rO   r	   rpowr'   s     r   r   zOpsMixin.__rpow__   rV   r"   N)#__name__
__module____qualname__r    r   r#   r)   r,   r/   r2   r5   r9   r:   r=   r@   rD   rH   rK   rO   rP   rS   rW   rZ   r]   r`   rc   rf   ri   ro   rp   rs   rv   ry   r|   r    r"   r   r   r   !   s    h'4 (4 h'4 (4 h'4 (4 h'4 (4 h'4 (4 h'4 (4 i(: ): j)< *< h'9 (9 i(; ); i(9 )9 j); *; i(7 )7 j)9 *9 i(7 )7 j)9 *9 i(7 )7 j)9 *9 m,; -; n-= .= n-< .< m,> -> i(7 )7 j)9 *9 l+1 ,1 m,< -< i(7 )7 j)9 *9r"   r   c                    ddl m} t        ||      r| j                  |      S | j                  j                  |j                        S )zU
    Helper to check if a DataFrame is aligned with another DataFrame or Series.
    r   	DataFrame)pandasr   
isinstance_indexed_samecolumnsequalsindex)framer   r   s      r   _is_alignedr      s=     !%#""5)) }}##EKK00r"   c                  	
 ddl m	 ddlm
 t	        
fd|D              }t	        	fd|D              }|dk\  r|dk\  rt        	fd|D              t	        
fd	|D              }|rt        j                  d
t        t                      g }|D ]Z  }|u r|j                  |       t        |
      r%|j                  t        j                  |             J|j                  |       \  t        | |      |i |S t        S )a  
    In the future DataFrame, inputs to ufuncs will be aligned before applying
    the ufunc, but for now we ignore the index but raise a warning if behaviour
    would change in the future.
    This helper detects the case where a warning is needed and then fallbacks
    to applying the ufunc on arrays to avoid alignment.

    See https://github.com/pandas-dev/pandas/pull/39239
    r   r   NDFramec              3  6   K   | ]  }t        |        y wr   r   ).0xr   s     r   	<genexpr>z"_maybe_fallback.<locals>.<genexpr>   s     =jG,=   c              3  6   K   | ]  }t        |        y wr   r   r   r   r   s     r   r   z"_maybe_fallback.<locals>.<genexpr>   s     <:a+<r         c              3  <   K   | ]  }t        |      s|  y wr   r   r   s     r   r   z"_maybe_fallback.<locals>.<genexpr>   s     I
1i0H1Is   c              3  R   K   | ]  }t        |      st        |          y wr   )r   r   )r   r   r   first_frames     r   r   z"_maybe_fallback.<locals>.<genexpr>   s)      
01z!W?UK++
s   ''a  Calling a ufunc on non-aligned DataFrames (or DataFrame/Series combination). Currently, the indices are ignored and the result takes the index/columns of the first DataFrame. In the future , the DataFrames/Series will be aligned before applying the ufunc.
Convert one of the arguments to a NumPy array (eg 'ufunc(df1, np.asarray(df2)') to keep the current behaviour, or align manually (eg 'df1, df2 = df1.align(df2)') before passing to the ufunc to obtain the future behaviour and silence this warning.
stacklevel)r   r   pandas.core.genericr   r   nextwarningswarnFutureWarningr   appendr   npasarraygetattrr   )ufuncmethodinputskwargsn_alignablen_framesnon_aligned
new_inputsr   r   r   r   s            @@@r   _maybe_fallbackr      s    !+=f==K<V<<HaHM IfII  
5;
 

 MMU +- J )#%%a(7+%%bjjm4%%a() *75&):@@@ r"   c                    ddl m ddlm t	               }t        di |}t        g|i |}|t        ur|S t         g|i |}|t        ur|S t        j                  j                  |j                  f}|D ]s  }t        |d      xr |j                   j                  kD  }	t        |d      xr0 t	        |      j                  |vxr t        | j                         }
|	s|
smt        c S  t!        d |D              }t#        ||      D cg c]  \  }}t%        |      s| c}}t'              dkD  rt'        t)        |            dkD  rt+        dj-                               j.                  }dd	 D ]@  }t1        t#        ||j.                              D ]  \  }\  }}|j3                  |      ||<    B t5        t#         j6                  |            t!        fd
t#        ||      D              }n)t5        t#         j6                   j.                               j8                  dk(  rI|D cg c]  }t        |d      st;        |d       }}t'        t)        |            dk(  r|d   nd	}d|ini fd} fdd|v rt=         g|i |} ||      S dk(  rt?         g|i |}|t        ur|S  j8                  dkD  rBt'        |      dkD  sj@                  dkD  r%t!        d |D              } t;              |i |}nz j8                  dk(  r%t!        d |D              } t;              |i |}nFdk(  r-|s+|d   jB                  }|jE                  t;                    }ntG        |d   g|i |} ||      }|S c c}}w c c}w )z
    Compatibility with numpy ufuncs.

    See also
    --------
    numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__
    r   r   )BlockManager__array_priority____array_ufunc__c              3  2   K   | ]  }t        |        y wr   )typer   r   s     r   r   zarray_ufunc.<locals>.<genexpr>!  s     *a$q'*s   r   z;Cannot apply ufunc {} to mixed DataFrame and Series inputs.Nc              3  d   K   | ]'  \  }}t        |      r |j                  di n| ) y w)Nr   )
issubclassreindex)r   r   tr   reconstruct_axess      r   r   zarray_ufunc.<locals>.<genexpr>:  s:      
1 .87-CIAII)()J
s   -0namec                Z    j                   dkD  rt        fd| D              S  |       S )Nr   c              3  .   K   | ]  } |        y wr   r   )r   r   _reconstructs     r   r   z3array_ufunc.<locals>.reconstruct.<locals>.<genexpr>K  s     9Qa9s   )nouttuple)resultr   r   s    r   reconstructz array_ufunc.<locals>.reconstructH  s*    ::>9&999F##r"   c                   t        j                  |       r| S | j                  j                  k7  rSdk(  rLj                  dk(  r7d}t        j                  |j                        t        t                      | S t        | S t        |       r j                  | fi ddi} n j                  | fi ddi} t              dk(  r| j                        } | S )Nouterr   zouter method for ufunc {} is not implemented on pandas objects. Returning an ndarray, but in the future this will raise a 'NotImplementedError'. Consider explicitly converting the DataFrame to an array with '.to_numpy()' first.r   copyFr   )r   	is_scalarndimr   r   formatr   r   NotImplementedErrorr   _constructorlen__finalize__)	r   msgr   	alignabler   r   reconstruct_kwargsr   r   s	     r   r   z!array_ufunc.<locals>._reconstructO  s    == M;;$))# 99>@  MM

5)=EUEW "M))Mfl+&T&&vP1CP%PF 'T&&*.@GLF y>Q((.Fr"   outreducec              3  F   K   | ]  }t        j                  |        y wr   )r   r   r   s     r   r   zarray_ufunc.<locals>.<genexpr>  s     5rzz!}5s   !c              3  6   K   | ]  }t        |d         yw)T)extract_numpyNr
   r   s     r   r   zarray_ufunc.<locals>.<genexpr>  s     L}Qd;;Ls   __call__r   )$r   r   pandas.core.internalsr   r   _standardize_out_kwargr   r   r   r   ndarrayr   hasattrr   r   _HANDLED_TYPESr   zipr   r   setr   r   axes	enumerateuniondict_AXIS_ORDERSr   r   dispatch_ufunc_with_outdispatch_reduction_ufuncr   _mgrapplydefault_array_ufunc)r   r   r   r   r   clsr   no_deferitemhigher_priorityhas_array_ufunctypesr   r   r   objiax1ax2namesr   r   mgrr   r   r   r   r   r   s   ```                    @@@@@@r   array_ufuncr      s    ,2
t*C#-f-F UF>V>v>F^# /tUFVVVvVF^# 	

""H
  "D./ B''$*A*AA 	
 D+, :T
**(::tT%8%899 	
 o!!" *6**E"651Ltq!Z75KLI
9~ s5z?Q & &-  yyQR= 	)C "+3tSXX+>!? ):C))C.Q)	)  D$5$5t <= 
FE*
 

  D$5$5tyy AByyA~-3Jwq&7IF#JJs5z?a/uQxT$d^$# #J (ufPvPP6"")$vQQ&Q'M
 yy1}#f+/UZZ!^ 5f55 (':6:	aLVLL'':6: Z )..CYYwuf56F )E6UFUfUF  FMA M@ Ks    N55N5N;N;c                 t    d| vr3d| v r/d| v r+| j                  d      }| j                  d      }||f}|| d<   | S )z
    If kwargs contain "out1" and "out2", replace that with a tuple "out"

    np.divmod, np.modf, np.frexp can have either `out=(out1, out2)` or
    `out1=out1, out2=out2)`
    r   out1out2)pop)r   r   r   r   s       r   r   r     sM     Fv/Ff4Dzz&!zz&!TluMr"   c                   |j                  d      }|j                  dd      } t        ||      |i |}|t        u rt        S t        |t              rPt        |t              rt        |      t        |      k7  rt        t        ||      D ]  \  }}	t        ||	|        |S t        |t              rt        |      dk(  r|d   }nt        t        |||       |S )zz
    If we have an `out` keyword, then call the ufunc without `out` and then
    set the result into the given `out`.
    r   whereNr   r   )	r   r   r   r   r   r   r   r   _assign_where)
r   r   r   r   r   r   r   r   arrress
             r   r   r     s     **U
CJJw%E#WUF#V6v6F&% #u%SS[)@%%C( 	+HC#sE*	+ 
#us8q=a&C%%#vu%Jr"   c                B    ||| dd yt        j                  | ||       y)zV
    Set a ufunc result into 'out', masking with a 'where' argument if necessary.
    N)r   putmask)r   r   r   s      r   r   r     s"     }A


3v&r"   c                     t         fd|D              st        |D cg c]  }| ur|nt        j                  |       }} t	        ||      |i |S c c}w )z
    Fallback to the behavior we would get if we did not define __array_ufunc__.

    Notes
    -----
    We are assuming that `self` is among `inputs`.
    c              3  &   K   | ]  }|u  
 y wr   r   )r   r   r   s     r   r   z&default_array_ufunc.<locals>.<genexpr>  s     )QqDy)s   )anyr   r   r   r   )r   r   r   r   r   r   r   s   `      r   r   r     s^     )&))!!AGHAq}!"**Q-7HJH!75&!:888 Is   "Ac                B   |dk(  sJ t        |      dk7  s|d   | urt        S |j                  t        vrt        S t        |j                     }t	        | |      st        S | j
                  dkD  rt        | t              rd|d<   d|vrd|d<    t        | |      dddi|S )	z@
    Dispatch ufunc reductions to self's reduction methods.
    r   r   r   Fnumeric_onlyaxisskipnar   )	r   r   r   REDUCTION_ALIASESr   r   r   r   r   )r   r   r   r   r   method_names         r   r   r     s     X
6{a6!9D0~~..#ENN3K 4%yy1}dJ'%*F>" F6N &74%=U=f==r"   )r   np.ufuncr   strr   r   r   r   )returnr   )r   r  r   r  )r  None)!__doc__
__future__r   r%   typingr   r   numpyr   pandas._libsr   pandas._libs.ops_dispatchr   pandas.util._exceptionsr   pandas.core.dtypes.genericr   pandas.corer	   pandas.core.constructionr   pandas.core.ops.commonr   r  r   r   r   r   r   r   r   r   r   r   r"   r   <module>r     s    #      G 4 1 ! 2 ; 	 A9 A9P
1;|nb F'9 #>r"   