o
    i I                     @  s   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 dZdd Zd-ddZd-ddZd.d"d#Zd/d$d%Zd0d'd(Zd/d)d*Zd/d+d,Z dS )1zn
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                   @  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     t S NNotImplementedselfotherop r   P/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/core/arraylike.py_cmp_method%      zOpsMixin._cmp_method__eq__c                 C     |  |tjS r   )r   operatoreqr   r   r   r   r   r!   (      zOpsMixin.__eq____ne__c                 C  r"   r   )r   r#   ner%   r   r   r   r'   ,   r&   zOpsMixin.__ne____lt__c                 C  r"   r   )r   r#   ltr%   r   r   r   r)   0   r&   zOpsMixin.__lt____le__c                 C  r"   r   )r   r#   ler%   r   r   r   r+   4   r&   zOpsMixin.__le____gt__c                 C  r"   r   )r   r#   gtr%   r   r   r   r-   8   r&   zOpsMixin.__gt____ge__c                 C  r"   r   )r   r#   ger%   r   r   r   r/   <   r&   zOpsMixin.__ge__c                 C  r   r   r   r   r   r   r   _logical_methodC   r    zOpsMixin._logical_method__and__c                 C  r"   r   )r1   r#   and_r%   r   r   r   r2   F   r&   zOpsMixin.__and____rand__c                 C  r"   r   )r1   r   rand_r%   r   r   r   r4   J   r&   zOpsMixin.__rand____or__c                 C  r"   r   )r1   r#   or_r%   r   r   r   r6   N   r&   zOpsMixin.__or____ror__c                 C  r"   r   )r1   r   ror_r%   r   r   r   r8   R   r&   zOpsMixin.__ror____xor__c                 C  r"   r   )r1   r#   xorr%   r   r   r   r:   V   r&   zOpsMixin.__xor____rxor__c                 C  r"   r   )r1   r   rxorr%   r   r   r   r<   Z   r&   zOpsMixin.__rxor__c                 C  r   r   r   r   r   r   r   _arith_methoda   r    zOpsMixin._arith_method__add__c                 C  r"   r   )r>   r#   r   r%   r   r   r   r?   d   r&   zOpsMixin.__add____radd__c                 C  r"   r   )r>   r   raddr%   r   r   r   r@   h   r&   zOpsMixin.__radd____sub__c                 C  r"   r   )r>   r#   subr%   r   r   r   rB   l   r&   zOpsMixin.__sub____rsub__c                 C  r"   r   )r>   r   rsubr%   r   r   r   rD   p   r&   zOpsMixin.__rsub____mul__c                 C  r"   r   )r>   r#   mulr%   r   r   r   rF   t   r&   zOpsMixin.__mul____rmul__c                 C  r"   r   )r>   r   rmulr%   r   r   r   rH   x   r&   zOpsMixin.__rmul____truediv__c                 C  r"   r   )r>   r#   truedivr%   r   r   r   rJ   |   r&   zOpsMixin.__truediv____rtruediv__c                 C  r"   r   )r>   r   rtruedivr%   r   r   r   rL      r&   zOpsMixin.__rtruediv____floordiv__c                 C  r"   r   )r>   r#   floordivr%   r   r   r   rN      r&   zOpsMixin.__floordiv____rfloordivc                 C  r"   r   )r>   r   	rfloordivr%   r   r   r   __rfloordiv__   r&   zOpsMixin.__rfloordiv____mod__c                 C  r"   r   )r>   r#   modr%   r   r   r   rS      r&   zOpsMixin.__mod____rmod__c                 C  r"   r   )r>   r   rmodr%   r   r   r   rU      r&   zOpsMixin.__rmod__
__divmod__c                 C  s   |  |tS r   )r>   divmodr%   r   r   r   rW      s   zOpsMixin.__divmod____rdivmod__c                 C  r"   r   )r>   r   rdivmodr%   r   r   r   rY      r&   zOpsMixin.__rdivmod____pow__c                 C  r"   r   )r>   r#   powr%   r   r   r   r[      r&   zOpsMixin.__pow____rpow__c                 C  r"   r   )r>   r   rpowr%   r   r   r   r]      r&   zOpsMixin.__rpow__N)#__name__
__module____qualname__r   r   r!   r'   r)   r+   r-   r/   r1   r2   r4   r6   r8   r:   r<   r>   r?   r@   rB   rD   rF   rH   rJ   rL   rN   rR   rS   rU   rW   rY   r[   r]   r   r   r   r   r   !   sx    


























r   c                 C  s.   ddl m} t||r| |S | j|jS )zU
    Helper to check if a DataFrame is aligned with another DataFrame or Series.
    r   	DataFrame)pandasrc   
isinstance_indexed_samecolumnsequalsindex)framer   rc   r   r   r   _is_aligned   s   

