o
    Û­j(Ç  ã                   @  s  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„Z0e0edƒƒ G dd„ dƒZ1G dd„ dƒZ2d©dd „Z3dªd!d"„Z4	d«d¬d%d&„Z5d­d,d-„Z6			d®d¯d2d3„Z7d°d5d6„Z8d±d7d8„Z9d²d³d9d:„Z:d´d=d>„Z;dµdBdC„Z<d´dDdE„Z=ddddFœd¶dGdH„Z>ddddFœd¶dIdJ„Z?e1dKƒe;e=ddd ddLœd·dPdQ„ƒƒƒZ@d¸dWdX„ZAe2ƒ e;ddddFœd¹dYdZ„ƒƒZBe2ƒ ddddFœdºd[d\„ƒZCd»d`da„ZDe
 Ee
jF¡fd¼dedf„ZGe2dgdh�dddgddiœd½djdk„ƒZHe1dKdlƒe2dgdh�dddgddiœd¾dmdn„ƒƒZIe1dKdlƒdddgddiœd¿dodp„ƒZJdqdr„ ZKeKdsdtdu�ZLeKdvdwdu�ZMddddFœdÀdydz„ZNddddFœdÀd{d|„ZOe1dKdlƒe=ddddFœd¹d}d~„ƒƒZPe1dKdlƒe=ddddFœd¹dd€„ƒƒZQe1dKdlƒe=ddd ddLœd·d�d‚„ƒƒZRdÁd„d…„ZSe
 Ee
jF¡fdÂdˆd‰„ZT	gdÃdÄdŒd�„ZUdÅdŽd�„ZVd�d‘„ ZWe1dKdlƒd’dd“œdÆdšd›„ƒZXdÇd�dž„ZYe1dKdlƒddgdŸœdÈd d¡„ƒZZd¢d£„ Z[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ÚnotnaÚ
bottleneckÚwarn)ÚerrorsFTÚvÚboolÚreturnÚNonec                 C  s   t r| ad S d S ©N)Ú_BOTTLENECK_INSTALLEDÚ_USE_BOTTLENECK)r$   © r+   úO/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/core/nanops.pyÚset_use_bottleneck9   s   ÿr-   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 r(   )r   Útype)Ú.0Údtyper+   r+   r,   Ú	<genexpr>F   ó   € z$disallow.__init__.<locals>.<genexpr>)ÚsuperÚ__init__Útupler/   )Úselfr/   ©Ú	__class__r+   r,   r6   D   s   
zdisallow.__init__r%   c                 C  s   t |dƒot|jj| jƒS )Nr2   )ÚhasattrÚ
issubclassr2   r0   r/   )r8   Úobjr+   r+   r,   ÚcheckH   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ˆ | i |¤ŽW S  tyB } zt| d ƒr=t|ƒ|‚‚ d }~ww )Nc                 3  s   � | ]}ˆ   |¡V  qd S r(   )r>   )r1   r=   )r8   r+   r,   r3   O   r4   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ÚkwargsÚobj_iterÚf_nameÚe©r?   r8   r+   r,   Ú_fL   s   
ÿ
€ùzdisallow.__call__.<locals>._f©Ú	functoolsÚwrapsr   r   )r8   r?   rP   r+   rO   r,   Ú__call__K   s   
zdisallow.__call__)r/   r   r&   r'   ©r&   r%   )r?   r   r&   r   )rF   Ú
__module__Ú__qualname__r6   r>   rT   Ú__classcell__r+   r+   r9   r,   r.   C   s    
r.   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 r(   )ÚnamerK   )r8   rZ   rK   r+   r+   r,   r6   c   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ÚskipnarD   ú
np.ndarrayr]   úAxisInt | Noner^   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Úmaskr]   r\   )ÚlenrK   ÚitemsÚsizeÚgetÚ_na_for_min_countr*   Ú_bn_ok_dtyper2   ÚpopÚ	_has_infs)rD   r]   r^   ÚkwdsÚkr$   Úresult©r[   Úbn_funcÚbn_namer8   r+   r,   r?   o   s$   €
üþz%bottleneck_switch.__call__.<locals>.f)rD   r_   r]   r`   r^   r%   )
rZ   rF   ÚgetattrÚbnÚAttributeErrorÚ	NameErrorrR   rS   r   r   )r8   r[   r?   r+   rn   r,   rT   g   s   ÿü
'zbottleneck_switch.__call__r(   )r&   r'   )r[   r   r&   r   )rF   rV   rW   r6   rT   r+   r+   r+   r,   rY   b   s    rY   r2   r   rZ   Ústrc                 C  s   | t krt| ƒs|dvS dS )N)ÚnansumÚnanprodÚnanmeanF)Úobjectr   )r2   rZ   r+   r+   r,   rh   š   s   rh   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)Ú
isinstanceÚnpÚndarrayr2   r
   Úhas_infsÚravelÚisinfrE   rH   ÚNotImplementedError)rm   r+   r+   r,   rj   ®   s   
þrj   Ú
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_dtyper~   r@   Úinfr
   Úi8maxr	   )r2   r„   Úfill_value_typr+   r+   r,   Ú_get_fill_value»   s   r‹   rD   r_   r^   rb   únpt.NDArray[np.bool_] | Nonec                 C  s4   |du r| j jdv rdS |s| j jdv 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ÚbiuÚmM)r2   Úkindr   )rD   r^   rb   r+   r+   r,   Ú_maybe_get_maskÑ   s   !r�   r   rŠ   ú
str | Noneú/tuple[np.ndarray, npt.NDArray[np.bool_] | None]c                 C  s¢   t | ||ƒ}| j}d}| jjdv rt |  d¡¡} d}|rM|durMt|||d�}|durM| ¡ rM|s6t|ƒrE|  	¡ } t 
| ||¡ | |fS 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�   r2   r�   r~   ÚasarrayÚviewr‹   rE   r‡   ÚcopyÚputmaskÚwhere)rD   r^   r„   rŠ   rb   r2   Údatetimeliker+   r+   r,   Ú_get_valuesý   s$   )ÿþrš   únp.dtypec                 C  sR   | }| j dv rt tj¡}|S | j dkrt tj¡}|S | j dkr't tj¡}|S )NÚbiÚur?   )r�   r~   r2   Úint64Úuint64Úfloat64)r2   Ú	dtype_maxr+   r+   r,   Ú_get_dtype_maxD  s   

ü
þr¢   c                 C  s   t | ƒrdS t| jtjƒ S )NF)r   r<   r0   r~   Úinteger©r2   r+   r+   r,   r‡   P  s   r‡   c                 C  s  | t u r	 | S |jdkrM|du rt}t| tjƒsFt|ƒr J dƒ‚| |kr'tj} t| ƒr5t dd¡ 	|¡} nt 
| ¡ |¡} | j	|dd�} | S |  	|¡} | S |jdkr‹t| tjƒsƒ| |ksat | ¡rkt d¡ 	|¡} | S t | ¡tjkrwtd	ƒ‚t 
| ¡j	|dd�} | S |  	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	   r}   r~   r   r   r@   Ú
datetime64Úastyperž   r•   ÚisnanÚtimedelta64Úfabsr
   r‰   rI   )rm   r2   r„   r+   r+   r,   Ú_wrap_resultsV  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©r]   r^   rb   rD   r_   r]   r`   r^   r%   rb   rŒ   c                  sr   | }| j jdv }|r|d u rt| ƒ}ˆ | f|||dœ|¤Ž}|r7t||j td�}|s7|d us0J ‚t||||ƒ}|S )NrŽ   r±   )r„   )r2   r�   r   r¯   r	   Ú_mask_datetimelike_result)rD   r]   r^   rb   rK   Úorig_valuesr™   rm   ©r°   r+   r,   Únew_func…  s   	z&_datetimelike_compat.<locals>.new_func©rD   r_   r]   r`   r^   r%   rb   rŒ   rQ   )r°   rµ   r+   r´   r,   Ú_datetimelike_compat  s   û
r·   r]   r`   úScalar | np.ndarrayc                 C  sl   | 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 )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.
    Úiufcbr    é   Nr¤   )r2   r�   r«   r   ÚndimÚshaper~   Úfull)rD   r]   r„   Úresult_shaper+   r+   r,   rg   ¡  s   


 rg   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©r]   rD   r_   r]   r`   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   rb   c                   s(   g | ]}ˆˆ | fd ˆ| iˆ¤Ž‘qS ©rb   r+   )r1   Úi)Úarrsr°   rK   rb   r+   r,   Ú
<listcomp>Ö  s    ÿz:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>c                   s   g | ]
}ˆ |fi ˆ¤Ž‘qS r+   r+   )r1   Úx)r°   rK   r+   r,   rÅ   Ú  s    r]   )r»   Úflagsr¼   r2   ry   r%   Úlistrf   ri   Úrangerc   r~   Úarray)rD   r]   rK   Úresultsr´   )rÄ   rK   rb   r,   ÚnewfuncÇ  s    
ÿ



ÿ
z&maybe_operate_rowwise.<locals>.newfunc)rD   r_   r]   r`   rQ   )r°   rÌ   r+   r´   r,   Úmaybe_operate_rowwiseÀ  s   
rÍ   r±   c                C  ón   | 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r2|  	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„   rb   )r2   r�   rE   Úwarningsr"   ÚFutureWarningr   rš   ry   r«   r%   ©rD   r]   r^   rb   Ú_r+   r+   r,   Ú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.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Ò   )r2   r�   ÚallrÓ   r"   rÔ   r   rš   ry   r«   r%   rÕ   r+   r+   r,   Únanall  rØ   rÚ   ÚM8)r]   r^   ra   rb   ra   ÚintÚfloatc                C  sn   | j }t| |d|d�\} }t|ƒ}|jdkr|}n|jdk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.values)
    3.0
    r   rÒ   r?   r¨   r¤   ©ra   )	r2   rš   r¢   r�   r~   r    ÚsumÚ_maybe_null_outr¼   )rD   r]   r^   ra   rb   r2   Ú	dtype_sumÚthe_sumr+   r+   r,   rv   \  s   "

