a
    Of(                     @  sf  d dl m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( d d
l)m*Z*m+Z+m,Z, edddZ-e-duZ.da/ddddddZ0e0ed G dd dZ1G dd dZ2ddddddZ3ddd d!Z4ddd"d#d$d%Z5d&dd'd'd(d)d*Z6dd&dd+d,d'd-d.d/d0Z7d1d1d2d3d4Z8ddd2d5d6Z9dd1d7d8d9Z:d:d:d;d<d=Z;d&d>d?d@dAdBZ<d:d:d;dCdDZ=ddddEd&d>dd'ddFdGdHZ>ddddEd&d>dd'ddFdIdJZ?e1dKe;e=ddd ddLd&d>ddMd'dNdOdPdQZ@dRd>dSd&dTdUdVdWZAe2 e;ddddEd&d>dd'dNdFdXdYZBe2 ddddEd>ddZd[d\ZCd]d^d&d_d`daZDe
Ee
jFfd]d'd>dMd1dbdcdddeZGe2dfdgdddfddhd>ddMdidjdkZHe1dKdle2dfdgdddfddhd&d>ddMdmdndoZIe1dKdldddfddhd&d>ddMd'dNdpdqdrZJdsdt ZKeKdudvdwZLeKdxdydwZMddddEd&d>dd'dzdFd{d|ZNddddEd&d>dd'dzdFd}d~ZOe1dKdle=ddddEd&d>dd'dNdFddZPe1dKdle=ddddEd&d>dd'dNdFddZQe1dKdle=ddd ddLd&d>ddMd'dNdOddZRd&d>d'dddddZSe
Ee
jFfd]d'd>dddddZTddd>d'ddMddddZUdd'dMddddZVdd ZWe1dKdldddd&d&dddNdddZXdddddZYe1dKdlddfdd&d&dddNdddZZdd Z[ddddddZ\d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_complexis_floatis_float_dtype
is_integeris_numeric_dtypeis_object_dtypeneeds_i8_conversionpandas_dtype)isnana_value_for_dtypenotnaZ
bottleneckwarn)errorsFTboolNone)vreturnc                 C  s   t r| ad S N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)r%    r*   K/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/core/nanops.pyset_use_bottleneck9   s    r,   zcompute.use_bottleneckc                      sB   e Zd Zddd fddZdddd	Zd
d
dddZ  ZS )disallowr   r$   )dtypesr&   c                   s"   t    tdd |D | _d S )Nc                 s  s   | ]}t |jV  qd S r'   )r   type).0dtyper*   r*   r+   	<genexpr>F       z$disallow.__init__.<locals>.<genexpr>)super__init__tupler.   )selfr.   	__class__r*   r+   r5   D   s    
zdisallow.__init__r#   r&   c                 C  s   t |dot|jj| jS )Nr1   )hasattr
issubclassr1   r/   r.   )r7   objr*   r*   r+   checkH   s    zdisallow.checkr   )fr&   c                   s"   t   fdd}tt|S )Nc               
     s   t | | }tfdd|D rD jdd}td| dz | i |W S  ty } z$t| d rzt|| W Y d }~n
d }~0 0 d S )Nc                 3  s   | ]}  |V  qd S r'   )r>   )r0   r=   )r7   r*   r+   r2   O   r3   z0disallow.__call__.<locals>._f.<locals>.<genexpr>nan zreduction operation 'z' not allowed for this dtyper   )		itertoolschainvaluesany__name__replace	TypeError
ValueErrorr   )argskwargsZobj_iterf_nameer?   r7   r*   r+   _fL   s    

zdisallow.__call__.<locals>._f	functoolswrapsr   r   )r7   r?   rO   r*   rN   r+   __call__K   s    zdisallow.__call__)rF   
__module____qualname__r5   r>   rS   __classcell__r*   r*   r8   r+   r-   C   s   r-   c                   @  s,   e Zd Zd
ddddZddddd	ZdS )bottleneck_switchNr$   r:   c                 K  s   || _ || _d S r'   )namerK   )r7   rX   rK   r*   r*   r+   r5   c   s    zbottleneck_switch.__init__r   )altr&   c              	     sn   j p
 jzttW n ttfy4   d Y n0 t d dddddd fdd}tt	|S )	NTaxisskipna
