o
    թZhD                     @  s   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 dZd(ddZd)ddZd*dd Zd+d"d#Zd*d$d%Zd*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)
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   L/var/www/html/lang_env/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(   .   r%   zOpsMixin.__lt____le__c                 C  r!   r   )r   r"   ler$   r   r   r   r*   2   r%   zOpsMixin.__le____gt__c                 C  r!   r   )r   r"   gtr$   r   r   r   r,   6   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_methodA   r   zOpsMixin._logical_method__and__c                 C  r!   r   )r0   r"   and_r$   r   r   r   r1   D   r%   zOpsMixin.__and____rand__c                 C  r!   r   )r0   r   Zrand_r$   r   r   r   r3   H   r%   zOpsMixin.__rand____or__c                 C  r!   r   )r0   r"   or_r$   r   r   r   r4   L   r%   zOpsMixin.__or____ror__c                 C  r!   r   )r0   r   Zror_r$   r   r   r   r6   P   r%   zOpsMixin.__ror____xor__c                 C  r!   r   )r0   r"   xorr$   r   r   r   r7   T   r%   zOpsMixin.__xor____rxor__c                 C  r!   r   )r0   r   Zrxorr$   r   r   r   r9   X   r%   zOpsMixin.__rxor__c                 C  r   r   r   r   r   r   r   _arith_method_   r   zOpsMixin._arith_method__add__c                 C  r!   )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
        )r:   r"   r   r$   r   r   r   r;   b   s   XzOpsMixin.__add____radd__c                 C  r!   r   )r:   r   Zraddr$   r   r   r   r<      r%   zOpsMixin.__radd____sub__c                 C  r!   r   )r:   r"   subr$   r   r   r   r=      r%   zOpsMixin.__sub____rsub__c                 C  r!   r   )r:   r   Zrsubr$   r   r   r   r?      r%   zOpsMixin.__rsub____mul__c                 C  r!   r   )r:   r"   mulr$   r   r   r   r@      r%   zOpsMixin.__mul____rmul__c                 C  r!   r   )r:   r   Zrmulr$   r   r   r   rB      r%   zOpsMixin.__rmul____truediv__c                 C  r!   r   )r:   r"   truedivr$   r   r   r   rC      r%   zOpsMixin.__truediv____rtruediv__c                 C  r!   r   )r:   r   Zrtruedivr$   r   r   r   rE      r%   zOpsMixin.__rtruediv____floordiv__c                 C  r!   r   )r:   r"   floordivr$   r   r   r   rF      r%   zOpsMixin.__floordiv__Z__rfloordivc                 C  r!   r   )r:   r   Z	rfloordivr$   r   r   r   __rfloordiv__   r%   zOpsMixin.__rfloordiv____mod__c                 C  r!   r   )r:   r"   modr$   r   r   r   rI      r%   zOpsMixin.__mod____rmod__c                 C  r!   r   )r:   r   Zrmodr$   r   r   r   rK      r%   zOpsMixin.__rmod__
__divmod__c                 C  s   |  |tS r   )r:   divmodr$   r   r   r   rL      s   zOpsMixin.__divmod____rdivmod__c                 C  r!   r   )r:   r   Zrdivmodr$   r   r   r   rN      r%   zOpsMixin.__rdivmod____pow__c                 C  r!   r   )r:   r"   powr$   r   r   r   rO      r%   zOpsMixin.__pow____rpow__c                 C  r!   r   )r:   r   Zrpowr$   r   r   r   rQ      r%   zOpsMixin.__rpow__N)#__name__
__module____qualname__r   r
   r    r&   r(   r*   r,   r.   r0   r1   r3   r4   r6   r7   r9   r:   r;   r<   r=   r?   r@   rB   rC   rE   rF   rH   rI   rK   rL   rN   rO   rQ   r   r   r   r   r      sx    












Y













r   ufuncnp.ufuncmethodstrinputsr   kwargsc                   sX  ddl m}m} ddlm ddlm m t}t	di |}t
	g|R i |}|tur4|S tjj|jf}	|D ](}