rv   rm   ú+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}   r~   r   r«   r•   r2   rE   r	   rž   )rm   r]   rb   r³   Ú	axis_maskr+   r+   r,   r²   Œ  s   þr²   c                C  s$  | j }t| |d|d�\} }t|ƒ}t  tj¡}|jdv r#t  tj¡}n|jdv r/t  tj¡}n	|jdkr8|}|}t| j|||d�}| j||d�}t	|ƒ}|dur…t
|dd	ƒr…ttj|ƒ}tjd
d�� || }	W d  ƒ n1 sqw   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.values)
    1.5
    r   rÒ   rŽ   Úiur?   r¤   Nr»   FÚignore)rÙ   )r2   rš   r¢   r~   r    r�   Ú_get_countsr¼   rß   Ú_ensure_numericrq   r   r   ÚerrstaterE   r@   )rD   r]   r^   rb   r2   rá   Údtype_countÚcountrâ   Úthe_meanÚct_maskr+   r+   r,   rx   Ÿ  s2   !



þ
þrx   c             
     s´  | j jdko	|du }d‡ fdd„	}| j }t| ˆ |dd�\} }| j jdkrU| j tkr:t | ¡}|dv r:td| › d�ƒ‚z|  d	¡} W n tyT } ztt	|ƒƒ|‚d}~ww |sh|durh| j
