U
    fª/et  ã                   @   s„   d 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 eeegef dœdd	„Zed
œdd„Zdd„ Zdd„ ZdS )z;
Boilerplate functions used in defining binary operations.
é    )Úwraps)ÚCallable)Úitem_from_zerodim©ÚF)ÚABCDataFrameÚABCIndexÚ	ABCSeries)ÚnameÚreturnc                    s   t t dœ‡ fdd„}|S )z§
    Boilerplate for pandas conventions in arithmetic and comparison methods.

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

    Returns
    -------
    decorator
    )Úmethodr   c                    s
   t | ˆ ƒS ©N)Ú_unpack_zerodim_and_defer)r   ©r
   © ú:/tmp/pip-unpacked-wheel-tiezk1ph/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(   |  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
    Ú__>   ÚltÚgtÚeqÚleÚneÚgec                    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_method6   s    


z-_unpack_zerodim_and_defer.<locals>.new_method)Ústripr   )r   r
   r!   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_nameJ   s    r&   c                 C   sL   t | dƒ}t |dƒ}|r4|r4| j|jkr.| jS dS n|r>| jS |rH|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
   )ÚaÚbZa_hasZb_hasr   r   r   r#   `   s    

r#   N)Ú__doc__Ú	functoolsr   Útypingr   Zpandas._libs.libr   Zpandas._typingr   Zpandas.core.dtypes.genericr   r   r	   Ústrr   r   r&   r#   r   r   r   r   Ú<module>   s   &