
    OwgD                        d Z ddlmZ ddlZddlm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dddZ G 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)
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      L/var/www/horilla/myenv/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__.   r'   r!   __le__c                B    | j                  |t        j                        S r   )r   r$   ler&   s     r   r.   zOpsMixin.__le__2   r'   r!   __gt__c                B    | j                  |t        j                        S r   )r   r$   gtr&   s     r   r1   zOpsMixin.__gt__6   r'   r!   __ge__c                B    | j                  |t        j                        S r   )r   r$   ger&   s     r   r4   zOpsMixin.__ge__:   r'   r!   c                    t         S r   r   r   s      r   _logical_methodzOpsMixin._logical_methodA   r    r!   __and__c                B    | j                  |t        j                        S r   )r8   r$   and_r&   s     r   r9   zOpsMixin.__and__D   s    ##E8==99r!   __rand__c                B    | j                  |t        j                        S r   )r8   r   rand_r&   s     r   r<   zOpsMixin.__rand__H   s    ##E9??;;r!   __or__c                B    | j                  |t        j                        S r   )r8   r$   or_r&   s     r   r?   zOpsMixin.__or__L       ##E8<<88r!   __ror__c                B    | j                  |t        j                        S r   )r8   r   ror_r&   s     r   rC   zOpsMixin.__ror__P       ##E9>>::r!   __xor__c                B    | j                  |t        j                        S r   )r8   r$   xorr&   s     r   rG   zOpsMixin.__xor__T   rB   r!   __rxor__c                B    | j                  |t        j                        S r   )r8   r   rxorr&   s     r   rJ   zOpsMixin.__rxor__X   rF   r!   c                    t         S r   r   r   s      r   _arith_methodzOpsMixin._arith_method_   r    r!   __add__c                B    | j                  |t        j                        S )a/  
        Get Addition of DataFrame and other, column-wise.

        Equivalent to ``DataFrame.add(other)``.

        Parameters
        ----------
        other : scalar, sequence, Series, dict or DataFrame
            Object to be added to the DataFrame.

        Returns
        -------
        DataFrame
            The result of adding ``other`` to DataFrame.

        See Also
        --------
        DataFrame.add : Add a DataFrame and another object, with option for index-
            or column-oriented addition.

        Examples
        --------
        >>> df = pd.DataFrame({'height': [1.5, 2.6], 'weight': [500, 800]},
        ...                   index=['elk', 'moose'])
        >>> df
               height  weight
        elk       1.5     500
        moose     2.6     800

        Adding a scalar affects all rows and columns.

        >>> df[['height', 'weight']] + 1.5
               height  weight
        elk       3.0   501.5
        moose     4.1   801.5

        Each element of a list is added to a column of the DataFrame, in order.

        >>> df[['height', 'weight']] + [0.5, 1.5]
               height  weight
        elk       2.0   501.5
        moose     3.1   801.5

        Keys of a dictionary are aligned to the DataFrame, based on column names;
        each value in the dictionary is added to the corresponding column.

        >>> df[['height', 'weight']] + {'height': 0.5, 'weight': 1.5}
               height  weight
        elk       2.0   501.5
        moose     3.1   801.5

        When `other` is a :class:`Series`, the index of `other` is aligned with the
        columns of the DataFrame.

        >>> s1 = pd.Series([0.5, 1.5], index=['weight', 'height'])
        >>> df[['height', 'weight']] + s1
               height  weight
        elk       3.0   500.5
        moose     4.1   800.5

        Even when the index of `other` is the same as the index of the DataFrame,
        the :class:`Series` will not be reoriented. If index-wise alignment is desired,
        :meth:`DataFrame.add` should be used with `axis='index'`.

        >>> s2 = pd.Series([0.5, 1.5], index=['elk', 'moose'])
        >>> df[['height', 'weight']] + s2
               elk  height  moose  weight
        elk    NaN     NaN    NaN     NaN
        moose  NaN     NaN    NaN     NaN

        >>> df[['height', 'weight']].add(s2, axis='index')
               height  weight
        elk       2.0   500.5
        moose     4.1   801.5

        When `other` is a :class:`DataFrame`, both columns names and the
        index are aligned.

        >>> other = pd.DataFrame({'height': [0.2, 0.4, 0.6]},
        ...                      index=['elk', 'moose', 'deer'])
        >>> df[['height', 'weight']] + other
               height  weight
        deer      NaN     NaN
        elk       1.7     NaN
        moose     3.0     NaN
        )rN   r$   r   r&   s     r   rO   zOpsMixin.__add__b   s    p !!%66r!   __radd__c                B    | j                  |t        j                        S r   )rN   r   raddr&   s     r   rQ   zOpsMixin.__radd__       !!%88r!   __sub__c                B    | j                  |t        j                        S r   )rN   r$   subr&   s     r   rU   zOpsMixin.__sub__       !!%66r!   __rsub__c                B    | j                  |t        j                        S r   )rN   r   rsubr&   s     r   rY   zOpsMixin.__rsub__   rT   r!   __mul__c                B    | j                  |t        j                        S r   )rN   r$   mulr&   s     r   r\   zOpsMixin.__mul__   rX   r!   __rmul__c                B    | j                  |t        j                        S r   )rN   r   rmulr&   s     r   r_   zOpsMixin.__rmul__   rT   r!   __truediv__c                B    | j                  |t        j                        S r   )rN   r$   truedivr&   s     r   rb   zOpsMixin.__truediv__   s    !!%)9)9::r!   __rtruediv__c                B    | j                  |t        j                        S r   )rN   r   rtruedivr&   s     r   re   zOpsMixin.__rtruediv__   s    !!%););<<r!   __floordiv__c                B    | j                  |t        j                        S r   )rN   r$   floordivr&   s     r   rh   zOpsMixin.__floordiv__   s    !!%):):;;r!   __rfloordivc                B    | j                  |t        j                        S r   )rN   r   	rfloordivr&   s     r   __rfloordiv__zOpsMixin.__rfloordiv__   s    !!%)<)<==r!   __mod__c                B    | j                  |t        j                        S r   )rN   r$   modr&   s     r   ro   zOpsMixin.__mod__   rX   r!   __rmod__c                B    | j                  |t        j                        S r   )rN   r   rmodr&   s     r   rr   zOpsMixin.__rmod__   rT   r!   
