
    PiE                        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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dS )'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)maybe_unbox_numpy_scalar)
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"d<S )=OpsMixinc                    t           S NNotImplementedselfotherops      i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/arraylike.py_cmp_methodzOpsMixin._cmp_method%           __eq__c                B    |                      |t          j                  S r   )r    operatoreqr   r   s     r   r#   zOpsMixin.__eq__(       x{333r"   __ne__c                B    |                      |t          j                  S r   )r    r%   ner'   s     r   r)   zOpsMixin.__ne__,   r(   r"   __lt__c                B    |                      |t          j                  S r   )r    r%   ltr'   s     r   r,   zOpsMixin.__lt__0   r(   r"   __le__c                B    |                      |t          j                  S r   )r    r%   ler'   s     r   r/   zOpsMixin.__le__4   r(   r"   __gt__c                B    |                      |t          j                  S r   )r    r%   gtr'   s     r   r2   zOpsMixin.__gt__8   r(   r"   __ge__c                B    |                      |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    |                      |t          j                  S r   )r9   r%   and_r'   s     r   r:   zOpsMixin.__and__F   s    ##E8=999r"   __rand__c                B    |                      |t          j                  S r   )r9   r	   rand_r'   s     r   r=   zOpsMixin.__rand__J   s    ##E9?;;;r"   __or__c                B    |                      |t          j                  S r   )r9   r%   or_r'   s     r   r@   zOpsMixin.__or__N       ##E8<888r"   __ror__c                B    |                      |t          j                  S r   )r9   r	   ror_r'   s     r   rD   zOpsMixin.__ror__R       ##E9>:::r"   __xor__c                B    |                      |t          j                  S r   )r9   r%   xorr'   s     r   rH   zOpsMixin.__xor__V   rC   r"   __rxor__c                B    |                      |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    |                      |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
        )rO   r%   r   r'   s     r   rP   zOpsMixin.__add__d   s    t !!%666r"   __radd__c                B    |                      |t          j                  S r   )rO   r	   raddr'   s     r   rR   zOpsMixin.__radd__       !!%888r"   __sub__c                B    |                      |t          j                  S r   )rO   r%   subr'   s     r   rV   zOpsMixin.__sub__       !!%666r"   __rsub__c                B    |                      |t          j                  S r   )rO   r	   rsubr'   s     r   rZ   zOpsMixin.__rsub__   rU   r"   __mul__c                B    |                      |t          j                  S r   )rO   r%   mulr'   s     r   r]   zOpsMixin.__mul__   rY   r"   __rmul__c                B    |                      |t          j                  S r   )rO   r	   rmulr'   s     r   r`   zOpsMixin.__rmul__   rU   r"   __truediv__c                B    |                      |t          j                  S r   )rO   r%   truedivr'   s     r   rc   zOpsMixin.__truediv__   s    !!%)9:::r"   __rtruediv__c                B    |                      |t          j                  S r   )rO   r	   rtruedivr'   s     r   rf   zOpsMixin.__rtruediv__   s    !!%);<<<r"   __floordiv__c                B    |                      |t          j                  S r   )rO   r%   floordivr'   s     r   ri   zOpsMixin.__floordiv__   s    !!%):;;;r"   __rfloordivc                B    |                      |t          j                  S r   )rO   r	   	rfloordivr'   s     r   __rfloordiv__zOpsMixin.__rfloordiv__   s    !!%)<===r"   __mod__c                B    |                      |t          j                  S r   )rO   r%   modr'   s     r   rp   zOpsMixin.__mod__   rY   r"   __rmod__c                B    |                      |t          j                  S r   )rO   r	   rmodr'   s     r   rs   zOpsMixin.__rmod__   rU   r"   