np.ndarrayAxisInt | Noner#   )rD   r[   r\   c                  s   t jdkr2j D ]\}}||vr|||< q| jdkrT|dd u rTt| |S tr|rt| jr|dd d u r|	dd  | fd|i|}t
|rΈ | f||d|}q | f||d|}n | f||d|}|S )Nr   	min_countmaskr[   rZ   )lenrK   itemssizeget_na_for_min_countr)   _bn_ok_dtyper1   pop	_has_infs)rD   r[   r\   kwdskr%   resultrY   Zbn_funcZbn_namer7   r*   r+   r?   o   s    

z%bottleneck_switch.__call__.<locals>.f)
rX   rF   getattrbnAttributeError	NameErrorrQ   rR   r   r   )r7   rY   r?   r*   rl   r+   rS   g   s    
"'zbottleneck_switch.__call__)N)rF   rT   rU   r5   rS   r*   r*   r*   r+   rW   b   s   rW   r   str)r1   rX   r&   c                 C  s   | t krt| s|dvS dS )N)nansumnanprodnanmeanF)objectr   )r1   rX   r*   r*   r+   rf      s    rf   r:   c              	   C  sT   t | tjr&| jdv r&t| dS zt|  W S  t	t
fyN   Y dS 0 d S )N)f8Zf4KF)
isinstancenpndarrayr1   r
   Zhas_infsZravelisinfrE   rH   NotImplementedError)rk   r*   r*   r+   rh      s    
rh   zScalar | None)r1   
fill_valuec                 C  sP   |dur|S t | r:|du r"tjS |dkr0tjS tj S n|dkrHtjS tS dS )z9return the correct fill value for the dtype of the valuesN+inf)_na_ok_dtypery   r@   infr
   i8maxr	   )r1   r}   fill_value_typr*   r*   r+   _get_fill_value   s    
r   r]   npt.NDArray[np.bool_] | None)rD   r\   r`   r&   c                 C  s4   |du r0| j jdv rdS |s(| j jdv r0t| }|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biumM)r1   kindr   )rD   r\   r`   r*   r*   r+   _maybe_get_mask   s    !r   r   z
str | Nonez/tuple[np.ndarray, npt.NDArray[np.bool_] | None])rD   r\   r}   r   r`   r&   c                 C  s   t | ||}| j}d}| jjdv r6t| d} d}|r|durt|||d}|dur| r|slt|r| 	 } t
| || nt| | |} | |fS )a  
    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
    Fr   i8TN)r}   r   )r   r1   r   ry   Zasarrayviewr   rE   r   copyputmaskwhere)rD   r\   r}   r   r`   r1   datetimeliker*   r*   r+   _get_values   s"    )r   znp.dtype)r1   r&   c                 C  sN   | }| j dv rttj}n.| j dkr4ttj}n| j dkrJttj}|S )NZbiur?   )r   ry   r1   int64Zuint64float64)r1   Z	dtype_maxr*   r*   r+   _get_dtype_maxD  s    


r   c                 C  s   t | rdS t| jtj S )NF)r   r<   r/   ry   integerr1   r*   r*   r+   r   P  s    r   r   c                 C  s  | t u rn|jdkr|du r"t}t| tjst|r>J d| |krLtj} t| rhtdd	|} nt
| |} | j	|dd} n
| 	|} n~|jdkrt| tjs| |kst| rtd	|} n.t| tjkrtd	nt
| j	|dd} n| 	d
|} | S )zwrap our results if neededMNzExpected non-null fill_valuer   nsFr   mzoverflow in timedelta operationm8[ns])r   r   r	   rx   ry   rz   r   r@   Z
datetime64astyper   r   isnanZtimedelta64fabsr
   r   rI   )rk   r1   r}   r*   r*   r+   _wrap_resultsV  s.    