jsc|  ¡ } tj| |< | j}	| jd
krË|durË|	rÄˆ s€t ||| ¡}
nUt ¡ �7 t ddt¡ | jd
 d
kr—|dks¢| jd d
kr­|d
kr­tjt | ¡dd�}
ntj| |d�}
W d  ƒ n1 s¾w   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                   st   |d u r	t | ƒ}n| }ˆ s| ¡ stjS t ¡ � t ddt¡ t | | ¡}W d   ƒ |S 1 s3w   Y  |S )Nrè   úAll-NaN slice encountered)	r    rÙ   r~   r@   rÓ   Úcatch_warningsÚfilterwarningsÚRuntimeWarningÚ	nanmedian)rÆ   Ú_maskÚres©r^   r+   r,   Ú
get_medianý  s   

ÿ
ûúznanmedian.<locals>.get_median)rb   r„   ©ÚstringÚmixedzCannot convert ú to numericrz   rº   rè   rð   r   T)Úkeepdimsr¿   r(   )r2   r�   rš   ry   r
   Úinfer_dtyperH   r«   rI   ru   rÇ   Ú	writeabler–   r~   r@   re   r»   Úapply_along_axisrÓ   rñ   rò   ró   r¼   rô   ÚsqueezeÚ_get_empty_reduction_resultr¯   )rD   r]   r^   rb   Úusing_nan_sentinelrø   r2   ÚinferredÚerrÚnotemptyrö   r+   r÷   r,   rô   à  sL   

