o
    _~#g(                     @  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/ddddZ0e0ed G dd dZ1G dd dZ2ddd Z3dd!d"Z4	ddd%d&Z5dd,d-Z6			ddd2d3Z7dd5d6Z8dd7d8Z9ddd9d:Z:dd=d>Z;ddBdCZ<ddDdEZ=ddddFddGdHZ>ddddFddIdJZ?e1dKe;e=ddd ddLddPdQZ@ddWdXZAe2 e;ddddFddYdZZBe2 ddddFdd[d\ZCdd`daZDe
Ee
jFfddedfZGe2dgdhdddgddiddjdkZHe1dKdle2dgdhdddgddiddmdnZIe1dKdldddgddiddodpZJdqdr ZKeKdsdtduZLeKdvdwduZMddddFddydzZNddddFdd{d|ZOe1dKdle=ddddFdd}d~ZPe1dKdle=ddddFdddZQe1dKdle=ddd ddLdddZRdddZSe
Ee
jFfdddZT	gddddZUdddZVdd ZWe1dKdlddddddZXdddZYe1dKdlddgddddZZdd Z[ddd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+   w/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/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rt| 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rt
|dd	rttj|}tjd
d || }	W d   n1 sqw   Y  |dk}
|
 rt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Ĉ st||| }
nUt 7 tddt | jd
 d
kr|dks| jd d
kr|d
krtjt| dd}
ntj| |d}
W d   n1 sw   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 sw   Y  | j}|jdkr|j|dd}t|tjrt|	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 sw   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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rt|||rt| dd}t
|r|d	} | S tj} | S )
zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nr   r   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| st| st| st | trt
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
 $