a
    Oªf¬  ã                   @  s–   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ erdddl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)Úwraps)ÚTYPE_CHECKINGÚCallable)Úitem_from_zerodim)Úis_matching_na)ÚABCIndexÚ	ABCSeries)ÚFÚ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   © úO/var/www/ai-form-bot/venv/lib/python3.9/site-packages/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                   s2   |  d¡ d¡}|dv ‰ 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
    Ú__>   ÚgtÚleÚltÚneÚeqÚgec                   sN   ˆ rt | tƒrt |tƒrn"t|dd ƒ}|d ur<|| jkr<tS t|ƒ}ˆ| |ƒS )NÚ__pandas_priority__)Ú
isinstancer   r	   Úgetattrr   ÚNotImplementedr   )ÚselfÚotherÚprio©Zis_cmpr   r   r   Ú
new_method>   s    
z-_unpack_zerodim_and_defer.<locals>.new_method)ÚremoveprefixÚremovesuffixr   )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_nameQ   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y|   t| j|jƒrv| j Y S Y dS  tyŽ   Y dS 0 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'   g   s(    




r'   N)Ú__doc__Ú
__future__r   Ú	functoolsr   Útypingr   r   Zpandas._libs.libr   Zpandas._libs.missingr   Zpandas.core.dtypes.genericr   r	   Zpandas._typingr
   r   r   r*   r'   r   r   r   r   Ú<module>   s   &