o
    ŀg                     @  sL   d Z ddlmZ ddlZddlZddlmZ dddZdd
dZ	dd Z
dS )aP  
Missing data handling for arithmetic operations.

In particular, pandas conventions regarding division by zero differ
from numpy in the following ways:
    1) np.array([-1, 0, 1], dtype=dtype1) // np.array([0, 0, 0], dtype=dtype2)
       gives [nan, nan, nan] for most dtype combinations, and [0, 0, 0] for
       the remaining pairs
       (the remaining being dtype1==dtype2==intN and dtype==dtype2==uintN).

       pandas convention is to return [-inf, nan, inf] for all dtype
       combinations.

       Note: the numpy behavior described here is py3-specific.

    2) np.array([-1, 0, 1], dtype=dtype1) % np.array([0, 0, 0], dtype=dtype2)
       gives precisely the same results as the // operation.

       pandas convention is to return [nan, nan, nan] for all dtype
       combinations.

    3) divmod behavior consistent with 1) and 2).
    )annotationsN)	roperatorresult
np.ndarrayc                 C  s   | j jdkr| S t|d}t|tj }|s|s| S |r!t|}|j jdv rF|dk}| rF|t|  @ }| j	ddd} t
| |tj | S )z
    If this is a reversed op, then flip x,y

    If we have an integer value (or array in y)
    and we have 0's, fill them with np.nan,
    return the result.

    Mask the nan's from x.
    fdtypeiur   float64Fcopy)r   kindhasattr
isinstancenpndarrayarrayanyisnanastypeputmasknan)r   xyis_variable_typeis_scalar_typeymaskmask r   K/var/www/html/myenv/lib/python3.10/site-packages/pandas/core/ops/missing.py_fill_zeros!   s   


r   returnc                 C  s   t |ds
t|}t | dst| } |dk}| ri|t|@ }|| @ }| dk }| dk}|| dk@ }||@ ||@ B }	||@ ||@ B }
| sR|	 sR|
 ri|jddd}tj||< tj||
< tj ||	< |S )am  
    Set results of  0 // 0 to np.nan, regardless of the dtypes
    of the numerator or the denominator.

    Parameters
    ----------
    x : ndarray
    y : ndarray
    result : ndarray

    Returns
    -------
    ndarray
        The filled result.

    Examples
    --------
    >>> x = np.array([1, 0, -1], dtype=np.int64)
    >>> x
    array([ 1,  0, -1])
    >>> y = 0       # int 0; numpy behavior is different with float
    >>> result = x // y
    >>> result      # raw numpy result does not fill division by zero
    array([0, 0, 0])
    >>> mask_zero_div_zero(x, y, result)
    array([ inf,  nan, -inf])
    r   r   r	   Fr
   )r   r   r   r   signbitr   r   inf)r   r   r   zmask	zneg_mask	zpos_maskx_lt0x_gt0nan_maskneginf_maskposinf_maskr   r   r   mask_zero_div_zeroG   s&   






r+   c                 C  s   | t u rt|||d t|d ||f}|S | tju r-t|||d t|d ||f}|S | tju r:t|||}|S | tju rGt|||}|S | tju rTt|||}|S | tj	u r_t|||}|S )ab  
    Call _fill_zeros with the appropriate fill value depending on the operation,
    with special logic for divmod and rdivmod.

    Parameters
    ----------
    op : function (operator.add, operator.div, ...)
    left : object (np.ndarray for non-reversed ops)
        We have excluded ExtensionArrays here
    right : object (np.ndarray for reversed ops)
        We have excluded ExtensionArrays here
    result : ndarray

    Returns
    -------
    result : np.ndarray

    Notes
    -----
    For divmod and rdivmod, the `result` parameter and returned `result`
    is a 2-tuple of ndarray objects.
    r      )
divmodr+   r   r   rdivmodoperatorfloordiv	rfloordivmodrmod)opleftrightr   r   r   r   dispatch_fill_zeros   s,   

	


r7   )r   r   )r   r   r    r   )__doc__
__future__r   r/   numpyr   pandas.corer   r   r+   r7   r   r   r   r   <module>   s    

&<