__divmod__c                8    |                      |t                    S r   )rO   divmodr'   s     r   rv   zOpsMixin.__divmod__   s    !!%000r"   __rdivmod__c                B    |                      |t          j                  S r   )rO   r	   rdivmodr'   s     r   ry   zOpsMixin.__rdivmod__   s    !!%):;;;r"   __pow__c                B    |                      |t          j                  S r   )rO   r%   powr'   s     r   r|   zOpsMixin.__pow__   rY   r"   __rpow__c                B    |                      |t          j                  S r   )rO   r	   rpowr'   s     r   r   zOpsMixin.__rpow__   rU   r"   N)#__name__
__module____qualname__r    r   r#   r)   r,   r/   r2   r5   r9   r:   r=   r@   rD   rH   rK   rO   rP   rR   rV   rZ   r]   r`   rc   rf   ri   ro   rp   rs   rv   ry   r|   r    r"   r   r   r   !   s          h''4 4 ('4 h''4 4 ('4 h''4 4 ('4 h''4 4 ('4 h''4 4 ('4 h''4 4 ('4   i((: : )(: j))< < *)< h''9 9 ('9 i((; ; )(; i((9 9 )(9 j)); ; *);   i((Y7 Y7 )(Y7v j))9 9 *)9 i((7 7 )(7 j))9 9 *)9 i((7 7 )(7 j))9 9 *)9 m,,; ; -,; n--= = .-= n--< < .-< m,,> > -,> i((7 7 )(7 j))9 9 *)9 l++1 1 ,+1 m,,< < -,< i((7 7 )(7 j))9 9 *)9 9 9r"   r   ufuncnp.ufuncmethodstrinputsr   kwargsc                    ddl m}m} ddlm ddlm t                     }t          di |}t           g|R i |}|t          ur|S t          j        j        |j        f}	|D ]k}
t          |
d          o|
j         j        k    }t          |
d          o+t          |
          j        |	vot!          |
 j                   }|s|r	t          c S lt%          d |D                       }fdt'          ||d	
          D             t)                    dk    rt+          |          }t)          |          dk    r*||h                    |          rt/          d d           j        }dd         D ]G}t3          t'          ||j        d	
                    D ] \  }\  }}|                    |          ||<   !Ht7          t'           j        |d	
                    t%          fdt'          ||d	
          D                       }n)t7          t'           j         j        d	
                     j        dk    r:d |D             }t)          |          dk    r|                                nd}d|ini fd} fdd|v rt?           g|R i |} ||          S dk    rtA           g|R i |}|t          ur|S  j        dk    rNt)          |          dk    sj!        dk    r0t%          d |D                       } tE                    |i |}n j        dk    r0t%          d |D                       } tE                    |i |}nQdk    r3|s1|d         j#        }|$                    tE                              }ntK          |d         g|R i |} ||          }|S )z
    Compatibility with numpy ufuncs.

    See also
    --------
    numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__
    r   )	DataFrameSeries)NDFrame)BlockManager__array_priority____array_ufunc__c              3  4   K   | ]}t          |          V  d S r   )type.0xs     r   	<genexpr>zarray_ufunc.<locals>.<genexpr>-  s(      **a$q''******r"   c                :    g | ]\  }}t          |          |S r   )
issubclass)r   r   tr   s      r   
<listcomp>zarray_ufunc.<locals>.<listcomp>.  s<       aAw9O9O	  r"   Tstrict   zCannot apply ufunc z& to mixed DataFrame and Series inputs.Nc              3  \   K   | ]&\  }}t          |          r |j        di n|V  'd S )Nr   )r   reindex)r   r   r   r   reconstruct_axess      r   r   zarray_ufunc.<locals>.<genexpr>G  sb       
 
1 .87-C-CJIAI))()))
 
 
 
 
 
r"   c                <    h | ]}t          |d           |j        S )name)hasattrr   r   s     r   	<setcomp>zarray_ufunc.<locals>.<setcomp>O  s)    >>>A71f+=+=>>>>r"   r   c                f    j         dk    rt          fd| D                       S  |           S )Nr   c              3  .   K   | ]} |          V  d S r   r   )r   r   _reconstructs     r   r   z3array_ufunc.<locals>.reconstruct.<locals>.<genexpr>X  s+      99Qa999999r"   )nouttuple)resultr   r   s    r   reconstructz array_ufunc.<locals>.reconstructU  sA    :>>9999&999999|F###r"   c                D   t          j        |           r| S | j        j        k    rdk    rt          | S t	          |           r                    | | j                  } n j        | fi ddi} t                    dk    r| 	                              } | S )Nouter)axescopyFr   )
r   	is_scalarndimNotImplementedError
isinstance_constructor_from_mgrr   _constructorlen__finalize__)r   r   	alignabler   r   reconstruct_kwargsr   s    r   r   z!array_ufunc.<locals>._reconstruct\  s    =   	M;$)##  ))Mfl++ 	//V[/IIFF 'T& *.@ GL  F y>>Q((..Fr"   outreducec              3  >   K   | ]}t          j        |          V  d S r   npasarrayr   s     r   r   zarray_ufunc.<locals>.<genexpr>  s*      55rz!}}555555r"   c              3  8   K   | ]}t          |d           V  dS )T)extract_numpyNr
   r   s     r   r   zarray_ufunc.<locals>.<genexpr>  s/      LL}Qd;;;LLLLLLr"   __call__r   )&pandas.core.framer   r   pandas.core.genericr   pandas.core.internalsr   r   _standardize_out_kwargr   r   r   ndarrayr   r   r   r   _HANDLED_TYPESr   zipr   setissubsetr   r   	enumerateuniondict_AXIS_ORDERSr   popdispatch_ufunc_with_outdispatch_reduction_ufuncr   getattr_mgrapplydefault_array_ufunc)r   r   r   r   r   r   r   clsr   no_deferitemhigher_priorityhas_array_ufunctypes	set_typesr   objiax1ax2namesr   r   mgrr   r   r   r   r   r   s   ```                     @@@@@@r   array_ufuncr     sV           ,+++++222222