€þ

ÿ€õ€
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¤   )r~   rÊ   Úarangerc   Úemptyr    Úfillr@   )r¼   r]   ÚshpÚdimsÚretr+   r+   r,   r  C  s
   
r  Úvalues_shapeÚ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é   r0   r   r~   r@   r   r   rE   r—   )r  rb   r]   r  r2   rí   Údr+   r+   r,   Ú_get_counts_nanvarZ  s   ûr  rº   ©r  ©r]   r^   r  rb   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  )r2   r•   rš   r~   ÚsqrtÚnanvarr¯   )rD   r]   r^   r  rb   Ú
orig_dtyperm   r+   r+   r,   ÚnanstdŒ  s   
$

r  Úm8c                C  s  | j }t| ||ƒ}|jdv r|  d¡} |durtj| |< | j jdkr/t| j|||| j ƒ\}}n
t| j|||ƒ\}}|rJ|durJ|  ¡ } t 	| |d¡ t
| j|tjd�ƒ| }|dur`t ||¡}t
||  d ƒ}	|durst 	|	|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ç   rz   Nr?   r   )r]   r2   rÀ   Fr§   )r2   r�   r�   r«   r~   r@   r  r¼   r–   r—   rê   rß   r    Úexpand_dims)rD   r]   r^   r  rb   r2   rí   r  ÚavgÚsqrrm   r+   r+   r,   r  º  s,   %



r  c                C  sŒ   t | ||||d� t| ||ƒ}| jjdkr|  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.values)
     0.5773502691896258
    r  r?   rz   N)r  r�   r2   r�   r«   rE   r~   r@   r  r¼   r  )rD   r]   r^   r  rb   rí   rÖ   Úvarr+   r+   r,   Únansem  s   &
r  c                   s2   t dˆ› �d�td dd dœd‡ ‡fdd„ƒƒ}|S )Nr@   )rZ   Tr±   rD   r_   r]   r`   r^   r%   rb   rŒ   c                  sJ   | j dkr
t| |ƒS t| |ˆ |d�\} }t| ˆƒ|ƒ}t|||| jƒ}|S )Nr   ©rŠ   rb   )re   rg   rš   rq   rà   r¼   ©rD   r]   r^   rb   rm   ©rŠ   Úmethr+   r,   Ú	reduction;  s   
	

