U
    Mf                     @   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
 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)is_matching_na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-eb6vo0j3/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
    __>   eqlenegtlt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_method7   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_nameK   s    r'   c                 C   s   t | d}t |d}|r|rz4| 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$   a   s(    




r$   N)__doc__	functoolsr   typingr   Zpandas._libs.libr   Zpandas._libs.missingr   Zpandas._typingr   Zpandas.core.dtypes.genericr   r	   r
   strr   r   r'   r$   r   r   r   r   <module>   s   &