r   r   )funcr&   c                   s6   t  dddd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r[   r\   r`   r]   r^   r#   r   rD   r[   r\   r`   c                  sr   | }| j jdv }|r$|d u r$t| } | f|||d|}|rnt||j td}|sn|d us`J t||||}|S )Nr   r   )r}   )r1   r   r   r   r	   _mask_datetimelike_result)rD   r[   r\   r`   rK   orig_valuesr   rk   r   r*   r+   new_func  s    	z&_datetimelike_compat.<locals>.new_funcrP   )r   r   r*   r   r+   _datetimelike_compat  s    r   r^   zScalar | np.ndarray)rD   r[   r&   c                 C  sp   | j jdv r| d} t| j }| jdkr.|S |du r:|S | jd| | j|d d  }tj||| j dS 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.
    Ziufcbr      Nr   )r1   r   r   r   ndimshapery   full)rD   r[   r}   Zresult_shaper*   r*   r+   re     s    


 re   c                   s.   t  dd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r[   r]   r^   )rD   r[   c                  s   |dkr| j dkr| jd r| jd d | jd kr| jtkr| jtkrt|  dd urd fddt	t
 D }nfd	d D }t|S | fd
|iS )Nr      ZC_CONTIGUOUSi  r   r`   c                   s(   g | ] } | fd | iqS r`   r*   )r0   i)arrsr   rK   r`   r*   r+   
<listcomp>  s   z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>c                   s   g | ]} |fi qS r*   r*   )r0   x)r   rK   r*   r+   r     r3   r[   )r   flagsr   r1   ru   r#   listrd   rg   rangera   ry   array)rD   r[   rK   resultsr   )r   rK   r`   r+   newfunc  s*    



z&maybe_operate_rowwise.<locals>.newfuncrP   )r   r   r*   r   r+   maybe_operate_rowwise  s    r   r   )rD   r[   r\   r`   r&   c                C  sn   | j jdv r|du r| |S | j jdkr<tjdtt d t| |d|d\} }| j tkrd| 	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.values)
    True

    >>> from pandas.core import nanops
    >>> s = pd.Series([np.nan])
    >>> nanops.nanany(s.values)
    False
    iubNr   zz'any' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).any() instead.
stacklevelFr}   r`   )r1   r   rE   warningsr!   FutureWarningr   r   ru   r   r#   rD   r[   r\   r`   _r*   r*   r+   nanany  s    "


r   c                C  sn   | j jdv r|du r| |S | j jdkr<tjdtt d t| |d|d\} }| j tkrd| 	t
} | |S )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.values)
    True

    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 0])
    >>> nanops.nanall(s.values)
    False
    r   Nr   zz'all' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).all() instead.r   Tr   )r1   r   allr   r!   r   r   r   ru   r   r#   r   r*   r*   r+   nanall  s    "


r   ZM8)r[   r\   r_   r`   intfloat)rD   r[   r\   r_   r`   r&   c                C  sn   | j }t| |d|d\} }t|}|jdkr2|}n|jdkrHt 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.values)
    3.0
    r   r   r?   r   r   r_   )	r1   r   r   r   ry   r   sum_maybe_null_outr   )rD   r[   r\   r_   r`   r1   	dtype_sumthe_sumr*   r*   r+   rr   \  s    "

rr   z+np.ndarray | np.datetime64 | np.timedelta64znpt.NDArray[np.bool_]z5np.ndarray | np.datetime64 | np.timedelta64 | NaTType)rk   r[   r`   r   r&   c                 C  sR   t | tjr4| d|j} |j|d}t| |< n| rNtt|jS | S )Nr   r   )	rx   ry   rz   r   r   r1   rE   r	   r   )rk   r[   r`   r   Z	axis_maskr*   r*   r+   r     s    
r   c                C  s*  | j }t| |d|d\} }t|}t tj}|jdv rFt tj}n*|jdv r^t tj}n|jdkrp|}|}t| j|||d}| j||d}t	|}|durt
|dd	rttj|}tjd
d || }	W d   n1 s0    Y  |dk}
|
 r&tj|	|
< n|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.values)
    1.5
    r   r   r   iur?   r   Nr   Fignore)r   )r1   r   r   ry   r   r   _get_countsr   r   _ensure_numericrm   r   rz   errstaterE   r@   )rD   r[   r\   r`   r1   r   Zdtype_countcountr   Zthe_meanZct_maskr*   r*   r+   rt     s.    !


&
rt   rZ   c             
     s  | j jdko|du }d fdd	}| j }t|  |dd\} }| j jdkr| j tkrtt| }|dv rttd|  dz| d	} W n2 ty } ztt	||W Y d}~n