ÿz_nanminmax.<locals>.reductionr¶   )rY   r·   )r!  rŠ   r"  r+   r   r,   Ú
_nanminmax:  s   ûr#  Úminr†   )rŠ   Úmaxú-infúint | np.ndarrayc                C  ó0   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_outr  r+   r+   r,   Ú	nanargmaxU  ó   &
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  r+   r+   r,   Ú	nanargminƒ  r,  r.  c                C  s  t | ||ƒ}| jjdkr|  d¡} t| j||ƒ}n
t| j||| jd�}|r5|dur5|  ¡ } t | |d¡ n|sB|durB| 	¡ rBtj
S tjddd�� | j|tjd�| }W d  ƒ n1 s^w   Y  |durmt ||¡}| | }|r~|dur~t ||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 sÂw   Y  | j}|jdkrÖ|j|dd�}t|tjƒrît |	dkd|¡}tj
||dk < |S |	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?   rz   r¤   Nr   rè   ©ÚinvalidÚdividerÀ   rº   g      à?g      ø?Fr§   é   )r�   r2   r�   r«   ré   r¼   r–   r~   r—   rE   r@   rë   rß   r    r  Ú_zero_out_fperrr}   r   r˜   r0   )rD   r]   r^   rb   rí   ÚmeanÚadjustedÚ	adjusted2Ú	adjusted3Úm2Úm3rm   r2   r+   r+   r,   Únanskew±  sL   %
ÿ&ÿ
ü
r:  c                C  sv  t | ||ƒ}| jjdkr|  d¡} t| j||ƒ}n
t| j||| jd�}|r5|dur5|  ¡ } t | |d¡ n|sB|durB| 	¡ rBtj
S tjddd�� | j|tjd�| }W d  ƒ n1 s^w   Y  |durmt ||¡}| | }|r~|dur~t ||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 sÐw   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w   Y  | j}|jdk�r"|j|dd�}t|tjƒ�r9t |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?   rz   r¤   Nr   rè   r/  rÀ   r2  rº   é   Fr§   )r�   r2   r�   r«   ré   r¼   r–   r~   r—   rE   r@   rë   rß   r    r  r3  r}   r   r0   r˜   )rD   r]   r^   rb   rí   r4  r5  r6  Ú	adjusted4r8  Úm4ÚadjÚ	numeratorÚdenominatorrm   r2   r+   r+   r,   Únankurt	  sX   %
ÿ ý	ÿrA  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^   ra   rb   rm   r+   r+   r,   rw   j  s    
ÿrw   ú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éÿÿÿÿ)rq   rÙ   rE   )rm   r]   rb   r^   Úna_maskr+   r+   r,   r*  —  s    ÷ú
r*  únp.dtype[np.floating]ú&np.floating | npt.NDArray[np.floating]c                 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§   )re   rß   r~   rB  r0   r¼   r   r«   )r  rb   r]   r2   Únrí   r+   r+   r,   ré   ²  s   


ré   únp.ndarray | float | NaTTypeútuple[int, ...]c           	      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r�t|||ƒr�t| 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º   Úc16rz   Fr§   r2   r@   )r}   r~   r   r¼   rß   Úbroadcast_torE   r   Úiscomplexobjr«   r   r@   r   Úcheck_below_min_countrq   r0   )	rm   r]   rb   r¼   ra   Ú	null_maskÚbelow_countÚ	new_shapeÚresult_dtyper+   r+   r,   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)r~   rB  re   rß   )r¼   rb   ra   Ú	non_nullsr+   r+   r,   rN    s   rN  c                 C  sB   t | tjƒrt t | ¡dk d| ¡S t | ¡dk r| j d¡S | S )Ng›+¡†›„=r   )r}   r~   r   r˜   Úabsr2   r0   )Úargr+   r+   r,   r3  *  s   r3  Úpearson)ÚmethodÚmin_periodsÚaÚbrW  r   rX  ú
int | Nonec                C  s€   t | ƒt |ƒkrtdƒ‚|du rd}t| ƒt|ƒ@ }| ¡ s&| | } || }t | ƒ|k r/tjS t| ƒ} t|ƒ}t|ƒ}|| |ƒS )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNrº   )rc   ÚAssertionErrorr    rÙ   r~   r@   rê   Úget_corr_func)rY  rZ  rW  rX  Úvalidr?   r+   r+   r,   Únancorr2  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   r+   ©rY  rZ  rb  r+   r,   r°   X  ó   zget_corr_func.<locals>.funcÚspearman©Ú	spearmanrc                   rd  re  r+   rf  ri  r+   r,   r°   _  rg  rV  c                 S  s   t  | |¡d S )N©r   rº   )r~   Úcorrcoefrf  r+   r+   r,   r°   e  s   zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)Úscipy.statsrc  rj  ÚcallablerI   )rW  r°   r+   )rc  rj  r,   r]  R  s    
ÿr]  )rX  r  c                C  s‚   t | ƒt |ƒkrtdƒ‚|d u rd}t| ƒt|ƒ@ }| ¡ s&| | } || }t | ƒ|k r/tjS t| ƒ} t|ƒ}tj| ||d�d S )Nz&Operands to nancov must have same sizerº   r  rk  )rc   r\  r    rÙ   r~   r@   rê   Úcov)rY  rZ  rX  r  r^  r+   r+   r,   Únancovr  s   rp  c                 C  sf  t | tjƒri| jjdv r|  tj¡} | S | jtkrgt 	| ¡}|dv r*t
d| › d�ƒ‚z|  tj¡} W n) t
tfy[   z
|  tj¡} W Y | S  tyZ } z	t
d| › d�ƒ|‚d }~ww w t t | ¡¡sg| j} | S t| ƒs±t| ƒs±t| ƒs±t | tƒr‚t
d| › d�ƒ‚zt| ƒ} W | S  t
tfy°   zt| ƒ} W Y | S  ty¯ } z	t
d| › d�ƒ|‚d }~ww w | S )Nr�   rù   zCould not convert rü   zCould not convert string 'z' to numeric)r}   r~   r   r2   r�   r«   r    ry   r
   rþ   rH   Ú
