a
    pÝEbÅH  ã                   @   s"  d 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„ dƒZdd„ Zejeeedœdd„Zejeeedœdd„Zedœdd„Zejedœdd„Zddœdd „Zejedœd!d"„Z ejedœd#d$„Z!dS )%zn
Methods that can be shared by many array-like classes or subclasses:
    Series
    Index
    ExtensionArray
é    N)Ú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                   @   sä  e Zd Zdd„ Zedƒdd„ ƒZedƒdd„ ƒZed	ƒd
d„ ƒZedƒdd„ ƒZedƒdd„ ƒZ	edƒdd„ ƒZ
dd„ Zedƒdd„ ƒZedƒdd„ ƒZedƒdd„ ƒZed ƒd!d"„ ƒZed#ƒd$d%„ ƒZed&ƒd'd(„ ƒZd)d*„ Zed+ƒd,d-„ ƒZed.ƒd/d0„ ƒZed1ƒd2d3„ ƒZed4ƒd5d6„ ƒZed7ƒd8d9„ ƒZed:ƒd;d<„ ƒZed=ƒd>d?„ ƒZed@ƒdAdB„ ƒZedCƒdDdE„ ƒZedFƒdGdH„ ƒZedIƒdJdK„ ƒZedLƒdMdN„ ƒZedOƒdPdQ„ ƒZedRƒdSdT„ ƒZ edUƒdVdW„ ƒZ!edXƒdYdZ„ ƒZ"d[S )\ÚOpsMixinc                 C   s   t S ©N©ÚNotImplemented©ÚselfÚotherÚop© r   úU/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pandas/core/arraylike.pyÚ_cmp_method#   s    zOpsMixin._cmp_methodÚ__eq__c                 C   s   |   |tj¡S r   )r   ÚoperatorÚeq©r   r   r   r   r   r   &   s    zOpsMixin.__eq__Ú__ne__c                 C   s   |   |tj¡S r   )r   r   Úner!   r   r   r   r"   *   s    zOpsMixin.__ne__Ú__lt__c                 C   s   |   |tj¡S r   )r   r   Últr!   r   r   r   r$   .   s    zOpsMixin.__lt__Ú__le__c                 C   s   |   |tj¡S r   )r   r   Úler!   r   r   r   r&   2   s    zOpsMixin.__le__Ú__gt__c                 C   s   |   |tj¡S r   )r   r   Úgtr!   r   r   r   r(   6   s    zOpsMixin.__gt__Ú__ge__c                 C   s   |   |tj¡S r   )r   r   Úger!   r   r   r   r*   :   s    zOpsMixin.__ge__c                 C   s   t S r   r   r   r   r   r   Ú_logical_methodA   s    zOpsMixin._logical_methodÚ__and__c                 C   s   |   |tj¡S r   )r,   r   Úand_r!   r   r   r   r-   D   s    zOpsMixin.__and__Ú__rand__c                 C   s   |   |tj¡S r   )r,   r   Zrand_r!   r   r   r   r/   H   s    zOpsMixin.__rand__Ú__or__c                 C   s   |   |tj¡S r   )r,   r   Úor_r!   r   r   r   r0   L   s    zOpsMixin.__or__Ú__ror__c                 C   s   |   |tj¡S r   )r,   r   Zror_r!   r   r   r   r2   P   s    zOpsMixin.__ror__Ú__xor__c                 C   s   |   |tj¡S r   )r,   r   Úxorr!   r   r   r   r3   T   s    zOpsMixin.__xor__Ú__rxor__c                 C   s   |   |tj¡S r   )r,   r   Zrxorr!   r   r   r   r5   X   s    zOpsMixin.__rxor__c                 C   s   t S r   r   r   r   r   r   Ú_arith_method_   s    zOpsMixin._arith_methodÚ__add__c                 C   s   |   |tj¡S r   )r6   r   r   r!   r   r   r   r7   b   s    zOpsMixin.__add__Ú__radd__c                 C   s   |   |tj¡S r   )r6   r   Zraddr!   r   r   r   r8   f   s    zOpsMixin.__radd__Ú__sub__c                 C   s   |   |tj¡S r   )r6   r   Úsubr!   r   r   r   r9   j   s    zOpsMixin.__sub__Ú__rsub__c                 C   s   |   |tj¡S r   )r6   r   Zrsubr!   r   r   r   r;   n   s    zOpsMixin.__rsub__Ú__mul__c                 C   s   |   |tj¡S r   )r6   r   Úmulr!   r   r   r   r<   r   s    zOpsMixin.__mul__Ú__rmul__c                 C   s   |   |tj¡S r   )r6   r   Zrmulr!   r   r   r   r>   v   s    zOpsMixin.__rmul__Ú__truediv__c                 C   s   |   |tj¡S r   )r6   r   Útruedivr!   r   r   r   r?   z   s    zOpsMixin.__truediv__Ú__rtruediv__c                 C   s   |   |tj¡S r   )r6   r   Zrtruedivr!   r   r   r   rA   ~   s    zOpsMixin.__rtruediv__Ú__floordiv__c                 C   s   |   |tj¡S r   )r6   r   Úfloordivr!   r   r   r   rB   ‚   s    zOpsMixin.__floordiv__Z__rfloordivc                 C   s   |   |tj¡S r   )r6   r   Z	rfloordivr!   r   r   r   Ú__rfloordiv__†   s    zOpsMixin.__rfloordiv__Ú__mod__c                 C   s   |   |tj¡S r   )r6   r   Úmodr!   r   r   r   rE   Š   s    zOpsMixin.__mod__Ú__rmod__c                 C   s   |   |tj¡S r   )r6   r   Zrmodr!   r   r   r   rG   Ž   s    zOpsMixin.__rmod__Ú
__divmod__c                 C   s   |   |t¡S r   )r6   Údivmodr!   r   r   r   rH   ’   s    zOpsMixin.__divmod__Ú__rdivmod__c                 C   s   |   |tj¡S r   )r6   r   Zrdivmodr!   r   r   r   rJ   –   s    zOpsMixin.__rdivmod__Ú__pow__c                 C   s   |   |tj¡S r   )r6   r   Úpowr!   r   r   r   rK   š   s    zOpsMixin.__pow__Ú__rpow__c                 C   s   |   |tj¡S r   )r6   r   Zrpowr!   r   r   r   rM   ž   s    zOpsMixin.__rpow__N)#Ú__name__Ú
__module__Ú__qualname__r   r
   r   r"   r$   r&   r(   r*   r,   r-   r/   r0   r2   r3   r5   r6   r7   r8   r9   r;   r<   r>   r?   rA   rB   rD   rE   rG   rH   rJ   rK   rM   r   r   r   r   r      sv   


























