
    d                    8   d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	Z	d dl
Zd dlmZ d dlmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZ d dlmZ d dlm Z  d d	l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d d
l0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7  edd          Z8e8duZ9da:dddZ; e; ed                      G d d          Z< G d d          Z=dd Z>dd!Z?	 ddd$Z@dd*ZA	 	 	 ddd/ZBdd0ZCddd2ZDdd5ZEdd9ZFdd:ZGdddd;dd<ZHdddd;dd=ZI e<d>          eEeGddd dd?ddC                                    ZJddIZK e<e1           e=            eEdddd;ddJ                                    ZL e=            dddd;ddK            ZMddPZN ejO        ejP                  fddUZQ e=dVW          dddVddXddY            ZR e<d>dZ           e=dVW          dddVddXdd[                        ZS e<d>dZ          dddVddXdd\            ZTd] ZU eUd^d_`          ZV eUdadb`          ZW e<dc          dddd;dde            ZX e<dc          dddd;ddf            ZY e<d>dZ          eGdddd;ddg                        ZZ e<d>dZ          eGdddd;ddh                        Z[ e<d>dZ          eGddd dd?ddi                        Z\ddkZ] ejO        ejP                  fddmZ^	 dddoZ_ddpZ`dq Za e<d>dZ          drddsddz            Zbdd|Zc e<d>dZ          ddVd}dd~            Zdd Zed Zf efejg                  Zh efeji                  Zj efejk                  Zl efejm                  Zn efejo                  Zp efejq                  ZrddZsdS )    )annotationsN)AnyCallablecast)
get_option)NaTNaTTypeiNaTlib)		ArrayLikeAxisIntCorrelationMethodDtypeDtypeObjFScalarShapenpt)import_optional_dependency)find_stack_level)is_any_int_dtypeis_bool_dtype
is_complexis_datetime64_any_dtypeis_floatis_float_dtype
is_integeris_integer_dtypeis_numeric_dtypeis_object_dtype	is_scalaris_timedelta64_dtypeneeds_i8_conversionpandas_dtype)PeriodDtype)isnana_value_for_dtypenotna)extract_array
bottleneckwarn)errorsFTvboolreturnNonec                    t           r| ad S d S N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)r-   s    N/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/core/nanops.pyset_use_bottleneckr6   C   s           zcompute.use_bottleneckc                  0     e Zd Zd fdZddZdd
Z xZS )disallowdtypesr   r/   r0   c                    t                                                       t          d |D                       | _        d S )Nc              3  >   K   | ]}t          |          j        V  d S r2   )r$   type).0dtypes     r5   	<genexpr>z$disallow.__init__.<locals>.<genexpr>P   s-      IIL//4IIIIIIr7   )super__init__tupler:   )selfr:   	__class__s     r5   rB   zdisallow.__init__N   s;    II&IIIIIr7   r.   c                `    t          |d          ot          |j        j        | j                  S )Nr?   )hasattr
issubclassr?   r=   r:   )rD   objs     r5   checkzdisallow.checkR   s'    sG$$PCINDK)P)PPr7   fr   c                p     t          j                   fd            }t          t          |          S )Nc                    t          j        | |                                          }t          fd|D                       r.j                            dd          }t          d| d          	 t          j        d          5   | i |cd d d            S # 1 swxY w Y   d S # t          $ r+}t          | d                   rt          |          | d }~ww xY w)	Nc              3  B   K   | ]}                     |          V  d S r2   )rJ   )r>   rI   rD   s     r5   r@   z0disallow.__call__.<locals>._f.<locals>.<genexpr>Y   s-      77s4::c??777777r7   nan zreduction operation 'z' not allowed for this dtypeignoreinvalidr   )	itertoolschainvaluesany__name__replace	TypeErrornperrstate
ValueErrorr    )argskwargsobj_iterf_nameerK   rD   s        r5   _fzdisallow.__call__.<locals>._fV   sL    tV]]__==H7777h77777 ++E266PFPPP  
[222 . .1d-f--. . . . . . . . . . . . . . . . . .   
 #47++ .#A,,A-s<   3B* BB* B!!B* $B!%B* *
C4&CC	functoolswrapsr   r   )rD   rK   rc   s   `` r5   __call__zdisallow.__call__U   sG    				 	 	 	 	 
		& Ar{{r7   )r:   r   r/   r0   r/   r.   )rK   r   r/   r   )rX   
__module____qualname__rB   rJ   rg   __classcell__)rE   s   @r5   r9   r9   M   so        J J J J J JQ Q Q Q       r7   r9   c                       e Zd Zdd	dZd
dZdS )bottleneck_switchNr/   r0   c                "    || _         || _        d S r2   )namer_   )rD   ro   r_   s      r5   rB   zbottleneck_switch.__init__n   s    	r7   altr   c                      j         pj        	 t          t                    n# t          t
          f$ r d Y nw xY wt          j                  d ddd
 fd	            }t          t          |          S )NTaxisskipnarV   
