o
    d                     @  s  d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	Z	d dl
Zd dlmZ d dlmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZ d dlmZ d dlm Z  d d	l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d d
l0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7 edddZ8e8duZ9da:ddddZ;e;ed G dd dZ<G dd dZ=dd!d"Z>dd#d$Z?	ddd'd(Z@dd.d/ZA			ddd4d5ZBdd6d7ZCddd9d:ZDdd=d>ZEddBdCZFddDdEZGddddFddGdHZHddddFddIdJZIe<dKeEeGddd ddLddPdQZJddWdXZKe<e1e= eEddddFddYdZZLe= ddddFdd[d\ZMddadbZNeOejPfddgdhZQe=didjdddiddkddldmZRe<dKdne=didjdddiddkddodpZSe<dKdndddiddkddqdrZTdsdt ZUeUdudvdwZVeUdxdydwZWe<dzddddFdd|d}ZXe<dzddddFdd~dZYe<dKdneGddddFdddZZe<dKdneGddddFdddZ[e<dKdneGddd ddLdddZ\dddZ]eOejPfdddZ^	iddddZ_dddZ`dd Zae<dKdnddddddZbdddZce<dKdnddiddddZddd Zedd ZfefejgZhefejiZjefejkZlefejmZnefejoZpefejqZrdddZsdS )    )annotationsN)AnyCallablecast)
get_option)NaTNaTTypeiNaTlib)		ArrayLikeAxisIntCorrelationMethodDtypeDtypeObjFScalarShapenpt)import_optional_dependency)find_stack_level)is_any_int_dtypeis_bool_dtype
is_complexis_datetime64_any_dtypeis_floatis_float_dtype
is_integeris_integer_dtypeis_numeric_dtypeis_object_dtype	is_scalaris_timedelta64_dtypeneeds_i8_conversionpandas_dtype)PeriodDtype)isnana_value_for_dtypenotna)extract_array
bottleneckwarn)errorsFTvboolreturnNonec                 C  s   t r| ad S d S N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)r,    r3   W/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/core/nanops.pyset_use_bottleneckC   s   r5   zcompute.use_bottleneckc                      s2   e Zd Zd fddZddd	ZdddZ  ZS )disallowdtypesr   r.   r/   c                   s"   t    tdd |D | _d S )Nc                 s  s    | ]}t |jV  qd S r0   )r#   type).0dtyper3   r3   r4   	<genexpr>P       z$disallow.__init__.<locals>.<genexpr>)super__init__tupler7   )selfr7   	__class__r3   r4   r>   N   s   
zdisallow.__init__r-   c                 C  s   t |dot|jj| jS )Nr:   )hasattr
issubclassr:   r8   r7   )r@   objr3   r3   r4   checkR   s   zdisallow.checkfr   c                   s"   t   fdd}tt|S )Nc               
     s   t | | }tfdd|D r" jdd}td| dz!tjdd  | i |W  d    W S 1 s<w   Y  W d S  t	y[ } zt