complex128rI   rE   ÚimagÚrealr   r   r   ru   rÝ   Úcomplex)rÆ   r  r  r+   r+   r,   rê   Ž  sL   
ã
í€þýó

ùý€þü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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¿   )r~   Úcumprodr@   ÚmaximumÚ
accumulaterˆ   ÚcumsumÚminimumr2   r�   r<   r0   r£   Úbool_r–   r   )rD   Ú
accum_funcr^   Úmask_aÚmask_bÚvalsrb   rm   r+   r+   r,   Úna_accum_func²  s"   üûþr  )T)r$   r%   r&   r'   )r2   r   rZ   ru   r&   r%   rU   )NN)r2   r   r„   r…   )rD   r_   r^   r%   rb   rŒ   r&   rŒ   )NNN)rD   r_   r^   r%   r„   r   rŠ   r‘   rb   rŒ   r&   r’   )r2   r›   r&   r›   )r2   r   r&   r%   r(   )r2   r›   )r°   r   r&   r   )rD   r_   r]   r`   r&   r¸   )
rD   r_   r]   r`   r^   r%   rb   rŒ   r&   r%   )rD   r_   r]   r`   r^   r%   ra   rÜ   rb   rŒ   r&   rÝ   )
rm   rã   r]   r`   rb   rä   r³   r_   r&   rå   )
rD   r_   r]   r`   r^   r%   rb   rŒ   r&   rÝ   )r]   r`   r^   r%   )r¼   r   r]   r   r&   r_   )r  r   rb   rŒ   r]   r`   r  rÜ   r2   r›   r&   r  )r]   r`   r^   r%   r  rÜ   )rD   r_   r]   r`   r^   r%   r  rÜ   )rD   r_   r]   r`   r^   r%   r  rÜ   rb   rŒ   r&   rÝ   )
rD   r_   r]   r`   r^   r%   rb   rŒ   r&   r'  )
rm   r_   r]   r`   rb   rŒ   r^   r%   r&   rC  )
r  r   rb   rŒ   r]   r`   r2   rF  r&   rG  )rº   )rm   rI  r]   r`   rb   rŒ   r¼   rJ  ra   rÜ   r&   rI  )r¼   rJ  rb   rŒ   ra   rÜ   r&   r%   )
rY  r_   rZ  r_   rW  r   rX  r[  r&   rÝ   )rW  r   r&   r`  )
rY  r_   rZ  r_   rX  r[  r  r[  r&   rÝ   )rD   r   r^   r%   r&   r   )]Ú
__future__r   rR   rB   Útypingr   r   r   rÓ   Únumpyr~   Ú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   Úpandas.core.dtypes.missingr   r   r    rr   r)   r*   r-   r.   rY   rh   rj   r‹   r�   rš   r¢   r‡   r¯   r·   rg   rÍ   r×   rÚ   rv   r²   rx   rô   r  r2   r    r  r  r  r  r#  ÚnanminÚnanmaxr+  r.  r:  rA  rw   r*  ré   rà   rN  r3  r_  r]  rp  rê   r  r+   r+   r+   r,   Ú<module>   s   ,(

8
ÿ
/û
G

)
"
%û@û=ú
-û?
b
û2ú-úIú4û1û.ûVû_ú
+
ü.û
0û
 û$