np.ndarrayrs   AxisInt | Nonert   r.   c                  t          
j                  dk    r(
j                                        D ]\  }}||vr|||<   | j        dk    r%|                    d          t          | |          S t          rw|rut          | j        	          r`|                    dd           =|	                    dd             | fd|i|}t          |          r | f||d|}n | f||d|}n | f||d|}|S )Nr   	min_countmaskrs   rr   )lenr_   itemssizeget_na_for_min_countr4   _bn_ok_dtyper?   pop	_has_infs)rV   rs   rt   kwdskr-   resultrp   bn_funcbn_namerD   s          r5   rK   z%bottleneck_switch.__call__.<locals>.fz   s^    4;!## K--// $ $DAq}}"#Q{aDHH[$9$9$A )666 G6 Gl6<.Q.Q G88FD))1 HHVT***$WV??$?$??F !(( O!$V!N$v!N!N!N!N SJd6JJTJJFFVF$vFFFFMr7   )rV   ru   rs   rv   rt   r.   )
ro   rX   getattrbnAttributeError	NameErrorre   rf   r   r   )rD   rp   rK   r   r   s   `` @@r5   rg   zbottleneck_switch.__call__r   s    )+s|	b'**GG	* 	 	 	GGG	 
		 $(	%	 %	 %	 %	 %	 %	 %	 %	 %	 %	 
	%	N Aqzzs   * A A r2   )r/   r0   )rp   r   r/   r   )rX   ri   rj   rB   rg    r7   r5   rm   rm   m   sA            0 0 0 0 0 0r7   rm   r?   r   ro   strc                J    t          |           st          |           s|dvS dS )N)nansumnanprodnanmeanF)r    r#   )r?   ro   s     r5   r   r      s5    5!! <*=e*D*D < ;;;5r7   c                   t          | t          j                  r0| j        dv r't	          j        |                     d                    S 	 t          j        |                                           S # t          t          f$ r Y dS w xY w)N)f8f4KF)
isinstancer[   ndarrayr?   r   has_infsravelisinfrW   rZ   NotImplementedError)r   s    r5   r   r      s    &"*%% 3<<'' <S 1 1222x##%%%*+   uus   %A2 2BB
fill_valueScalar | Nonec                    ||S t          |           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[   rO   infr   i8maxr
   )r?   r   fill_value_typs      r5   _get_fill_valuer      s`     E !6M''vwV##9Kr7   rV   ru   rt   ry   npt.NDArray[np.bool_] | Nonec                    |Ot          | j                  st          | j                  rdS |st          | j                  rt	          |           }|S )a  
    Compute a mask if and only if necessary.

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

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

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

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

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

    Returns
    -------
    Optional[np.ndarray[bool]]
    N)r   r?   r   r#   r&   )rV   rt   ry   s      r5   _maybe_get_maskr      s]    B |&& 	*:6<*H*H 	4 	 (66 	 <<DKr7   r   r   
str | NoneHtuple[np.ndarray, npt.NDArray[np.bool_] | None, np.dtype, np.dtype, Any]c                   t          |          sJ t          | d          } t          | ||          }| j        }d}t	          | j                  r)t          j        |                     d                    } d}t          |          }t          |||          }|r^|\|Z|
                                rF|s|r+|                                 } t          j        | ||           nt          j        | | |          } |}t          |          st          |          rt          j        t
          j                  }n-t#          |          rt          j        t
          j                  }| ||||fS )a7  
    Utility to get the values view, mask, dtype, dtype_max, and fill_value.

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

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

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

    Returns
    -------
    values : ndarray
        Potential copy of input value array
    mask : Optional[ndarray[bool]]
        Mask for values, if deemed necessary to compute
    dtype : np.dtype
        dtype for values
    dtype_max : np.dtype
        platform independent dtype
    fill_value : Any
        fill value used
    Textract_numpyFi8)r   r   )r!   r)   r   r?   r#   r[   asarrayviewr   r   rW   copyputmaskwherer   r   int64r   float64)	rV   rt   r   r   ry   r?   datetimelikedtype_ok	dtype_maxs	            r5   _get_valuesr     s   \ Z      6666F66400DLEL6<((  FKK--..E""H !*^  J  =4#**@88:: 	= =< =