| d	 rVt|| d }~ww )
Nc                 3  s    | ]}  |V  qd S r0   )rF   )r9   rE   )r@   r3   r4   r;   Y   r<   z0disallow.__call__.<locals>._f.<locals>.<genexpr>nan zreduction operation 'z' not allowed for this dtypeignoreinvalidr   )	itertoolschainvaluesany__name__replace	TypeErrornperrstate
ValueErrorr   )argskwargsobj_iterf_nameerG   r@   r3   r4   _fV   s    
(
zdisallow.__call__.<locals>._f	functoolswrapsr   r   )r@   rG   r]   r3   r\   r4   __call__U   s   
zdisallow.__call__)r7   r   r.   r/   r.   r-   )rG   r   r.   r   )rQ   
__module____qualname__r>   rF   ra   __classcell__r3   r3   rA   r4   r6   M   s    
r6   c                   @  s"   e Zd Zd
dddZddd	ZdS )bottleneck_switchNr.   r/   c                 K  s   || _ || _d S r0   )namerX   )r@   rg   rX   r3   r3   r4   r>   n   s   
zbottleneck_switch.__init__altr   c              	     sf   j p jzttW n ttfy   d Y nw t d ddd fd	d
}tt	|S )NTaxisskipnarO   
np.ndarrayrj   AxisInt | Nonerk   r-   c                  s   t jdkrj D ]\}}||vr|||< q| jdkr*|dd u r*t| |S trj|rjt| jrj|dd d u r]|	dd  | fd|i|}t
|r[ | f||d|}|S  | f||d|}|S  | f||d|}|S )Nr   	min_countmaskrj   ri   )lenrX   itemssizeget_na_for_min_countr2   _bn_ok_dtyper:   pop	_has_infs)rO   rj   rk   kwdskr,   resultrh   bn_funcbn_namer@   r3   r4   rG   z   s$   
z%bottleneck_switch.__call__.<locals>.f)rO   rl   rj   rm   rk   r-   )
rg   rQ   getattrbnAttributeError	NameErrorr_   r`   r   r   )r@   rh   rG   r3   r{   r4   ra   r   s   
'zbottleneck_switch.__call__r0   )r.   r/   )rh   r   r.   r   )rQ   rc   rd   r>   ra   r3   r3   r3   r4   rf   m   s    rf   r:   r   rg   strc                 C  s   t | st| s|dvS dS )N)nansumnanprodnanmeanF)r   r"   )r:   rg   r3   r3   r4   ru      s   ru   c              	   C  sP   t | tjr| jdv rt| dS zt|  W S  t	t
fy'   Y dS w )N)f8f4KF)
isinstancerT   ndarrayr:   r
   has_infsravelisinfrP   rS   NotImplementedError)rz   r3   r3   r4   rw      s   
rw   
fill_valueScalar | Nonec                 C  sJ   |dur|S t | r|du rtjS |dkrtjS tj S |dkr#tjS tS )z9return the correct fill value for the dtype of the valuesN+inf)_na_ok_dtyperT   rH   infr
   i8maxr	   )r:   r   fill_value_typr3   r3   r4   _get_fill_value   s   r   rO   rl   rk   ro   npt.NDArray[np.bool_] | Nonec                 C  s:   |du rt | jst| jrdS |st| jrt| }|S )a  
    Compute a mask if and only if necessary.

    This function will compute a mask iff it is necessary. Otherwise,
    return the provided mask (potentially None) when a mask does not need to be
    computed.

    A mask is never necessary if the values array is of boolean or integer
    dtypes, as these are incapable of storing NaNs. If passing a NaN-capable
    dtype that is interpretable as either boolean or integer data (eg,
    timedelta64), a mask must be provided.

    If the skipna parameter is False, a new mask will not be computed.

    The mask is computed using isna() by default. Setting invert=True selects
    notna() as the masking function.

    Parameters
    ----------
    values : ndarray
        input array to potentially compute mask for
    skipna : bool
        boolean for whether NaNs should be skipped
    mask : Optional[ndarray]
        nan-mask if known

    Returns
    -------
    Optional[np.ndarray[bool]]
    N)r   r:   r   r"   r%   )rO   rk   ro   r3   r3   r4   _maybe_get_mask   s   !r   r   r   
str | NoneHtuple[np.ndarray, npt.NDArray[np.bool_] | None, np.dtype, np.dtype, Any]c           	      C  s   t |sJ t| dd} t| ||}| j}d}t| jr&t| d} d}t|}t	|||d}|rW|durW|durW|
 rW|sC|rO|  } t| || nt| | |} |}t|sat|rhttj}n
t|rrttj}| ||||fS )a7  
    Utility to get the values view, mask, dtype, dtype_max, and fill_value.

    If both mask and fill_value/fill_value_typ are not None and skipna is True,
    the values array will be copied.

    For input arrays of boolean or integer dtypes, copies will only occur if a
    precomputed mask, a fill_value/fill_value_typ, and skipna=True are
    provided.

    Parameters
    ----------
    values : ndarray
        input array to potentially compute mask for
    skipna : bool
        boolean for whether NaNs should be skipped
    fill_value : Any
        value to fill NaNs with
    fill_value_typ : str
        Set to '+inf' or '-inf' to handle dtype-specific infinities
    mask : Optional[np.ndarray[bool]]
        nan-mask if known

    Returns
    -------
    values : ndarray
        Potential copy of input value array
    mask : Optional[ndarray[bool]]
        Mask for values, if deemed necessary to compute
    dtype : np.dtype
        dtype for values
    dtype_max : np.dtype
        platform independent dtype
    fill_value : Any
        fill value used
    Textract_numpyFi8)r   r   N)r    r(   r   r:   r"   rT   asarrayviewr   r   rP   copyputmaskwherer   r   int64r   float64)	rO   rk   r   r   ro   r:   datetimelikedtype_ok	dtype_maxr3   r3   r4   _get_values  s0   .
r   c                 C  s   t | rdS t| jtj S )NF)r"   rD   r8   rT   integerr:   r3   r3   r4   r   a  s   r   np.dtypec                 C  s  | t u r	 | S t|rL|du rt}t| tjsEt|rJ d| |kr&tj} t| r4tdd	|} nt
| |} | j	|dd} | S | 	|} | S t|rt| tjs| |ks_t| ritd	|} | S t| tjkrutdt
| j	|dd} | S | 	d|} | S )	zwrap our results if neededNzExpected non-null fill_valuer   nsFr   zoverflow in timedelta operationm8[ns])r   r   r	   r   rT   r   r%   rH   
datetime64astyper   r   r!   isnantimedelta64fabsr
   r   rV   )rz   r:   r   r3   r3   r4   _wrap_resultsg  s8   #
r   funcr   c                   s,   t  ddddd fdd}tt|S )z
    If we have datetime64 or timedelta64 values, ensure we have a correct
    mask before calling the wrapped function, then cast back afterwards.
    NTrj   rk   ro   rO   rl   rj   rm   rk   r-   ro   r   c                  sr   | }| j jdv }|r|d u rt| } | f|||d|}|r7t||j td}|s7|d us0J t||||}|S )NmMr   )r   )r:   kindr%   r   r	   _mask_datetimelike_result)rO   rj   rk   ro   rX   orig_valuesr   rz   r   r3   r4   new_func  s   	z&_datetimelike_compat.<locals>.new_func)rO   rl   rj   rm   rk   r-   ro   r   r^   )r   r   r3   r   r4   _datetimelike_compat  s   
r   rj   rm   Scalar | np.ndarrayc                 C  sh   t | r	| d} t| j}| jdkr|S |du r|S | jd| | j|d d  }tj||| jdS )a  
    Return the missing value for `values`.

    Parameters
    ----------
    values : ndarray
    axis : int or None
        axis for the reduction, required if values.ndim > 1.

    Returns
    -------
    result : scalar or ndarray
        For 1-D values, returns a scalar of the correct missing type.
        For 2-D values, returns a 1-D array where each element is missing.
    r      Nr   )r   r   r&   r:   ndimshaperT   full)rO   rj   r   result_shaper3   r3   r4   rt     s   


 rt   c                   s(   t  ddd	 fdd}tt|S )
z
    NumPy operations on C-contiguous ndarrays with axis=1 can be
    very slow if axis 1 >> axis 0.
    Operate row-by-row and concatenate the results.
    Nrj   rO   rl   rj   rm   c                  s   |dkrT| j dkrT| jd rT| jd d | jd krT| jtkrT| jtkrTt|  dd urEd fddt	t
 D }n
fd	d D }t|S | fd
|iS )Nr      C_CONTIGUOUSi  r   ro   c                   s(   g | ]} | fd | iqS ro   r3   )r9   i)arrsr   rX   ro   r3   r4   
<listcomp>  s    z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>c                   s   g | ]
} |fi qS r3   r3   )r9   x)r   rX   r3   r4   r     s    rj   )r   flagsr   r:   objectr-   listrs   rv   rangerp   rT   array)rO   rj   rX   resultsr   )r   rX   ro   r4   newfunc  s*   



z&maybe_operate_rowwise.<locals>.newfunc)rO   rl   rj   rm   r^   )r   r   r3   r   r4   maybe_operate_rowwise  s   
r   r   c                C  ^   t | jr| jjdkrtjdtt d t| |d|d\} }}}}t| r*| 	t
} | |S )a  
    Check if any elements along an axis evaluate to True.

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : bool

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2])
    >>> nanops.nanany(s)
    True

    >>> from pandas.core import nanops
    >>> s = pd.Series([np.nan])
    >>> nanops.nanany(s)
    False
    r   zz'any' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).any() instead.
stacklevelFr   ro   )r"   r:   r   warningsr*   FutureWarningr   r   r   r   r-   rP   rO   rj   rk   ro   _r3   r3   r4   nanany     "

r   c                C  r   )a  
    Check if all elements along an axis evaluate to True.

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : bool

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanall(s)
    True

    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 0])
    >>> nanops.nanall(s)
    False
    r   zz'all' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).all() instead.r   Tr   )r"   r:   r   r   r*   r   r   r   r   r   r-   allr   r3   r3   r4   nanall*  r   r   M8)rj   rk   rn   ro   rn   intfloatc          
      C  sf   t | |d|d\} }}}}|}t|r|}n
t|r ttj}| j||d}	t|	||| j|d}	|	S )a  
    Sum the elements along an axis ignoring NaNs

    Parameters
    ----------
    values : ndarray[dtype]
    axis : int, optional
    skipna : bool, default True
    min_count: int, default 0
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : dtype

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nansum(s)
    3.0
    r   r   r   rn   )	r   r   r!   rT   r:   r   sum_maybe_null_outr   )
rO   rj   rk   rn   ro   r:   r   r   	dtype_sumthe_sumr3   r3   r4   r   a  s   "r   rz   +np.ndarray | np.datetime64 | np.timedelta64npt.NDArray[np.bool_]r   5np.ndarray | np.datetime64 | np.timedelta64 | NaTTypec                 C  sT   t | tjr| d|j} |j|d}t| |< | S | r(tt|jS | S )Nr   r   )	r   rT   r   r   r   r:   rP   r	   r   )rz   rj   ro   r   	axis_maskr3   r3   r4   r     s   r   c                C  s  t | |d|d\} }}}}|}ttj}|jdv r!ttj}nt|r,ttj}nt|r4|}|}t| j|||d}	t	| j
||d}
|durt|
ddrttj|	}	tjdd	 |
|	 }W d   n1 skw   Y  |	dk}| r}tj||< |S |	dkr|
|	 ntj}|S )
a  
    Compute the mean of the element along an axis ignoring NaNs

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    float
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanmean(s)
    1.5
    r   r   r   r   Nr   FrJ   r   )r   rT   r:   r   r   r   r   _get_countsr   _ensure_numericr   r~   r   r   rU   rP   rH   )rO   rj   rk   ro   r:   r   r   r   dtype_countcountr   the_meanct_maskr3   r3   r4   r     s2   "


r   c          
   
     s"  d
 fdd	}t |  |dd\} }}}}t| js4z| d} W n ty3 } ztt||d}~ww |dur=tj| |< | j	}| j
dkr|dur|rw sUt||| }	n7t  tdd	t t| |}	W d   n1 sqw   Y  nt| j|tjtj}	n
|r|| |ntj}	t|	|S )a  
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 2])
    >>> nanops.nanmedian(s)
    2.0
    Nc                   st   |d u r	t | }n| } s| stjS t  tddt t| | }W d    |S 1 s3w   Y  |S )NrJ   All-NaN slice encountered)	r'   r   rT   rH   r   catch_warningsfilterwarningsRuntimeWarning	nanmedian)r   _maskresrk   r3   r4   
get_median   s   


znanmedian.<locals>.get_medianr   )ro   r   r   r   rJ   r   r0   )r   r   r:   r   rV   rS   r   rT   rH   rr   r   apply_along_axisr   r   r   r   r   get_empty_reduction_resultr   float_r   )
rO   rj   rk   ro   r   r:   r   errnotemptyr   r3   r   r4   r     s4   



r   r   tuple[int, ...]r   np.dtype | type[np.floating]c                 C  s<   t | }t t| }t j|||k |d}|| |S )z
    The result from a reduction on an empty ndarray.

    Parameters
    ----------
    shape : Tuple[int]
    axis : int
    dtype : np.dtype
    fill_value : Any

    Returns
    -------
    np.ndarray
    r   )rT   r   arangerp   emptyfill)r   rj   r:   r   shpdimsretr3   r3   r4   r   8  s
   

r   values_shaper   ddof-tuple[float | np.ndarray, float | np.ndarray]c                 C  s   t | |||d}||| }t|r!||krtj}tj}||fS ttj|}||k}| r?t||tj t||tj ||fS )a:  
    Get the count of non-null values along an axis, accounting
    for degrees of freedom.

    Parameters
    ----------
    values_shape : Tuple[int, ...]
        shape tuple from values ndarray, used if mask is None
    mask : Optional[ndarray[bool]]
        locations in values that should be considered missing
    axis : Optional[int]
        axis to count along
    ddof : int
        degrees of freedom
    dtype : type, optional
        type to use for count

    Returns
    -------
    count : int, np.nan or np.ndarray
    d : int, np.nan or np.ndarray
    r   )	r   r8   r    rT   rH   r   r   rP   r   )r  ro   rj   r  r:   r   dr3   r3   r4   _get_counts_nanvarS  s   r  r   r  rj   rk   r  ro   c             	   C  sT   | j dkr
| d} | j }t| ||d\} }}}}tt| ||||d}t||S )a  
    Compute the standard deviation along given axis while ignoring NaNs

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanstd(s)
    1.0
    zM8[ns]r   r   r  )r:   r   r   rT   sqrtnanvarr   )rO   rj   rk   r  ro   
orig_dtyper   rz   r3   r3   r4   nanstd  s   
$

r  m8c                C  s  t | dd} | j}t| ||}t|r!| d} |dur!tj| |< t| jr3t| j	|||| j\}}n
t| j	|||\}}|rN|durN| 
 } t| |d t| j|tjd| }|durdt||}t||  d }	|durwt|	|d |	j|tjd| }
t|r|
j|dd	}
|
S )
a  
    Compute the variance along given axis while ignoring NaNs

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanvar(s)
    1.0
    Tr   r   Nr   )rj   r:   r   Fr   )r(   r:   r   r   r   rT   rH   r   r  r   r   r   r   r   r   expand_dims)rO   rj   rk   r  ro   r:   r   r  avgsqrrz   r3   r3   r4   r    s.   %


r  c                C  s   t | ||||d t| ||}t| js| d} |s&|dur&| r&tjS t| j	|||| j\}}t | ||||d}t
|t
| S )a  
    Compute the standard error in the mean along given axis while ignoring NaNs

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nansem(s)
     0.5773502691896258
    r  r   N)r  r   r   r:   r   rP   rT   rH   r  r   r  )rO   rj   rk   r  ro   r   r   varr3   r3   r4   nansem  s   &

r  c                   s2   t d dtd dd dd fdd}|S )NrH   )rg   Tr   rO   rl   rj   rm   rk   r-   ro   r   r.   r   c             
     s   t | | |d\} }}}}|d ur| j| dks| jdkr>zt| ||d}|tj W n ttt	fy=   tj}Y nw t| |}t
|||| j}|S )Nr   ro   r   r   )r   r   rr   r~   r  rT   rH   r   rS   rV   r   )rO   rj   rk   ro   r:   r   r   rz   r   methr3   r4   	reduction2  s   	 
z_nanminmax.<locals>.reduction)
rO   rl   rj   rm   rk   r-   ro   r   r.   r   )rf   r   )r  r   r  r3   r  r4   
_nanminmax1  s   r   minr   )r   max-infOint | np.ndarrayc                C  6   t | dd|d\} }}}}| |}t||||}|S )a  
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : int or ndarray[int]
        The index/indices  of max value in specified axis or -1 in the NA case

    Examples
    --------
    >>> from pandas.core import nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmax(arr)
    4

    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 2] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [ 6.,  7., nan],
           [ 9., 10., nan]])
    >>> nanops.nanargmax(arr, axis=1)
    array([2, 2, 1, 1])
    Tr#  r  )r   argmax_maybe_arg_null_outrO   rj   rk   ro   r   rz   r3   r3   r4   	nanargmaxR     '
r*  c                C  r&  )a  
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : int or ndarray[int]
        The index/indices of min value in specified axis or -1 in the NA case

    Examples
    --------
    >>> from pandas.core import nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmin(arr)
    0

    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 0] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [nan,  7.,  8.],
           [nan, 10., 11.]])
    >>> nanops.nanargmin(arr, axis=1)
    array([0, 0, 1, 1])
    Tr   r  )r   argminr(  r)  r3   r3   r4   	nanargmin  r+  r-  c                C  s  t | dd} t| ||}t| js| d} t| j||}n
t| j||| jd}|r:|dur:|  } t	| |d n|sG|durG|
 rGtjS | j|tjd| }|dur[t||}| | }|rl|durlt	||d |d }|| }|j|tjd}	|j|tjd}
t|	}	t|
}
tjddd	 ||d
 d  |d  |
|	d   }W d   n1 sw   Y  | j}t|r|j|dd}t|tjrt|	dkd|}tj||dk < |S |	dkrdn|}|dk rtjS |S )a  
    Compute the sample skewness.

    The statistic computed here is the adjusted Fisher-Pearson standardized
    moment coefficient G1. The algorithm computes this coefficient directly
    from the second and third central moment.

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 1, 2])
    >>> nanops.nanskew(s)
    1.7320508075688787
    Tr   r   r   Nr   r   rJ   rL   divider   g      ?g      ?Fr      )r(   r   r   r:   r   r   r   r   rT   r   rP   rH   r   r   r  _zero_out_fperrrU   r   r   r   )rO   rj   rk   ro   r   meanadjusted	adjusted2	adjusted3m2m3rz   r:   r3   r3   r4   nanskew  sJ   '

&r8  c                C  sF  t | dd} t| ||}t| js| d} t| j||}n
t| j||| jd}|r:|dur:|  } t	| |d n|sG|durG|
 rGtjS | j|tjd| }|dur[t||}| | }|rl|durlt	||d |d }|d }|j|tjd}	|j|tjd}
tjddd	0 d
|d d  |d |d
   }||d  |d  |
 }|d |d
  |	d  }W d   n1 sw   Y  t|}t|}t|tjs|dk rtjS |dkrdS tjddd	 || | }W d   n1 sw   Y  | j}t|r
|j|dd}t|tjr!t|dkd|}tj||dk < |S )a  
    Compute the sample excess kurtosis

    The statistic computed here is the adjusted Fisher-Pearson standardized
    moment coefficient G2, computed directly from the second and fourth
    central moment.

    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 1, 3, 2])
    >>> nanops.nankurt(s)
    -1.2892561983471076
    Tr   r   r   Nr   r   rJ   r.  r0  r      Fr   )r(   r   r   r:   r   r   r   r   rT   r   rP   rH   r   r   r  rU   r1  r   r   r   )rO   rj   rk   ro   r   r2  r3  r4  	adjusted4r6  m4adj	numeratordenominatorrz   r:   r3   r3   r4   nankurt  sV   '

 	
r?  c                C  sF   t | ||}|r|dur|  } d| |< | |}t|||| j|dS )a  
    Parameters
    ----------
    values : ndarray[dtype]
    axis : int, optional
    skipna : bool, default True
    min_count: int, default 0
    mask : ndarray[bool], optional
        nan-mask if known

    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, 3, np.nan])
    >>> nanops.nanprod(s)
    6.0
    Nr   r   )r   r   prodr   r   )rO   rj   rk   rn   ro   rz   r3   r3   r4   r   k  s    
r   np.ndarray | intc                 C  sr   |d u r| S |d u st | dds"|r| rdS | S | r dS | S |r*||}n||}| r7d| |< | S )Nr   F)r~   r   rP   )rz   rj   ro   rk   na_maskr3   r3   r4   r(    s    
r(  float | np.ndarrayc                 C  sz   |du r|dur|j |  }nt| }||S |dur)|j| || }n| | }t|r6||S |j|ddS )a  
    Get the count of non-null values along an axis

    Parameters
    ----------
    values_shape : tuple of int
        shape tuple from values ndarray, used if mask is None
    mask : Optional[ndarray[bool]]
        locations in values that should be considered missing
    axis : Optional[int]
        axis to count along
    dtype : type, optional
        type to use for count

    Returns
    -------
    count : scalar or array
    NFr   )rr   r   rT   r@  r8   r   r    r   )r  ro   rj   r:   nr   r3   r3   r4   r     s   


r   np.ndarray | float | NaTTypec           	      C  s  |du r
|dkr
| S |durot | tjro|dur'|j| || | dk }n|| | dk }|d| ||d d  }t||}t|rmt| rit| rW| 	d} nt
| sb| j	ddd} tj| |< | S d| |< | S | turt|||rt| dd}t
|r|d	} | S tj} | S )
zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nr   r   c16r   Fr   r:   rH   )r   rT   r   r   r   broadcast_torP   r   iscomplexobjr   r   rH   r   check_below_min_countr~   r8   )	rz   rj   ro   r   rn   	null_maskbelow_count	new_shaperesult_dtyper3   r3   r4   r     s4   




r   c                 C  s:   |dkr|du rt | }n|j|  }||k rdS dS )a  
    Check for the `min_count` keyword. Returns True if below `min_count` (when
    missing value should be returned from the reduction).

    Parameters
    ----------
    shape : tuple
        The shape of the values (`values.shape`).
    mask : ndarray[bool] or None
        Boolean numpy array (typically of same shape as `shape`) or None.
    min_count : int
        Keyword passed through from sum/prod call.

    Returns
    -------
    bool
    r   NTF)rT   r@  rr   r   )r   ro   rn   	non_nullsr3   r3   r4   rJ    s   rJ  c                 C  sr   t | tjr*tjdd tt| dk d| W  d    S 1 s#w   Y  d S t| dk r7| jdS | S )NrJ   rK   g+=r   )r   rT   r   rU   r   absr:   r8   )argr3   r3   r4   r1  +  s
   $r1  pearson)methodmin_periodsabrS  r   rT  
int | Nonec                C  sp   t | t |krtd|du rd}t| t|@ }| s&| | } || }t | |k r/tjS t|}|| |S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNr   )rp   AssertionErrorr'   r   rT   rH   get_corr_func)rU  rV  rS  rT  validrG   r3   r3   r4   nancorr4  s   
r[  )Callable[[np.ndarray, np.ndarray], float]c                   sx   | dkrddl m   fdd}|S | dkr$ddl m fdd}|S | d	kr.d
d }|S t| r4| S td|  d)Nkendallr   
kendalltauc                       | |d S Nr   r3   rU  rV  r^  r3   r4   r   W     zget_corr_func.<locals>.funcspearman	spearmanrc                   r`  ra  r3   rb  re  r3   r4   r   ^  rc  rR  c                 S  s   t | |d S )Nr   r   )rT   corrcoefrb  r3   r3   r4   r   d  s   zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)scipy.statsr_  rf  callablerV   )rS  r   r3   )r_  rf  r4   rY  Q  s    
rY  )rT  r  c                C  sr   t | t |krtd|d u rd}t| t|@ }| s&| | } || }t | |k r/tjS tj| ||dd S )Nz&Operands to nancov must have same sizer   r  rg  )rp   rX  r'   r   rT   rH   cov)rU  rV  rT  r  rZ  r3   r3   r4   nancovq  s   rl  c                 C  s,  t | tjrYt| st| r| tj} | S t| rWz| tj} W n) t	t
fyK   z
| tj} W Y | S  t
yJ } z	t	d|  d|d }~ww w tt| sW| j} | S t| st| st| szt| } W | S  t	t
fy   zt| } W Y | S  t
y } z	t	d|  d|d }~ww w | S )NzCould not convert z to numeric)r   rT   r   r   r   r   r   r   
complex128rS   rV   rP   imagrealr   r   r   r   complex)r   r  r3   r3   r4   r     sB   
r   c                   s    fdd}|S )Nc                   s|   t | }t |}||B }tjdd  | |}W d    n1 s"w   Y  | r<t|r4|d}t||tj |S )NrJ   r   r$  )r%   rT   rU   rP   r   r   r   rH   )r   yxmaskymaskro   rz   opr3   r4   rG     s   
zmake_nancomp.<locals>.fr3   )ru  rG   r3   rt  r4   make_nancomp  s   rv  r   c             	   C  s   t jdt jft jjt j t jft jdt jft jjt jt jfi| \}}| jj	dvs+J |rPt
| jjt jt jfsP|  }t|}|||< ||dd}|||< |S || dd}|S )a  
    Cumulative function with skipna support.

    Parameters
    ----------
    values : np.ndarray or ExtensionArray
    accum_func : {np.cumprod, np.maximum.accumulate, np.cumsum, np.minimum.accumulate}
    skipna : bool

    Returns
    -------
    np.ndarray or ExtensionArray
    g      ?g        r   r   r   )rT   cumprodrH   maximum