r   c                 C   s2   ddl m} t||ƒr |  |¡S | j |j¡S dS )zU
    Helper to check if a DataFrame is aligned with another DataFrame or Series.
    r   ©Ú	DataFrameN)ÚpandasrR   Ú
isinstanceZ_indexed_sameÚcolumnsÚequalsÚindex)Úframer   rR   r   r   r   Ú_is_aligned§   s    

rY   )ÚufuncÚmethodÚinputsÚkwargsc           	         sø   ddl m‰  ddlm‰ t‡fdd„|D ƒƒ}t‡ fdd„|D ƒƒ}|dkrô|dkrôt‡ fd	d„|D ƒƒ‰t‡‡fd
d„|D ƒƒ}|rôtjdtt	ƒ d� g }|D ]>}|ˆu r¸| 
|¡ q t|ˆƒrÔ| 
t |¡¡ q | 
|¡ q 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   rQ   ©ÚNDFramec                 3   s   | ]}t |ˆ ƒV  qd S r   ©rT   ©Ú.0Úxr^   r   r   Ú	<genexpr>Á   ó    z"_maybe_fallback.<locals>.<genexpr>c                 3   s   | ]}t |ˆ ƒV  qd S r   r`   ra   rQ   r   r   rd   Â   re   é   é   c                 3   s   | ]}t |ˆ ƒr|V  qd S r   r`   ra   rQ   r   r   rd   Ê   re   c                 3   s$   | ]}t |ˆ ƒrtˆ|ƒ V  qd S r   )rT   rY   ra   )r_   Úfirst_framer   r   rd   Í   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)rS   rR   Úpandas.core.genericr_   r   ÚnextÚwarningsÚwarnÚFutureWarningr   ÚappendrT   ÚnpÚasarrayÚgetattrr   )	rZ   r[   r\   r]   Zn_alignableZn_framesZnon_alignedÚ
new_inputsrc   r   )rR   r_   rh   r   Ú_maybe_fallback´   s0    
ÿö
ru   c                    s`  ddl m‰ ddlm‰  tˆƒ}tf i |¤Ž}tˆˆg|¢R i |¤Ž}|turR|S tˆˆˆg|¢R i |¤Ž}|turx|S t	j
j|jf}|D ]P}t|dƒo¢|jˆjk}	t|dƒoÈt|ƒj|voÈt|ˆjƒ }
|	sÒ|
rŠt  S qŠtdd„ |D ƒƒ}‡fdd	„t||ƒD ƒ‰tˆƒd
k�r¬tt|ƒƒd
k�r4td ˆ¡ƒ‚ˆj}ˆd
d… D ]4}tt||jƒƒD ]\}\}}| |¡||< �qZ�qFttˆj|ƒƒ‰t‡‡fdd„t||ƒD ƒƒ}nttˆjˆjƒƒ‰ˆjd
k�r dd	„ |D ƒ}tt|ƒƒd
k�rò|d nd}d|i‰ni ‰‡‡fdd„}‡ ‡‡‡‡‡‡fdd„‰d|v �rVtˆˆˆg|¢R i |¤Ž}||ƒS ˆdk�rˆtˆˆˆg|¢R i |¤Ž}|tu�rˆ|S ˆjd
k�rÖt|ƒd
k�s®ˆjd
k�rÖtdd„ |D ƒƒ}tˆˆƒ|i |¤Ž}n~ˆjd
k�r
tdd„ |D ƒƒ}tˆˆƒ|i |¤Ž}nJˆdk�r6|�s6|d j }| !tˆˆƒ¡}nt"|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   r^   )ÚBlockManagerÚ__array_priority__Ú__array_ufunc__c                 s   s   | ]}t |ƒV  qd S r   )Útypera   r   r   r   rd     re   zarray_ufunc.<locals>.<genexpr>c                    s   g | ]\}}t |ˆ ƒr|‘qS r   )Ú
issubclass©rb   rc   Útr^   r   r   Ú
<listcomp>  re   zarray_ufunc.<locals>.<listcomp>rg   z;Cannot apply ufunc {} to mixed DataFrame and Series inputs.Nc                 3   s0   | ](\}}t |ˆ ƒr$|jf i ˆ¤Žn|V  qd S r   )rz   Zreindexr{   )r_   Úreconstruct_axesr   r   rd   5  s   ÿc                 S   s    g | ]}t |d ƒrt|d ƒ‘qS )Úname)Úhasattrrs   ra   r   r   r   r}   =  re   r   c                    s(   ˆj dkr t‡ fdd„| D ƒƒS ˆ | ƒS )Nrg   c                 3   s   | ]}ˆ |ƒV  qd S r   r   ra   )Ú_reconstructr   r   rd   F  re   z3array_ufunc.<locals>.reconstruct.<locals>.<genexpr>)ÚnoutÚtuple)Úresult)r�   rZ   r   r   ÚreconstructC  s    
z array_ufunc.<locals>.reconstructc                    s²   t  | ¡r| S | jˆjkrTˆdkrPˆjdkrLd}tj| ˆ¡ttƒ d� | S t‚| S t	| ˆ ƒrzˆj
| fi ˆ¤ddi¤Ž} nˆj
| fi ˆ¤ˆ¤ddi¤Ž} tˆƒdkr®|  ˆ¡} | S )NÚouterrf   zãouter 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.ri   ÚcopyFrg   )r   Z	is_scalarÚndimrm   rn   Úformatro   r   ÚNotImplementedErrorrT   Z_constructorÚlenZ__finalize__)r„   Úmsg)rv   Ú	alignabler[   r~   Úreconstruct_kwargsr   rZ   r   r   r�   J  s6    

ÿÿ
ÿÿÿÿ
z!array_ufunc.<locals>._reconstructÚoutÚreducec                 s   s   | ]}t  |¡V  qd S r   ©rq   rr   ra   r   r   r   rd   †  re   c                 s   s   | ]}t |d d�V  qdS )T)Zextract_numpyNr   ra   r   r   r   rd   Œ  re   Ú__call__)#rk   r_   Zpandas.core.internalsrv   ry   Ú_standardize_out_kwargru   r   r   rq   Zndarrayrx   r€   rw   rT   Z_HANDLED_TYPESrƒ   Úzipr‹   ÚsetrŠ   r‰   ÚaxesÚ	enumerateÚunionÚdictZ_AXIS_ORDERSrˆ   Údispatch_ufunc_with_outÚdispatch_reduction_ufuncr‚   rs   Z_mgrÚapplyÚdefault_array_ufunc)r   rZ   r[   r\   r]   Úclsr„   Zno_deferÚitemZhigher_priorityZhas_array_ufuncÚtypesr–   ÚobjÚiZax1Zax2Únamesr   r…   Zmgrr   )	rv   r_   r�   r�   r[   r~   rŽ   r   rZ   r   Úarray_ufuncò   s„    

þ
ÿý
ÿÿþ

%


&	
r¤   )Úreturnc                  K   s@   d| vr<d| v r<d| v r<|   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)Úpop)r]   r¦   r§   r�   r   r   r   r“      s    

r“   )rZ   r[   c           
      O   s¶   |  d¡}|  dd¡}t||ƒ|i |¤Ž}|tu r6tS t|tƒr‚t|tƒrZt|ƒt|ƒkr^t‚t||ƒD ]\}}	t||	|ƒ qh|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�   ÚwhereNrg   r   )	r¨   rs   r   rT   rƒ   r‹   rŠ   r”   Ú_assign_where)
r   rZ   r[   r\   r]   r�   r©   r„   ZarrÚresr   r   r   rš   ¯  s"    



rš   c                 C   s(   |du r|| dd…< nt  | ||¡ dS )zV
    Set a ufunc result into 'out', masking with a 'where' argument if necessary.
    N)rq   Zputmask)r�   r„   r©   r   r   r   rª   Ò  s    rª   c                    s@   t ‡ fdd„|D ƒƒst‚‡ fd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   s   | ]}|ˆ u V  qd S r   r   ra   ©r   r   r   rd   å  re   z&default_array_ufunc.<locals>.<genexpr>c                    s"   g | ]}|ˆ ur|nt  |¡‘qS r   r‘   ra   r¬   r   r   r}   è  re   z'default_array_ufunc.<locals>.<listcomp>)ÚanyrŠ   rs   )r   rZ   r[   r\   r]   rt   r   r¬   r   r�   Ý  s    r�   c                 O   s’   |dksJ ‚t |ƒdks$|d | ur(tS |jtvr6tS t|j }t| |ƒsNtS | jdkrzt| tƒrjd|d< d|vrzd|d< t| |ƒf ddi|¤ŽS )z@
    Dispatch ufunc reductions to self's reduction methods.
    r�   rg   r   FZnumeric_onlyZaxisZskipna)	r‹   r   rN   ÚREDUCTION_ALIASESr€   rˆ   rT   r   rs   )r   rZ   r[   r\   r]   Úmethod_namer   r   r   r›   í  s    




r›   )"Ú__doc__r   Útypingr   rm   Únumpyrq   Zpandas._libsr   Zpandas._libs.ops_dispatchr   Zpandas.util._exceptionsr   Zpandas.core.dtypes.genericr   Zpandas.corer   Zpandas.core.constructionr	   Zpandas.core.ops.commonr
   r®   r   rY   rZ   Ústrru   r¤   r™   r“   rš   rª   r�   r›   r   r   r   r   Ú<module>   s6   ü 	> /#