644444 4%<< I )-"6"6 )HRX&&					 )HRZ((	4	:55r7   c                d    t          |           rdS t          | j        t          j                   S )NF)r#   rH   r=   r[   integerr?   s    r5   r   r   a  s.    5!! u%*bj1111r7   np.dtypec                   | t           u rnt          |          r|t          }t          | t          j                  st          |          r
J d            | |k    rt          j        } t          |           r)t	          j        dd          	                    |          } n't	          j
        |                               |          } | 	                    |d          } n| 	                    |          } nt          |          rt          | t          j                  s| |k    st	          j        |           r(t	          j        d          	                    |          } nt	          j        |           t           j        k    rt%          d          t	          j
        |           	                    |d          } n(| 	                    d                              |          } | S )	zwrap our results if neededNzExpected non-null fill_valuer   nsFr   zoverflow in timedelta operationm8[ns])r   r   r
   r   r[   r   r&   rO   
datetime64astyper   r   r"   isnantimedelta64fabsr   r   r]   )r   r?   r   s      r5   _wrap_resultsr   g  s   }}	 	'	' 9J&"*-- 	*J''GG)GGGG##F|| 6ud33::5AA&))..u55]]5u]55FF ]]5))FF	e	$	$ 9&"*-- 	9##rx'7'7#..55e<<39,, !BCCC &))00U0CC ]]8,,11%88FMr7   funcr   c                x     t          j                   ddddd f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rs   rt   ry   rV   ru   rs   rv   rt   r.   ry   r   c                   | }| j         j        dv }|r|t          |           } | f|||d|}|r4t          ||j         t                    }|s|J t          ||||          }|S )NmMr   )r   )r?   kindr&   r   r
   _mask_datetimelike_result)	rV   rs   rt   ry   r_   orig_valuesr   r   r   s	           r5   new_funcz&_datetimelike_compat.<locals>.new_func  s     |(J6 	 DL<<DfL4TLLVLL 	T"6;+<NNNF T'''264{SSr7   )rV   ru   rs   rv   rt   r.   ry   r   rd   )r   r   s   ` r5   _datetimelike_compatr     s_     _T  $-1       0 8r7   rs   rv   Scalar | np.ndarrayc                   t          |           r|                     d          } t          | j                  }| j        dk    r|S ||S | j        d|         | j        |dz   d         z   }t          j        ||| j                  S )a  
    Return the missing value for `values`.

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

    Returns
    -------
    result : scalar or ndarray
        For 1-D values, returns a scalar of the correct missing type.
        For 2-D values, returns a 1-D array where each element is missing.
    r      Nr   )r   r   r'   r?   ndimshaper[   full)rV   rs   r   result_shapes       r5   r~   r~     s    "  *y))#FL11J{a	|ETE*V\$(**-EEw|Zv|DDDDr7   c                t     t          j                   ddd f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rs   rV   ru   rs   rv   c                  |dk    r| j         dk    r| j        d         r| j        d         dz  | j        d         k    r| j        t          k    r| j        t
          k    rt          |                               d          A                    d          fdt          t                              D             }nfdD             }t          j        |          S  | fd	|iS )
Nr      C_CONTIGUOUSi  r   ry   c                >    g | ]} |         fd |         iS ry   r   )r>   iarrsr   r_   ry   s     r5   
<listcomp>z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>  sE       >?DDa99tAw9&99  r7   c                "    g | ]} |fi S r   r   )r>   xr   r_   s     r5   r   z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>  s+    ;;;44,,V,,;;;r7   rs   )r   flagsr   r?   objectr.   listr}   r   rangerz   r[   array)rV   rs   r_   resultsr   ry   r   s     ` @@r5   newfuncz&maybe_operate_rowwise.<locals>.newfunc  s%    AIIq  ^, ! a4'6<?::&&$$<<Dzz&!!-zz&))      CHTCSCS   <;;;;d;;;8G$$$tF000000r7   )rV   ru   rs   rv   rd   )r   r   s   ` r5   maybe_operate_rowwiser     sW     _T>B 1 1 1 1 1 1 1 1. 7r7   r   c               H   t          | j                  r8| j        j        dk    r(t          j        dt
          t                                 t          | |d|          \  } }}}}t          |           r| 	                    t                    } |                     |          S )a  
    Check if any elements along an axis evaluate to True.

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

    Returns
    -------
    result : bool

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

    >>> from pandas.core import nanops
    >>> s = pd.Series([np.nan])
    >>> nanops.nanany(s)
    False
    r   zz'any' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).any() instead.
stacklevelFr   ry   )r#   r?   r   warningsr+   FutureWarningr   r   r    r   r.   rW   rV   rs   rt   ry   _s        r5   nananyr     s    D 6<(( 
V\->#-E-EJ'))		
 	
 	
 	
 %VVDQQQFAq!Q v %t$$ ::dr7   c               H   t          | j                  r8| j        j        dk    r(t          j        dt
          t                                 t          | |d|          \  } }}}}t          |           r| 	                    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)
    True

    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 0])
    >>> nanops.nanall(s)
    False
    r   zz'all' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).all() instead.r   Tr   )r#   r?   r   r   r+   r   r   r   r    r   r.   allr   s        r5   nanallr   *  s    D 6<(( 
