a
    é´«j(Ç  ã                   @  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/d­dddœdd„Z0e0edƒƒ G dd„ dƒZ1G dd„ dƒZ2ddddœdd„Z3ddœd d!„Z4d®dd"d#œd$d%„Z5d&dd'd'd(œd)d*„Z6d¯d&dd+d,d'd-d.œd/d0„Z7d1d1d2œd3d4„Z8ddd2œd5d6„Z9d°d1d7œ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œd�d‚„ƒƒZQe1dKdlƒe=ddd ddLœd&d>ddMd'dNdOœdƒd„„ƒƒZRd&d>d'dd…d†œd‡dˆ„ZSe
 Ee
jF¡fd]d'd>d‰dŠd‹œdŒd�„ZTd±dŽd>d'd�dMdŽd�œd‘d’„ZUd�d'dMdd“œd”d•„ZVd–d—„ ZWe1dKdlƒd˜dd™œd&d&dšd›dNdœœd�dž„ƒZXdšdŸd œd¡d¢„ZYe1dKdlƒddfd£œd&d&d›d›dNd¤œd¥d¦„ƒZZd§d¨„ Z[d©dd©dªœd«d¬„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*   úQ/var/www/html/laksyashrimp/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Ð|rÐt| 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r”t|||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ƒsˆt|ƒ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sÀt | ¡rÒt d¡ 	|¡} n.t | ¡tjkrìt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r¨t| ƒ‰ ˆ 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 sæ0    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 ||| ¡}
n�t ¡ �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 �sš0    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rÀt ||¡}t
||  d ƒ}	|duræt 	|	|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ç   Ú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„| 	¡ r„tj
S tjddd��$ | j|tjd�| }W d  ƒ n1 s¼0    Y  |durÚt ||¡}| | }|rü|durüt ||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 �s†0    Y  | j}|jdk�r°|j|dd�}t|tjƒ�ràt |	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„| 	¡ r„tj
S tjddd��$ | j|tjd�| }W d  ƒ n1 s¼0    Y  |durÚt ||¡}| | }|rü|durüt ||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 �s¢0    Y  t|ƒ}t|ƒ}t|tjƒ�sð|dk �rÚt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rÚt | tjƒrÚ|durN|j| | |¡ | dk }n8|| | dk }|d|… ||d d…  }t ||¡}t |¡rØt| ƒrÐt | ¡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rØt 	| ¡}|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} n¦t| ƒ�s€t| ƒ�s€t| ƒ�s€t | 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 ‚|ržt
| 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û û$