U
    MZßfD  ã                   @  sš   d Z ddlm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mZmZ d
ddœdd„Zd
dœdd„Zdd„ Zdd„ ZdS )z;
Boilerplate functions used in defining binary operations.
é    )Úannotations)ÚwrapsN)ÚCallable)Úitem_from_zerodim)Úis_matching_na)ÚF)ÚABCDataFrameÚABCIndexÚ	ABCSeriesÚstrzCallable[[F], F])ÚnameÚreturnc                   s   dddœ‡ fdd„}|S )z§
    Boilerplate for pandas conventions in arithmetic and comparison methods.

    Parameters
    ----------
    name : str

    Returns
    -------
    decorator
    r   )Úmethodr   c                   s
   t | ˆ ƒS ©N)Ú_unpack_zerodim_and_defer)r   ©r   © ú:/tmp/pip-unpacked-wheel-nbcvw55c/pandas/core/ops/common.pyÚwrapper"   s    z)unpack_zerodim_and_defer.<locals>.wrapperr   )r   r   r   r   r   Úunpack_zerodim_and_defer   s    r   r   c                   s^   t jdk r,ddlm}m} |||dƒdƒ}n| d¡ d¡}|dk‰ tˆƒ‡ ‡fdd„ƒ}|S )aM  
    Boilerplate for pandas conventions in arithmetic and comparison methods.

    Ensure method returns NotImplemented when operating against "senior"
    classes.  Ensure zero-dimensional ndarrays are always unpacked.

    Parameters
    ----------
    method : binary method
    name : str

    Returns
    -------
    method
    )é   é	   r   )ÚremoveprefixÚremovesuffixÚ__>   ÚeqÚgeÚgtÚneÚltÚlec                   s\   ˆ rt | tƒrt |tƒrn0tttfD ]$}t | |ƒr6 qJt ||ƒr$t  S q$t|ƒ}ˆ| |ƒS r   )Ú
isinstancer	   r
   r   ÚNotImplementedr   )ÚselfÚotherÚcls©Zis_cmpr   r   r   Ú
new_methodC   s    


z-_unpack_zerodim_and_defer.<locals>.new_method)ÚsysÚversion_infoZpandas.util._str_methodsr   r   r   )r   r   r   r   Zstripped_namer'   r   r&   r   r   (   s    
r   c                 C  s$   t |ttfƒrt| |ƒ}n| j}|S )a  
    Find the appropriate name to pin to an operation result.  This result
    should always be either an Index or a Series.

    Parameters
    ----------
    left : {Series, Index}
    right : object

    Returns
    -------
    name : object
        Usually a string
    )r!   r
   r	   Ú_maybe_match_namer   )ÚleftÚrightr   r   r   r   Úget_op_result_nameV   s    r-   c                 C  s®   t | dƒ}t |dƒ}|r–|r–z4| j|jkr2| jW S t| j|jƒrH| jW S W dS W qª tk
r~   t| j|jƒrx| j Y S Y dS  tk
r’   Y dS X n|r | jS |rª|jS dS )a«  
    Try to find a name to attach to the result of an operation between
    a and b.  If only one of these has a `name` attribute, return that
    name.  Otherwise return a consensus name if they match or None if
    they have different names.

    Parameters
    ----------
    a : object
    b : object

    Returns
    -------
    name : str or None

    See Also
    --------
    pandas.core.common.consensus_name_attr
    r   N)Úhasattrr   r   Ú	TypeErrorÚ
ValueError)ÚaÚbZa_hasZb_hasr   r   r   r*   l   s(    




r*   )Ú__doc__Ú
__future__r   Ú	functoolsr   r(   Útypingr   Zpandas._libs.libr   Zpandas._libs.missingr   Zpandas._typingr   Zpandas.core.dtypes.genericr   r	   r
   r   r   r-   r*   r   r   r   r   Ú<module>   s   .