V\->#-E-EJ'))		
 	
 	
 	
 %VV4PPPFAq!Q v %t$$ ::dr7   M8)rs   rt   rx   ry   rx   intfloatc                  t          | |d|          \  } }}}}|}t          |          r|}n-t          |          rt          j        t          j                  }|                     ||          }	t          |	||| j        |          }	|	S )a  
    Sum the elements along an axis ignoring NaNs

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

    Returns
    -------
    result : dtype

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nansum(s)
    3.0
    r   r   r   rx   )	r   r   r"   r[   r?   r   sum_maybe_null_outr   )
rV   rs   rt   rx   ry   r?   r   r   	dtype_sumthe_sums
             r5   r   r   a  s    D )414) ) )%FD%A Ie )			e	$	$ )HRZ((	jjYj//GgtT6<9UUUGNr7   r   +np.ndarray | np.datetime64 | np.timedelta64npt.NDArray[np.bool_]r   5np.ndarray | np.datetime64 | np.timedelta64 | NaTTypec                `   t          | t          j                  rN|                     d                              |j                  } |                    |          }t          | |<   nE|                                r1t          j        t                                        |j                  S | S )Nr   r   )	r   r[   r   r   r   r?   rW   r
   r   )r   rs   ry   r   	axis_masks        r5   r   r     s     &"*%% 	:t$$))+*;<<HH$H''	 !y88:: 	:8D>>&&{'8999Mr7   c                  t          | |d|          \  } }}}}|}t          j        t          j                  }|j        dv rt          j        t          j                  }nAt          |          rt          j        t          j                  }nt          |          r|}|}t          | j        |||          }	t          | 
                    ||                    }
|t          |
dd          rvt          t          j        |	          }	t          j        d	          5  |
|	z  }ddd           n# 1 swxY w Y   |	dk    }|                                rt          j        ||<   n|	dk    r|
|	z  nt          j        }|S )
a  
    Compute the mean of the element along an axis ignoring NaNs

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

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanmean(s)
    1.5
    r   r   r   r   Nr   FrQ   r   )r   r[   r?   r   r   r   r   _get_countsr   _ensure_numericr   r   r   r   r\   rW   rO   )rV   rs   rt   ry   r?   r   r   r   dtype_countcountr  the_meanct_masks                r5   r   r     s   D )414) ) )%FD%A I(2:&&K zZHRZ((			%	 	  HRZ((					 	dDDDDEfjjYj??@@GGGVU;;RZ''[X&&& 	' 	'H	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 1*;;== 	' "HW&+aii7U??RVOs   !D33D7:D7c                  d	fd	}t          | |d          \  } }}}}t          | j                  sF	 |                     d          } n/# t          $ r"}t          t          |                    |d}~ww xY w|t          j        | |<   | j	        }| j
        dk    r||rust          j        |||           }	nt          j                    5  t          j        ddt                     t          j        | |          }	ddd           n# 1 swxY w Y   nFt#          | j        |t          j        t          j                  }	n|r || |          nt          j        }	t)          |	|          S )
a  
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 2])
    >>> nanops.nanmedian(s)
    2.0
    Nc                6   |t          |           }n| }s |                                st          j        S t	          j                    5  t	          j        ddt                     t          j        | |                   }d d d            n# 1 swxY w Y   |S )NrQ   All-NaN slice encountered)	r(   r   r[   rO   r   catch_warningsfilterwarningsRuntimeWarning	nanmedian)r   _maskresrt   s      r5   