t|
doI|
jjk}t|
do\t|
j|	vo\t|
j }|sa|ret  S q=tdd |D }fd	d
t||D tdkrt|}t|dkr||h|rtd	 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rgt|dksS	j!dkrgtdd |D }t"	|i |}n?jdkrt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   )	DataFrameSeriesNDFrame)ArrayManagerBlockManager__array_priority____array_ufunc__c                 s  s    | ]}t |V  qd S r   )type.0xr   r   r   	<genexpr>,      zarray_ufunc.<locals>.<genexpr>c                   s   g | ]\}}t | r|qS r   )
issubclassre   rf   tr]   r   r   
<listcomp>-  s    zarray_ufunc.<locals>.<listcomp>   zCannot apply ufunc z& to mixed DataFrame and Series inputs.Nc                 3  s2    | ]\}}t | r|jdi n|V  qd S )Nr   )ri   Zreindexrj   )r^   reconstruct_axesr   r   rg   D  s
    
c                 S  s    g | ]}t |d rt|d qS )name)hasattrgetattrrd   r   r   r   rl   L  s     ro   c                   s(   j dkrt fdd| D S  | S )Nrm   c                 3  s    | ]} |V  qd S r   r   rd   )_reconstructr   r   rg   U  rh   z3array_ufunc.<locals>.reconstruct.<locals>.<genexpr>)nouttupleresult)rr   rU   r   r   reconstructR  s   
z array_ufunc.<locals>.reconstructc                   s   t | r| S | jjkrdkrt| S t|  fr%j| | jd} nj| fi ddi} tdkr?| 	} | S )Nouter)axescopyFrm   )
r   Z	is_scalarndimNotImplementedError
isinstanceZ_constructor_from_mgrry   Z_constructorlenZ__finalize__ru   )r_   r`   	alignablerW   rn   reconstruct_kwargsr   r   r   rr   Y  s(   

z!array_ufunc.<locals>._reconstructoutreducec                 s  s    | ]}t |V  qd S r   npZasarrayrd   r   r   r   rg     s    c                 s  s    | ]	}t |d dV  qdS )T)Zextract_numpyNr   rd   r   r   r   rg     s    __call__r   )&Zpandas.core.framer[   r\   Zpandas.core.genericr^   Zpandas.core.internalsr_   r`   rc   _standardize_out_kwargr   r   r   Zndarrayrb   rp   ra   r}   Z_HANDLED_TYPESrt   zipr~   setissubsetr|   ry   	enumerateuniondictZ_AXIS_ORDERSr{   dispatch_ufunc_with_outdispatch_reduction_ufuncrs   rq   Z_mgrapplydefault_array_ufunc)r   rU   rW   rY   rZ   r[   r\   clsrv   Zno_deferitemZhigher_priorityZhas_array_ufunctypesZ	set_typesry   objiZax1Zax2namesro   rw   Zmgrr   )
r_   r`   r^   rr   r   rW   rn   r   r   rU   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)rZ   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   whereNrm   r   )	r   rq   r   r}   rt   r~   r|   r   _assign_where)
r   rU   rW   rY   rZ   r   r   rv   Z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   Zputmask)r   rv   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   rd   r   r   r   rg     rh   z&default_array_ufunc.<locals>.<genexpr>c                   s"   g | ]}| ur
|nt |qS r   r   rd   r   r   r   rl     s   " z'default_array_ufunc.<locals>.<listcomp>)anyr|   rq   )r   rU   rW   rY   rZ   Z
new_inputsr   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   rm   r   FZnumeric_onlyZaxisZskipnaNr   )	r~   r   rR   REDUCTION_ALIASESrp   r{   r}   r   rq   )r   rU   rW   rY   rZ   method_namer   r   r   r     s   




r   )rU   rV   rW   rX   rY   r   rZ   r   )r   r   )rU   rV   rW   rX   )r   r   )__doc__
__future__r   r"   typingr   numpyr   Zpandas._libsr   Zpandas._libs.ops_dispatchr   Zpandas.core.dtypes.genericr   Zpandas.corer   Zpandas.core.constructionr	   Zpandas.core.ops.commonr
   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s2     
_ 
&

#