d}~0 0 |s|dur| j
js|  } tj| |< | j}	| jd
kr|dur|	r st||| }
nt v tddt | jd
 d
krF|dks`| jd d
krv|d
krvtjt| dd}
ntj| |d}
W d   n1 s0    Y  n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.values)
    2.0
    r?   Nc                   sr   |d u rt | }n| } s*| s*tjS t , tddt t| | }W d    n1 sd0    Y  |S )Nr   All-NaN slice encountered)	r    r   ry   r@   r   catch_warningsfilterwarningsRuntimeWarning	nanmedian)r   Z_maskresr\   r*   r+   
get_median  s    

,znanmedian.<locals>.get_median)r`   r}   stringmixedzCannot convert  to numericrv   r   r   r   r   T)Zkeepdimsr   )N)r1   r   r   ru   r
   infer_dtyperH   r   rI   rq   r   Z	writeabler   ry   r@   rc   r   Zapply_along_axisr   r   r   r   r   r   Zsqueeze_get_empty_reduction_resultr   )rD   r[   r\   r`   Zusing_nan_sentinelr   r1   inferrederrZnotemptyr   r*   r   r+   r     sH    

$

0r   r   r   )r   r[   r&   c                 C  s@   t | }t t| }t j|||k t jd}|t j |S )z
    The result from a reduction on an empty ndarray.

    Parameters
    ----------
    shape : Tuple[int, ...]
    axis : int

    Returns
    -------
    np.ndarray
    r   )ry   r   Zarangera   emptyr   fillr@   )r   r[   Zshpdimsretr*   r*   r+   r   C  s
    
r   z-tuple[float | np.ndarray, float | np.ndarray])values_shaper`   r[   ddofr1   r&   c                 C  s   t | |||d}||| }t|r<||krxtj}tj}n<ttj|}||k}| rxt||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   r/   r   ry   r@   r   rz   rE   r   )r   r`   r[   r   r1   r   dr*   r*   r+   _get_counts_nanvarZ  s    r   r   r   r[   r\   r   r`   )r[   r\   r   c             	   C  sN   | 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.values)
    1.0
    zM8[ns]r   r   r   )r1   r   r   ry   sqrtnanvarr   )rD   r[   r\   r   r`   Z
orig_dtyperk   r*   r*   r+   nanstd  s    $

r   Zm8)rD   r[   r\   r   c                C  s  | j }t| ||}|jdv r8| d} |dur8tj| |< | j jdkr^t| j|||| j \}}nt| j|||\}}|r|dur|  } t	| |d t
| j|tjd| }|durt||}t
||  d }	|durt	|	|d |	j|tjd| }
|jdk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.values)
    1.0
    r   rv   Nr?   r   )r[   r1   r   Fr   )r1   r   r   r   ry   r@   r   r   r   r   r   r   r   expand_dims)rD   r[   r\   r   r`   r1   r   r   ZavgZsqrrk   r*   r*   r+   r     s,    %


r   )rD   r[   r\   r   r`   r&   c                C  s   t | ||||d t| ||}| jjdkr4| d} |sN|durN| rNt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.values)
     0.5773502691896258
    r   r?   rv   N)r   r   r1   r   r   rE   ry   r@   r   r   r   )rD   r[   r\   r   r`   r   r   varr*   r*   r+   nansem  s    &
r   c                   s<   t d dtd dd dddddd	 fd
d}|S )Nr@   )rX   Tr   r]   r^   r#   r   r   c                  sJ   | j dkrt| |S t| | |d\} }t| |}t|||| j}|S )Nr   r   r`   )rc   re   r   rm   r   r   rD   r[   r\   r`   rk   r   methr*   r+   	reduction;  s    	