get_medianznanmedian.<locals>.get_median   s    =!HHEEFE 	eiikk 	6M$&& 	) 	)#5~   ,qx((C	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 
s   6BBBr   )ry   r   r   r   rQ   r  r2   )r   r   r?   r   r]   rZ   r   r[   rO   r|   r   apply_along_axisr   r  r  r  r  get_empty_reduction_resultr   float_r   )
rV   rs   rt   ry   r  r?   r   errnotemptyr  s
     `       r5   r  r    s   2      !,FFRS T T TFD%A&,'' /	/]]4((FF 	/ 	/ 	/CHH%%3.	/ vt{H {Q4+ 	T 
5)*dFCC ,.. 5 5+ "=~   ,vt44C5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 -V\4BFSSCC +3>jj&&&e$$$s)   A 
A8A33A81DDDr   tuple[int, ...]r   np.dtype | type[np.floating]c                    t          j        |           }t          j        t          |                     }t          j        |||k             |          }|                    |           |S )z
    The result from a reduction on an empty ndarray.

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

    Returns
    -------
    np.ndarray
    r   )r[   r   arangerz   emptyfill)r   rs   r?   r   shpdimsrets          r5   r  r  8  sZ    ( (5//C9SZZ  D
(3tt|$E
2
2
2CHHZJr7   values_shaper   ddof-tuple[float | np.ndarray, float | np.ndarray]c                   t          | |||          }||                    |          z
  }t          |          r||k    rt          j        }t          j        }ntt          t          j        |          }||k    }|                                r@t          j        ||t          j                   t          j        ||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!   r[   rO   r   r   rW   r   )r'  ry   rs   r(  r?   r  ds          r5   _get_counts_nanvarr,  S  s    : dD>>>E

4   A  
,D==FEA RZ''}88:: 	,Jq$'''JudBF+++!8Or7   r   r(  rs   rt   r(  ry   c          	         | j         dk    r|                     d          } | j         }t          | ||          \  } }}}}t          j        t          | ||||                    }t          ||          S )a  
    Compute the standard deviation along given axis while ignoring NaNs

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

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanstd(s)
    1.0
    zM8[ns]r   r   r.  )r?   r   r   r[   sqrtnanvarr   )rV   rs   rt   r(  ry   
orig_dtyper   r   s           r5   nanstdr3    s{    H |xX&&J'TBBBFD!QWVFf4dSSSTTF,,,r7   m8c               :   t          | d          } | j        }t          | ||          }t          |          r&|                     d          } |t
          j        | |<   t          | j                  r!t          | j	        |||| j                  \  }}nt          | j	        |||          \  }}|r,|*| 
                                } t          j        | |d           t          |                     |t
          j                            |z  }|t          j        ||          }t          || z
  dz            }	|t          j        |	|d           |	                    |t
          j                  |z  }
t          |          r|
                    |d	          }
|
S )
a  
    Compute the variance along given axis while ignoring NaNs

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

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanvar(s)
    1.0
    Tr   r   Nr   )rs   r?   r   Fr   )r)   r?   r   r   r   r[   rO   r   r,  r   r   r   r
  r   r   expand_dims)rV   rs   rt   r(  ry   r?   r  r+  avgsqrr   s              r5   r1  r1    s   J 6666FLE66400D "t$$6F4Lfl## F%flD$flSSqq%flD$EEq $$"

64### &**$bj*AA
B
BU
JCnS$''
3<A-
.
.C

3a   WW$bjW11A5F
 e 2u511Mr7   c                  t          | ||||           t          | ||          }t          | j                  s|                     d          } |s"| |                                rt          j        S t          | j	        |||| j                  \  }}t          | ||||          }t          j
        |          t          j
        |          z  S )a  
    Compute the standard error in the mean along given axis while ignoring NaNs

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

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nansem(s)
     0.5773502691896258
    r.  r   )r1  r   r   r?   r   rW   r[   rO   r,  r   r0  )rV   rs   rt   r(  ry   r  r   vars           r5   nansemr;    s    L 6V$TBBBB66400D&,'' %t$$ d&488::&v!&,dD&,OOHE1
d64
H
H
HC73<<"'%..((r7   c                n     t          d            t          d dd dd fd                        }|S )NrO   )ro   Tr   rV   ru   rs   rv   rt   r.   ry   r   r/   r   c                  t          | ||          \  } }}}}|| j        |         dk    s| j        dk    re	  t          | 	          ||          }|                    t
          j                   nB# t          t          t          f$ r t
          j        }Y nw xY w t          | 	          |          }t          |||| j                  }|S )Nr   ry   r   r   )r   r   r|   r   r#  r[   rO   r   rZ   r]   r   )
rV   rs   rt   ry   r?   r   r   r   r   meths
           r5   	reductionz_nanminmax.<locals>.reduction2  s     6AF>6
 6
 6
2eY
 d!3q!8!8V[A=M=M ...t9EEEBF####"Iz:        +WVT**400F tV\BBs   :A5 5#BB)
rV   ru   rs   rv   rt   r.   ry   r   r/   r   )rm   r   )r?  r   r@  s   `` r5   
_nanminmaxrA  1  sk    L$LL)))  $-1         *). r7   minr   )r   max-infOint | np.ndarrayc                   t          | 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])
    TrD  r>  )r   argmax_maybe_arg_null_outrV   rs   rt   ry   r   r   s         r5   	nanargmaxrK  R  P    N (VRVWWWFD!Q]]4  F tV<<FMr7   c                   t          | 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   argminrI  rJ  s         r5   	nanargminrO    rL  r7   c                  t          | d          } t          | ||          }t          | j                  s,|                     d          } t          | j        ||          }nt          | j        ||| j                  }|r-|+|                                 } t          j	        | |d           n$|s"| |
                                rt          j        S |                     |t          j                  |z  }|t          j        ||          }| |z
  }|r|t          j	        ||d           |dz  }||z  }|                    |t          j                  }	|                    |t          j                  }
t          |	          }	t          |
          }
t          j        dd	          5  ||d
z
  dz  z  |dz
  z  |
|	dz  z  z  }ddd           n# 1 swxY w Y   | j        }t          |          r|                    |d          }t#          |t          j                  r.t          j        |	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)
    1.7320508075688787
    Tr   r   r   Nr   r   rQ   rS   divider   g      ?g      ?Fr      )r)   r   r   r?   r   r	  r   r   r[   r   rW   rO   r   r   r6  _zero_out_fperrr\   r   r   r   )rV   rs   rt   ry   r  meanadjusted	adjusted2	adjusted3m2m3r   r?   s                r5   nanskewr[    s   N 6666F66400D&,'' Jt$$FL$55FL$FLIII $"

64#### (TXXZZ(v::d"*:--5D~dD))}H &$"

8T1%%%!IH$I	t2:	.	.B	t2:	.	.B 
		B			B	Xh	7	7	7 M M519,,	:rBG|LM M M M M M M M M M M M M M M LEe 2u511&"*%% "'1f--FuqyAgg61996MMs   -GGGc                  t          | d          } t          | ||          }t          | j                  s,|                     d          } t          | j        ||          }nt          | j        ||| j                  }|r-|+|                                 } t          j	        | |d           n$|s"| |
                                rt          j        S |                     |t          j                  |z  }|t          j        ||          }| |z
  }|r|t          j	        ||d           |dz  }|dz  }|                    |t          j                  }	|                    |t          j                  }
t          j        dd	          5  d
|dz
  dz  z  |dz
  |d
z
  z  z  }||dz   z  |dz
  z  |
z  }|dz
  |d
z
  z  |	dz  z  }ddd           n# 1 swxY w Y   t!          |          }t!          |          }t#          |t          j                  s|dk     rt          j        S |dk    rdS t          j        dd	          5  ||z  |z
  }ddd           n# 1 swxY w Y   | j        }t          |          r|                    |d          }t#          |t          j                  r-t          j        |dk    d|          }t          j        ||dk     <   |S )a  
    Compute the sample excess kurtosis

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

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

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 1, 3, 2])
    >>> nanops.nankurt(s)
    -1.2892561983471076
    Tr   r   r   Nr   r   rQ   rQ  rS  r      Fr   )r)   r   r   r?   r   r	  r   r   r[   r   rW   rO   r   r   r6  r\   rT  r   r   r   )rV   rs   rt   ry   r  rU  rV  rW  	adjusted4rY  m4adj	numeratordenominatorr   r?   s                   r5   nankurtrc    sj   N 6666F66400D&,'' Jt$$FL$55FL$FLIII $"

64#### (TXXZZ(v::d"*:--5D~dD))}H &$"

8T1%%%!I1I	t2:	.	.B	t2:	.	.B	Xh	7	7	7 8 8519""uqyUQY&?@UQY'5195:	qyUQY/"a%78 8 8 8 8 8 8 8 8 8 8 8 8 8 8  	**I!+..Kk2:..  1996M!1	Xh	7	7	7 / /[(3./ / / / / / / / / / / / / / / LEe 2u511&"*%% #+*Av66FuqyMs$   :GGG	II!$I!c                   t          | ||          }|r||                                 } d| |<   |                     |          }t          |||| j        |          S )a  
    Parameters
    ----------
    values : ndarray[dtype]
    axis : int, optional
    skipna : bool, default True
    min_count: int, default 0
    mask : ndarray[bool], optional
        nan-mask if known

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

    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, 3, np.nan])
    >>> nanops.nanprod(s)
    6.0
    Nr   r   )r   r   prodr   r   )rV   rs   rt   rx   ry   r   s         r5   r   r   k  sp    @ 66400D $"t[[F dFLI   r7   np.ndarray | intc                    || S |t          | dd          s0|r|                                rdS n]|                                rdS nF|r|                    |          }n|                    |          }|                                rd| |<   | S )Nr   F)r   r   rW   )r   rs   ry   rt   na_masks        r5   rI  rI    s     ||766599| 	xxzz r xxzz r  	%hhtnnGGhhtnnG;;== 	! F7OMr7   float | np.ndarrayc                h   |H||j         |                                z
  }nt          j        |           }|                    |          S |$|j        |         |                    |          z
  }n| |         }t          |          r|                    |          S |                    |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   )r|   r   r[   re  r=   r   r!   r   )r'  ry   rs   r?   nr  s         r5   r	  r	    s    0 |	DHHJJ&AA%%Azz!}}
4 488D>>1T" !zz%   <<E<***r7   np.ndarray | float | NaTTypec                   ||dk    r| S |t          | t          j                  r|+|j        |         |                    |          z
  |z
  dk     }n<||         |z
  dk     }|d|         ||dz   d         z   }t          j        ||          }t          j        |          rtt          |           r`t          j        |           r| 	                    d          } n&t          |           s| 	                    dd          } t          j        | |<   nbd| |<   n\| t          urSt          |||          rBt          | 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   c16r   Fr   r?   rO   )r   r[   r   r   r   broadcast_torW   r   iscomplexobjr   r   rO   r   check_below_min_countr   r=   )	r   rs   ry   r   rx   	null_maskbelow_count	new_shaperesult_dtypes	            r5   r   r     s    |	QJvrz::D)DHHTNN:YF!KII  +	1A5KeteuTAXZZ'88IY??I6) 		)'' )?6** =#]]511FF'// =#]]4e]<<F$&Fy!! %)y!	s		 i88 	 "67D99Ll++  %**511Mr7   c                    |dk    r;|t          j        |           }n|j        |                                z
  }||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[   re  r|   r   )r   ry   rx   	non_nullss       r5   rr  rr    sJ    ( 1}}<II	DHHJJ.Iy  45r7   c                T   t          | t          j                  r[t          j        d          5  t          j        t          j        |           dk     d|           cd d d            S # 1 swxY w Y   d S t          j        |           dk     r| j                            d          n| S )NrQ   rR   g+=r   )r   r[   r   r\   r   absr?   r=   )args    r5   rT  rT  +  s    #rz"" A[*** 	9 	98BF3KK%/C88	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 %'F3KK%$7$7sy~~a   S@s   ,A))A-0A-pearson)methodmin_periodsabr}  r   r~  
int | Nonec               b   t          |           t          |          k    rt          d          |d}t          |           t          |          z  }|                                s| |         } ||         }t          |           |k     rt          j        S t          |          } || |          S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNr   )rz   AssertionErrorr(   r   r[   rO   get_corr_func)r  r  r}  r~  validrK   s         r5   nancorrr  4  s     1vvQFGGG!HHuQxxE99;; eHeH
1vvvfA1Q77Nr7   )Callable[[np.ndarray, np.ndarray], float]c                    | dk    rddl m fd}|S | dk    rddl m fd}|S | dk    rd	 }|S t          |           r| S t	          d
|  d          )Nkendallr   )
kendalltauc                (     | |          d         S Nr   r   )r  r  r  s     r5   r   zget_corr_func.<locals>.funcW  s    :a##A&&r7   spearman)	spearmanrc                (     | |          d         S r  r   )r  r  r  s     r5   r   zget_corr_func.<locals>.func^  s    9Q??1%%r7   r|  c                8    t          j        | |          d         S )Nr   r   )r[   corrcoef)r  r  s     r5   r   zget_corr_func.<locals>.funcd  s    ;q!$$T**r7   zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)scipy.statsr  r  callabler]   )r}  r   r  r  s     @@r5   r  r  Q  s     ******	' 	' 	' 	' 	' 	:		))))))	& 	& 	& 	& 	& 	9			+ 	+ 	+ 	&		 
	86 	8 	8 	8  r7   )r~  r(  c               f   t          |           t          |          k    rt          d          |d}t          |           t          |          z  }|                                s| |         } ||         }t          |           |k     rt          j        S t	          j        | ||          d         S )Nz&Operands to nancov must have same sizer   r-  r  )rz   r  r(   r   r[   rO   cov)r  r  r~  r(  r  s        r5   nancovr  q  s     1vvQEFFF!HHuQxxE99;; eHeH
1vvv6!QT"""4((r7   c                H   t          | t          j                  rt          |           st	          |           r!|                     t          j                  } nHt          |           r	 |                     t          j                  } t          j	        t          j
        |                     s| j        } n# t          t          f$ rJ 	 |                     t          j                  } n&# t          $ r}t          d|  d          |d }~ww xY wY nw xY wnt          |           s}t          |           snt!          |           s_	 t#          |           } nN# t          t          f$ r: 	 t%          |           } n&# t          $ r}t          d|  d          |d }~ww xY wY nw xY w| S )NzCould not convert z to numeric)r   r[   r   r   r   r   r   r    
complex128rW   imagrealrZ   r]   r   r   r   r   complex)r   r  s     r5   r
  r
    s   !RZ   NA 	-"2"2 	$$AAQ 	
HHR]++ vbgajj)) A z* R R RR,,AA! R R R#$G$G$G$GHHcQR AR	 qkk 	NZ]] 	Njmm 	N	NaAA:& 	N 	N 	NNAJJ N N N CQ C C CDD#MN 	N Hsl   *B7 7D	C)(D)
D3DDDDE F&E65F6
F FFFFc                      fd}|S )Nc                p   t          |           }t          |          }||z  }t          j        d          5   | |          }d d d            n# 1 swxY w Y   |                                rDt	          |          r|                    d          }t          j        ||t          j                   |S )NrQ   r  rE  )r&   r[   r\   rW   r   r   r   rO   )r   yxmaskymaskry   r   ops         r5   rK   zmake_nancomp.<locals>.f  s    QQu}[X&&& 	 	R1XXF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 88:: 	-V$$ ,s++JvtRV,,,s   AAAr   )r  rK   s   ` r5   make_nancompr    s#         Hr7   r   c          	     .   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 |rkt          | j        j        t           j        t           j        f          s;|                                 }t          |          }|||<    ||d          }|||<   n || 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[   cumprodrO   maximum
accumulater   cumsumminimumr?   r   rH   r=   r   bool_r   r&   )rV   
accum_funcrt   mask_amask_bvalsry   r   s           r5   na_accum_funcr    s     	
S"&M

0
	C=

/	
 NFF <J....  ,j!2RZ4JKK ,{{}}DzzT
Dq)))tF+++Mr7   )T)r-   r.   r/   r0   )r?   r   ro   r   r/   r.   rh   )NN)r?   r   r   r   )rV   ru   rt   r.   ry   r   r/   r   )NNN)rV   ru   rt   r.   r   r   r   r   ry   r   r/   r   )r?   r   r/   r.   r2   )r?   r   )r   r   r/   r   )rV   ru   rs   rv   r/   r   )
rV   ru   rs   rv   rt   r.   ry   r   r/   r.   )rV   ru   rs   rv   rt   r.   rx   r   ry   r   r/   r   )
r   r  rs   rv   ry   r  r   ru   r/   r  )
rV   ru   rs   rv   rt   r.   ry   r   r/   r   )rs   rv   rt   r.   )
r   r  rs   r   r?   r  r   r   r/   ru   )r'  r   ry   r   rs   rv   r(  r   r?   r   r/   r)  )rs   rv   rt   r.   r(  r   )rV   ru   rs   rv   rt   r.   r(  r   ry   r   r/   r   )
rV   ru   rs   rv   rt   r.   ry   r   r/   rF  )
r   ru   rs   rv   ry   r   rt   r.   r/   rf  )
r'  r   ry   r   rs   rv   r?   r   r/   rj  )r   )r   rm  rs   rv   ry   r   r   r  rx   r   r/   rm  )r   r  ry   r   rx   r   r/   r.   )
r  ru   r  ru   r}  r   r~  r  r/   r   )r}  r   r/   r  )
r  ru   r  ru   r~  r  r(  r  r/   r   )rV   r   rt   r.   r/   r   )t
__future__r   re   rT   operator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   r   r    r!   r"   r#   r$   pandas.core.dtypes.dtypesr%   pandas.core.dtypes.missingr&   r'   r(   pandas.core.constructionr)   r   r3   r4   r6   r9   rm   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   r   r  r  r?   r   r,  r3  r1  r;  rA  nanminnanmaxrK  rO  r[  rc  r   rI  r	  r   rr  rT  r  r  r  r
  r  gtnangtgenangeltnanltlenanleeqnaneqnenanner  r   r7   r5   <module>r     s
   " " " " " "                  
      % % % % % %           
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ? > > > > > 4 4 4 4 4 4                                 2 1 1 1 1 1          3 2 2 2 2 2V<<<$       ::677 8 8 8       @5 5 5 5 5 5 5 5p   (
 
 
 
 GK    ,) ) ) )^ !%)-V6 V6 V6 V6 V6r2 2 2 2& & & & &R   DE E E E>   J  )-4 4 4 4 4 4t  )-4 4 4 4 4 4n 
$  )-+ + + + +   +\   & 
+  )-< < < < <   <~ 04TPT M% M% M% M% M% M%`   @ bhrz**, , , , ,^   	*- *- *- *- *- *-Z 
$  	G G G G G  GT 
$  )-1) 1) 1) 1) 1) 1)h  : 
E&	1	1	1	E&	1	1	1 
#  )-* * * * * *Z 
#  )-* * * * * *Z 
$  )-U U U U U  Up 
$  )-^ ^ ^ ^ ^  ^B 
$  )-( ( ( ( (  (V   > bhrz**	&+ &+ &+ &+ &+\ - - - - -`   >A A A 
$
 !*"     8   @ 
$
 #) ) ) ) ) )0  @  & 	X[!!X[!!X[!!X[!!X[!!X[!!" " " " " "r7   