t**C#--f--F /tUFVVVVVvVVF^## 	
"H
  " "D.// B'$*AA 	
 D+,, :T

*(::tT%8999 	
  	"o 	"!!!!	" **6*****E   &%555  I 9~~
 JJ	y>>A9f"5">">y"I"I &SeSSS   yQRR= 	) 	)C "+3tSXd+K+K+K!L!L ) ):C))C..Q)  D$5tD I I IJJ 
 
 
 
 
FE$777
 
 
 
 

  D$5ty N N NOOyA~~>>>>>!%jjAoouyy{{{4$d^$ $ $ $ $ $         0 (ufPvPPPPP{6""")$vQQQQ&QQ''M
 y1}}#f++//UZ!^^ 55f55555 ('':6::	aLLVLLLLL''':6::	:		f	 Qin75&1122 %VAYvQQQQ&QQ [  FMr"   returnr   c                     d| vr;d| v r7d| v r3|                      d          }|                      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)r   )r   r   r   r   s       r   r   r     s\     Fv//Ff4D4Dzz&!!zz&!!TluMr"   c                2   |                     d          }|                     dd          } t          ||          |i |}|t          u rt          S t          |t                    rgt          |t                    r t          |          t          |          k    rt          t          ||d          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   whereNTr   r   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66F&%   #u%% 	&SS[[)@)@%%C555 	+ 	+HC#sE****
#u &s88q==a&CC%%#vu%%%Jr"   Nonec                H    |	|| dd<   dS t          j        | ||           dS )zV
    Set a ufunc result into 'out', masking with a 'where' argument if necessary.
    N)r   putmask)r   r   r   s      r   r   r     s4     }AAA

3v&&&&&r"   c                     t           fd|D                       st           fd|D             } t          ||          |i |S )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 V  	d S r   r   r   r   r   s     r   r   z&default_array_ufunc.<locals>.<genexpr>  s'      ))QqDy))))))r"   c                D    g | ]}|ur|nt          j        |          S r   r   r   s     r   r   z'default_array_ufunc.<locals>.<listcomp>  s-    HHHAq}}!!"*Q--HHHr"   )anyr   r   )r   r   r   r   r   
new_inputss   `     r   r   r     sh     ))))&))))) "!!HHHHHHHJ!75&!!:8888r"   c                   |dk    sJ t          |          dk    s
|d         | urt          S |j        t          vrt          S t          |j                 }t	          | |          st          S | j        dk    r#t          | t                    rd|d<   d|vrd|d<    t          | |          dddi|}t          |          }|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   r   method_namer   s          r   r   r     s     X
6{{a6!9D00~...#EN3K 4%% y1}}dJ'' 	+%*F>" F6N (WT;''??u???F%f--FMr"   )r   r   r   r   r   r   r   r   )r   r   )r   r   r   r   )r   r   )__doc__
__future__r   r%   typingr   numpyr   pandas._libsr   pandas._libs.ops_dispatchr   pandas.core.dtypes.castr   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
     s    # " " " " "                  G G G G G G < < < < < < 1 1 1 1 1 1 ! ! ! ! ! ! 2 2 2 2 2 2 ; ; ; ; ; ; 	  Y9 Y9 Y9 Y9 Y9 Y9 Y9 Y9@` ` ` `F          F' ' ' '9 9 9 9 % % % % % %r"   