__divmod__c                .    | j                  |t              S r   )rN   divmodr&   s     r   ru   zOpsMixin.__divmod__   s    !!%00r!   __rdivmod__c                B    | j                  |t        j                        S r   )rN   r   rdivmodr&   s     r   rx   zOpsMixin.__rdivmod__   s    !!%):):;;r!   __pow__c                B    | j                  |t        j                        S r   )rN   r$   powr&   s     r   r{   zOpsMixin.__pow__   rX   r!   __rpow__c                B    | j                  |t        j                        S r   )rN   r   rpowr&   s     r   r~   zOpsMixin.__rpow__   rT   r!   N)#__name__
__module____qualname__r   r   r"   r(   r+   r.   r1   r4   r8   r9   r<   r?   rC   rG   rJ   rN   rO   rQ   rU   rY   r\   r_   rb   re   rh   rn   ro   rr   ru   rx   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(W7 )W7r 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                v     ddl m}m} ddlm ddlmm t               }t        di |}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"||hj1                  |      rt3        d	 d
       j4                  }dd D ]@  }t7        t)        ||j4                              D ]  \  }\  }}|j9                  |      ||<    B t;        t)         j<                  |            t'        fdt)        ||      D              }n)t;        t)         j<                   j4                               j>                  dk(  rI|D cg c]  }t        |d      stA        |d       }}t-        t/        |            dk(  r|d   nd}d|i ni  fd}  fdd|v rtC         g|i |} ||      S dk(  rtE         g|i |}|t        ur|S  j>                  dkD  rBt-        |      dkD  sjF                  dkD  r%t'        d |D              } tA              |i |}nz j>                  dk(  r%t'        d |D              } tA              |i |}nFdk(  r-|s+|d   jH                  }|jK                  tA                    }ntM        |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   )	DataFrameSeries)NDFrame)ArrayManagerBlockManager__array_priority____array_ufunc__c              3  2   K   | ]  }t        |        y wr   )type.0xs     r   	<genexpr>zarray_ufunc.<locals>.<genexpr>,  s     *a$q'*s      zCannot apply ufunc z& 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>D  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>U  s     9Qa9s   )nouttuple)resultr   ufuncs    r   reconstructz array_ufunc.<locals>.reconstructR  s*    ::>9&999F##r!   c                J   t        j                  |       r| S | j                  j                  k7  rdk(  rt        | S t	        | f      rj                  | | j                        } n j                  | fi ddi} t              dk(  r| j                        } | S )Nouter)axescopyFr   )
r   	is_scalarndimNotImplementedError
isinstance_constructor_from_mgrr   _constructorlen__finalize__)r   r   r   	alignablemethodr   reconstruct_kwargsr   s    r   r   z!array_ufunc.<locals>._reconstructY  s    == M;;$))# ))Mf|\:;//V[[/IF 'T&&*.@GLF y>Q((.Fr!   outreducec              3  F   K   | ]  }t        j                  |        y wr   )npasarrayr   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   )'pandas.core.framer   r   pandas.core.genericr   pandas.core.internalsr   r   r   _standardize_out_kwargr   r   r   ndarrayr   hasattrr   r   _HANDLED_TYPESr   zipr   r   setissubsetr   r   	enumerateuniondict_AXIS_ORDERSr   getattrdispatch_ufunc_with_outdispatch_reduction_ufuncr   _mgrapplydefault_array_ufunc)!r   r   r   inputskwargsr   r   clsr   no_deferitemhigher_priorityhas_array_ufunctypesr   r   	set_typesr   objiax1ax2namesr   r   mgrr   r   r   r   r   r   r   s!   ```                       @@@@@@@r   array_ufuncr      s    ,
 t*C#-f-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~
 J	y>A9f"5">">y"I &%eW,RS  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^$ 0 (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Me M> Ks   N0&N0N6N6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   
new_inputss   `      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   numpyr   pandas._libsr   pandas._libs.ops_dispatchr   pandas.core.dtypes.genericr   pandas.corer   pandas.core.constructionr
   pandas.core.ops.commonr   r   r   r   r   r   r   r   r   r   r!   r   <module>r      sn    #     G 1 ! 2 ; 	 W9 W9|bJ F'9 #>r!   