accumulater   cumsumminimumr:   r   rD   r8   r   bool_r   r%   )rO   
accum_funcrk   mask_amask_bvalsro   rz   r3   r3   r4   na_accum_func  s"   r  )T)r,   r-   r.   r/   )r:   r   rg   r   r.   r-   rb   )NN)r:   r   r   r   )rO   rl   rk   r-   ro   r   r.   r   )NNN)rO   rl   rk   r-   r   r   r   r   ro   r   r.   r   )r:   r   r.   r-   r0   )r:   r   )r   r   r.   r   )rO   rl   rj   rm   r.   r   )
rO   rl   rj   rm   rk   r-   ro   r   r.   r-   )rO   rl   rj   rm   rk   r-   rn   r   ro   r   r.   r   )
rz   r   rj   rm   ro   r   r   rl   r.   r   )
rO   rl   rj   rm   rk   r-   ro   r   r.   r   )rj   rm   rk   r-   )
r   r  rj   r   r:   r  r   r   r.   rl   )r  r   ro   r   rj   rm   r  r   r:   r   r.   r  )rj   rm   rk   r-   r  r   )rO   rl   rj   rm   rk   r-   r  r   ro   r   r.   r   )
rO   rl   rj   rm   rk   r-   ro   r   r.   r%  )
rz   rl   rj   rm   ro   r   rk   r-   r.   rA  )
r  r   ro   r   rj   rm   r:   r   r.   rD  )r   )rz   rF  rj   rm   ro   r   r   r  rn   r   r.   rF  )r   r  ro   r   rn   r   r.   r-   )
rU  rl   rV  rl   rS  r   rT  rW  r.   r   )rS  r   r.   r\  )
rU  rl   rV  rl   rT  rW  r  rW  r.   r   )rO   r   rk   r-   r.   r   )t
__future__r   r_   rM   operatortypingr   r   r   r   numpyrT   pandas._configr   pandas._libsr   r   r	   r
   pandas._typingr   r   r   r   r   r   r   r   r   pandas.compat._optionalr   pandas.util._exceptionsr   pandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   pandas.core.dtypes.dtypesr$   pandas.core.dtypes.missingr%   r&   r'   pandas.core.constructionr(   r   r1   r2   r5   r6   rf   ru   rw   r   r   r   r   r   r   rt   r   r   r   r   r   r   r   r   r:   r   r  r  r  r  r   nanminnanmaxr*  r-  r8  r?  r   r(  r   r   rJ  r1  r[  rY  rl  r   rv  gtnangtgenangeltnanltlenanleeqnaneqnenanner  r3   r3   r3   r4   <module>   s   ,@ 
8

/
Y
)
"
%:7
.?
P
 /-J4--Xa
+
.
0	
  





