
    .iE                        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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)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"y<)=OpsMixinc                    t         S NNotImplementedselfotherops      S/var/www/app/trading-bot/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 )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6r"   __radd__c                B    | j                  |t        j                        S r   )rO   r	   raddr'   s     r   rR   zOpsMixin.__radd__       !!%88r"   __sub__c                B    | j                  |t        j                        S r   )rO   r%   subr'   s     r   rV   zOpsMixin.__sub__       !!%66r"   __rsub__c                B    | j                  |t        j                        S r   )rO   r	   rsubr'   s     r   rZ   zOpsMixin.__rsub__   rU   r"   __mul__c                B    | j                  |t        j                        S r   )rO   r%   mulr'   s     r   r]   zOpsMixin.__mul__   rY   r"   __rmul__c                B    | j                  |t        j                        S r   )rO   r	   rmulr'   s     r   r`   zOpsMixin.__rmul__   rU   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__   rY   r"   __rmod__c                B    | j                  |t        j                        S r   )rO   r	   rmodr'   s     r   rs   zOpsMixin.__rmod__   rU   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__   rY   r"   __rpow__c                B    | j                  |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 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(Y7 )Y7v 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}m} ddlm ddl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	      D cg c]  \  }}t)        |      s| c}}t+              d
kD  rt-        |      }t+        |      d
kD  r"||hj/                  |      rt1        d d       j2                  }d
d D ]B  }t5        t'        ||j2                  d	            D ]  \  }\  }}|j7                  |      ||<    D t9        t'         j:                  |d	            t%        fdt'        ||d	      D              }n+t9        t'         j:                   j2                  d	             j<                  d
k(  rK|D ch c]  }t        |d      s|j>                   }}t+        |      d
k(  r|jA                         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              } tI              |i |}nz j<                  d
k(  r%t%        d |D              } tI              |i |}nFdk(  r-|s+|d   jJ                  }|jM                  tI                    }ntO        |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)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   Tstrict   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>G  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>X  s     9Qa9s   )nouttuple)resultr   ufuncs    r   reconstructz array_ufunc.<locals>.reconstructU  s*    ::>9&999F##r"   c                F   t        j                  |       r| S | j                  j                  k7  rdk(  rt        | S t	        |       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   	alignablemethodr   reconstruct_kwargsr   s    r   r   z!array_ufunc.<locals>._reconstruct\  s    == M;;$))# ))Mfl+//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   _standardize_out_kwargr   r   r   ndarrayr   hasattrr   r   _HANDLED_TYPESr   zipr   r   setissubsetr   r   	enumerateuniondict_AXIS_ORDERSr   r   popdispatch_ufunc_with_outdispatch_reduction_ufuncr   getattr_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   s    ```                       @@@@@@r   array_ufuncr     s    ,2
t*C#-f-F /tUFVVVvVF^# 	

""H
  "D./ B''$*A*AA 	
 D+, :T
**(::tT%8%899 	
 o!!" *6**E&%5aAw9OI 9~
 J	y>A9f"5">">y"I &%eW,RS  yyQR= 	)C "+3tSXXd+K!L ):C))C.Q)	)  D$5$5tD IJ 
FE$7
 

  D$5$5tyy NOyyA~!'>A71f+=>>!%jAouyy{4$d^$ 0 (ufPvPP6"")$vQQ&Q'M
 yy1}#f+/UZZ!^ 5f55 (':6:	aLVLL'':6:	:	f Qinn75&12 %VAYvQQ&Q  FMgB ?s   N8%N8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)r   )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              rRt        |t              rt        |      t        |      k7  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6F&% #u%SS[)@%%C5 	+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                \   |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|}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~~..#ENN3K 4%yy1}dJ'%*F>" F6N (WT;'?u??F%f-FMr"   )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.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     sq    #     G < 1 ! 2 ; 	 Y9 Y9@`F F'9 %r"   