z_nanminmax.<locals>.reduction)rW   r   )r   r   r   r*   r   r+   
_nanminmax:  s    "r   minr~   )r   max-infzint | np.ndarrayc                C  s0   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   Zargmax_maybe_arg_null_outr   r*   r*   r+   	nanargmaxU  s    &
r   c                C  s0   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 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   Zargminr   r   r*   r*   r+   	nanargmin  s    &
r   c                C  s  t | ||}| jjdkr2| d} t| j||}nt| j||| jd}|rj|durj|  } t| |d n|s|dur|	 rtj
S tjddd$ | j|tjd| }W d   n1 s0    Y  |durt||}| | }|r|durt||d |d }|| }|j|tjd}	|j|tjd}
t|	}	t|
}
tjddd4 ||d	 d
  |d  |
|	d   }W d   n1 s0    Y  | j}|jdkr|j|dd}t|tjrt|	dkd|}tj
||dk < n(|	dkr|dn|}|dk rt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.values)
    1.7320508075688787
    r?   rv   r   Nr   r   invaliddivider   r   g      ?g      ?Fr      )r   r1   r   r   r   r   r   ry   r   rE   r@   r   r   r   r   _zero_out_fperrrx   rz   r   r/   )rD   r[   r\   r`   r   meanadjusted	adjusted2Z	adjusted3m2Zm3rk   r1   r*   r*   r+   nanskew  sF    %
2D
r  c                C  s~  t | ||}| jjdkr2| d} t| j||}nt| j||| jd}|rj|durj|  } t| |d n|s|dur|	 rtj
S tjddd$ | j|tjd| }W d   n1 s0    Y  |durt||}| | }|r|durt||d |d }|d }|j|tjd}	|j|tjd}
tjddd` d	|d
 d  |d |d	   }||d
  |d
  |
 }|d |d	  |	d  }W d   n1 s0    Y  t|}t|}t|tjs|dk rtj