rk   ufuncnp.ufuncmethodstrinputsr   kwargsc           	        s   ddl m  ddlm tfdd|D }t fdd|D }|dkrz|dkrzt fd	d|D tfd
d|D }|rztjdtt	 d g }|D ]}|u r\|
| qPt|rj|
t| qP|
| qPt| ||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   rb   NDFramec                 3      | ]}t | V  qd S r   re   .0xrr   r   r   	<genexpr>       z"_maybe_fallback.<locals>.<genexpr>c                 3  rt   r   ru   rv   rb   r   r   ry      rz         c                 3  s    | ]
}t | r|V  qd S r   ru   rv   rb   r   r   ry      s    c                 3  s&    | ]}t | rt| V  qd S r   )re   rk   rv   )rs   first_framer   r   ry      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)rd   rc   pandas.core.genericrs   r   nextwarningswarnFutureWarningr   appendre   npasarraygetattrr   )	rl   rn   rp   rq   n_alignablen_framesnon_aligned
new_inputsrx   r   )rc   rs   r}   r   _maybe_fallback   s0   

r   c                   sT  ddl m ddlm  t}tdi |}tg|R i |}|tur)|S tg|R i |}|tur<|S t	j
j|jf}|D ](}t|doQ|jjk}	t|dodt|j|vodt|j }
|	si|
rmt  S qEtdd |D }fdd	t||D td
krtt|d
krtdj}d
d D ]}tt||jD ]\}\}}||||< qqttj|tfddt||D }n	ttjjjd
krdd	 |D }tt|d
kr|d nd}d|ini fdd} fddd|v r%tg|R i |}||S dkr>tg|R i |}|tur>|S jd
kret|d
ksQjd
kretdd |D }t|i |}n?jd
krtdd |D }t|i |}n%dkr|s|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   rr   )BlockManager__array_priority____array_ufunc__c                 s  s    | ]}t |V  qd S r   )typerv   r   r   r   ry   !      zarray_ufunc.<locals>.<genexpr>c                   s   g | ]\}}t | r|qS r   )
issubclassrw   rx   trr   r   r   
<listcomp>"  s    zarray_ufunc.<locals>.<listcomp>r|   z;Cannot apply ufunc {} to mixed DataFrame and Series inputs.Nc                 3  s2    | ]\}}t | r|jdi n|V  qd S )Nr   )r   reindexr   )rs   reconstruct_axesr   r   ry   :  s
    
c                 S  s    g | ]}t |d rt|d qS )name)hasattrr   rv   r   r   r   r   B  s     r   c                   s(   j dkrt fdd| D S  | S )Nr|   c                 3  s    | ]} |V  qd S r   r   rv   )_reconstructr   r   ry   K  r   z3array_ufunc.<locals>.reconstruct.<locals>.<genexpr>)nouttuple)result)r   rl   r   r   reconstructH  s   
z array_ufunc.<locals>.reconstructc                   s   t | r| S | jjkr*dkr(jdkr&d}tj|tt d | S t| S t	|  r=j
| fi ddi} nj
| fi ddi} tdkrW| } | 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   NotImplementedErrorre   _constructorlen__finalize__)r   msg)r   	alignablern   r   reconstruct_kwargsr   rl   r   r   r   O  s6   



z!array_ufunc.<locals>._reconstructoutreducec                 s  s    | ]}t |V  qd S r   r   r   rv   r   r   r   ry     rz   c                 s  s    | ]	}t |d dV  qdS )T)extract_numpyNr	   rv   r   r   r   ry     s    __call__r   )#r   rs   pandas.core.internalsr   r   _standardize_out_kwargr   r   r   r   ndarrayr   r   r   re   _HANDLED_TYPESr   zipr   setr   r   axes	enumerateuniondict_AXIS_ORDERSr   dispatch_ufunc_with_outdispatch_reduction_ufuncr   r   _mgrapplydefault_array_ufunc)r   rl   rn   rp   rq   clsr   no_deferitemhigher_priorityhas_array_ufunctypesr   objiax1ax2namesr   r   mgrr   )	r   rs   r   r   rn   r   r   r   rl   r   array_ufunc   s   






%

&	
r   returnr   c                  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)rq   r   r   r   r   r   r   r     s   

r   c           
      O  s   | d}| dd}t|||i |}|tu rtS t|trAt|tr-t|t|kr/tt||D ]
\}}	t||	| q4|S t|trSt|dkrQ|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   re   r   r   r   r   _assign_where)
r   rl   rn   rp   rq   r   r   r   arrresr   r   r   r     s"   



r   Nonec                 C  s*   |du r|| dd< dS t | || dS )zV
    Set a ufunc result into 'out', masking with a 'where' argument if necessary.
    N)r   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   rv   r   r   r   ry     r   z&default_array_ufunc.<locals>.<genexpr>c                   s"   g | ]}| ur
|nt |qS r   r   rv   r   r   r   r     s   " z'default_array_ufunc.<locals>.<listcomp>)anyr   r   )r   rl   rn   rp   rq   r   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rtS t|j }t| |s'tS | jdkr=t| tr5d|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skipnaNr   )	r   r   r_   REDUCTION_ALIASESr   r   re   r   r   )r   rl   rn   rp   rq   method_namer   r   r   r     s   




r   )rl   rm   rn   ro   rp   r   rq   r   )r   r   )rl   rm   rn   ro   )r   r   )!__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   rk   r   r   r   r   r   r   r   r   r   r   r   <module>   s:     	

> 
2

#
