
    Mh                    J    S r SSKJr  SSKrSSKrSSKJr  SS jrS	S jr	S r
g)
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)	roperatorc                   U R                   R                  S:X  a  U $ [        US5      n[        U[        R
                  5      (       + nU(       d	  U(       d  U $ U(       a  [        R                  " U5      nUR                   R                  S;   ai  US:H  nUR                  5       (       aO  U[        R                  " U 5      ) -  nU R                  SSS9n [        R                  " X[        R                  5        U $ )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)resultxyis_variable_typeis_scalar_typeymaskmasks          I/var/www/html/env/lib/python3.13/site-packages/pandas/core/ops/missing.py_fill_zerosr   !   s     ||Cq'*#Arzz22NNHHQKww||tQ99;;BHHV,,,D ]]95]9FJJvRVV,M    c                d   [        US5      (       d  [        R                  " U5      n[        U S5      (       d  [        R                  " U 5      n US:H  nUR                  5       (       a  U[        R                  " U5      -  nX4) -  nU S:  nU S:  nX0S:H  -  nXV-  XG-  -  n	XW-  XF-  -  n
UR                  5       (       d*  U	R                  5       (       d  U
R                  5       (       aG  UR                  SSS9n[        R                  X('   [        R                  X*'   [        R                  * X)'   U$ )a  
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_masks              r   mask_zero_div_zeror,   G   s   : 1gHHQK1gHHQKFEyy{{BJJqM)	J&	AAF# (Y->? (Y->?<<>>[__..+//2C2C]]95]9F!vvF"$&&F#%66'FMr    c                   U [         L a   [        XUS   5      [        US   X5      4nU$ U [        R                  L a   [        X!US   5      [        US   X!5      4nU$ U [
        R                  L a  [        XU5      nU$ U [        R                  L a  [        X!U5      nU$ U [
        R                  L a  [        X1U5      nU$ U [        R                  L a  [        X2U5      nU$ )a  
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   s       r   dispatch_fill_zerosr9      s    . 
V|tF1I6q	4/
* M# 
y  	 uF1I6q	5/
  M 
x  	  $D8 M 
y""	" $E8
 M	 
x||	V51 M 
y~~	VD1Mr    )r   
np.ndarray)r   r:   returnr:   )__doc__
__future__r   r1   numpyr   pandas.corer   r   r,   r9    r    r   <module>rA      s)   . #   !#L9x-r    