S |dkr| jdS tjddd || | }W d   n1 s"0    Y  | j}|jdkrL|j|dd}t|tjrzt|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.values)
    -1.2892561983471076
    r?   rv   r   Nr   r   r   r   r   r      Fr   )r   r1   r   r   r   r   r   ry   r   rE   r@   r   r   r   r   r  rx   rz   r/   r   )rD   r[   r\   r`   r   r  r  r  Z	adjusted4r  Zm4Zadj	numeratordenominatorrk   r1   r*   r*   r+   nankurt	  sR    %
2 8

,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.values)
    6.0
    Nr   r   )r   r   prodr   r   )rD   r[   r\   r_   r`   rk   r*   r*   r+   rs   j  s     
rs   znp.ndarray | int)rk   r[   r`   r\   r&   c                 C  sn   |d u r| S |d u s t | dds@|r2| r>dS qj| rjdS n*|rP||}n
||}| rjd| |< | S )Nr   F)rm   r   rE   )rk   r[   r`   r\   Zna_maskr*   r*   r+   r     s    
r   znp.dtype[np.floating]z&np.floating | npt.NDArray[np.floating])r   r`   r[   r1   r&   c                 C  sz   |du r4|dur |j |  }n
t| }||S |durR|j| || }n| | }t|rl||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   )rc   r   ry   r  r/   r   r   r   )r   r`   r[   r1   nr   r*   r*   r+   r     s    


r   znp.ndarray | float | NaTTypeztuple[int, ...])rk   r[   r`   r   r_   r&   c           	      C  s  |du r|dkr| S |durt | tjr|durN|j| || | dk }n8|| | dk }|d| ||d d  }t||}t|rt| rt| r| 	d} nt
| s| j	ddd} tj| |< nd| |< n@| turt|||rt| dd}t
|r|d	} ntj} | S )
zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nr   r   Zc16rv   Fr   r1   r@   )rx   ry   rz   r   r   Zbroadcast_torE   r   Ziscomplexobjr   r   r@   r   check_below_min_countrm   r/   )	rk   r[   r`   r   r_   Z	null_maskZbelow_countZ	new_shapeZresult_dtyper*   r*   r+   r     s.    




r   )r   r`   r_   r&   c                 C  s:   |dkr6|du rt | }n|j|  }||k r6d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)ry   r  rc   r   )r   r`   r_   Z	non_nullsr*   r*   r+   r    s    r  c                 C  sF   t | tjr$tt| dk d| S t| dk r>| jdS | S d S )Ng+=r   )rx   ry   rz   r   absr1   r/   )argr*   r*   r+   r  *  s    r  pearson)methodmin_periodsr   z
int | None)abr  r  r&   c                C  s   t | t |krtd|du r$d}t| t|@ }| sL| | } || }t | |k r^tjS t| } t|}t|}|| |S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNr   )ra   AssertionErrorr    r   ry   r@   r   get_corr_func)r  r  r  r  validr?   r*   r*   r+   nancorr2  s    r  z)Callable[[np.ndarray, np.ndarray], float])r  r&   c                   s|   | dkr$ddl m   fdd}|S | dkrHddl m fdd}|S | d	kr\d
d }|S t| rh| S td|  dd S )NZkendallr   
kendalltauc                   s    | |d S Nr   r*   r  r  r  r*   r+   r   X  s    zget_corr_func.<locals>.funcZspearman	spearmanrc                   s    | |d S r  r*   r  r  r*   r+   r   _  s    r  c                 S  s   t | |d S )Nr   r   )ry   Zcorrcoefr  r*   r*   r+   r   e  s    zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)Zscipy.statsr  r  callablerI   )r  r   r*   )r  r  r+   r  R  s     
r  )r  r   )r  r  r  r   r&   c                C  s   t | t |krtd|d u r$d}t| t|@ }| sL| | } || }t | |k r^tjS t| } t|}tj| ||dd S )Nz&Operands to nancov must have same sizer   r   r   )ra   r  r    r   ry   r@   r   Zcov)r  r  r  r   r  r*   r*   r+   nancovr  s    r"  c                 C  s  t | tjr| jjdv r&| tj} n| jtkrt	| }|dv rRt
d|  dz| tj} W n^ t
tfy   z| tj} W n6 ty } zt
d|  d|W Y d }~n
d }~0 0 Y n0 tt| s| j} nt| st| st| st | trt
d|  dzt| } W n^ t
tfy~   zt| } W n8 tyx } zt
d|  d|W Y d }~n
d }~0 0 Y n0 | S )Nr   r   zCould not convert r   zCould not convert string 'z' to numeric)rx   ry   rz   r1   r   r   r   ru   r
   r   rH   Z
complex128rI   rE   imagrealr   r   r   rq   r   complex)r   r   r   r*   r*   r+   r     s6    

..r   r   )rD   r\   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sVJ |rt
| jjt jt jfs|  }t|}|||< ||dd}|||< n|| 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   )ry   Zcumprodr@   maximum
accumulater   Zcumsumminimumr1   r   r<   r/   r   Zbool_r   r   )rD   Z
accum_funcr\   Zmask_aZmask_bvalsr`   rk   r*   r*   r+   na_accum_func  s     
r*  )T)NN)NNN)N)r   )]
__future__r   rQ   rB   typingr   r   r   r   numpyry   Zpandas._configr   Zpandas._libsr   r   r	   r
   Zpandas._typingr   r   r   r   r   r   r   r   r   Zpandas.compat._optionalr   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   r   r   r   r   r   r   r   Zpandas.core.dtypes.missingr   r   r    rn   r(   r)   r,   r-   rW   rf   rh   r   r   r   r   r   r   r   re   r   r   r   rr   r   rt   r   r   r1   r   r   r   r   r   r   ZnanminZnanmaxr   r   r  r
  rs   r   r   r   r  r  r  r  r"  r   r*  r*   r*   r*   r+   <module>   s  ,(
8 /   G)"%@="-?b
2-I41.V_ +
. 0 $