
    bMh(                       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          Z-e-duZ.da/dddZ0 e0 ed                      G d d          Z1 G d d          Z2ddZ3ddZ4	 ddd"Z5dd(Z6	 	 	 ddd-Z7dd/Z8dd0Z9ddd1Z:dd4Z;dd8Z<dd9Z=dddd:dd;Z>dddd:dd<Z? e1d=          e;e=ddd dd>ddB                                    Z@ddHZA e2            e;dddd:ddI                        ZB e2            dddd:ddJ            ZCddNZD e
jE        e
jF                  fddRZG e2dST          dddSddUddV            ZH e1d=dW           e2dST          dddSddUddX                        ZI e1d=dW          dddSddUddY            ZJdZ ZK eKd[d\]          ZL eKd^d_]          ZMdddd:ddaZNdddd:ddbZO e1d=dW          e=dddd:ddc                        ZP e1d=dW          e=dddd:ddd                        ZQ e1d=dW          e=ddd dd>dde                        ZRddgZS e
jE        e
jF                  fddjZT	 dddmZUddnZVdo ZW e1d=dW          dpddqddx            ZXddzZY e1d=dW          ddSd{dd|            ZZd} Z[ddZ\dS )    )annotationsN)AnyCallablecast)
get_option)NaTNaTTypeiNaTlib)		ArrayLikeAxisIntCorrelationMethodDtypeDtypeObjFScalarShapenpt)import_optional_dependency)find_stack_level)
is_complexis_floatis_float_dtype
is_integeris_numeric_dtypeis_object_dtypeneeds_i8_conversionpandas_dtype)isnana_value_for_dtypenotna
bottleneckwarn)errorsFTvboolreturnNonec                    t           r| ad S d S N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)r%   s    R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/core/nanops.pyset_use_bottleneckr.   9   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'   r(   c                    t                                                       t          d |D                       | _        d S )Nc              3  >   K   | ]}t          |          j        V  d S r*   )r   type).0dtypes     r-   	<genexpr>z$disallow.__init__.<locals>.<genexpr>F   s-      IIL//4IIIIIIr/   )super__init__tupler2   )selfr2   	__class__s     r-   r:   zdisallow.__init__D   s;    II&IIIIIr/   r&   c                `    t          |d          ot          |j        j        | j                  S )Nr7   )hasattr
issubclassr7   r5   r2   )r<   objs     r-   checkzdisallow.checkH   s'    sG$$PCINDK)P)PPr/   fr   c                p     t          j                   fd            }t          t          |          S )Nc                 f   t          j        | |                                          }t          fd|D                       r.j                            dd          }t          d| d          	  | i |S # t          $ r+}t          | d                   rt          |          | d }~ww xY w)Nc              3  B   K   | ]}                     |          V  d S r*   )rB   )r6   rA   r<   s     r-   r8   z0disallow.__call__.<locals>._f.<locals>.<genexpr>O   s-      77s4::c??777777r/   nan zreduction operation 'z' not allowed for this dtyper   )		itertoolschainvaluesany__name__replace	TypeError
ValueErrorr   )argskwargsobj_iterf_nameerC   r<   s        r-   _fzdisallow.__call__.<locals>._fL   s     tV]]__==H7777h77777 ++E266PFPPP  	q$)&)))   
 #47++ .#A,,A-s   3A; ;
B0&B++B0	functoolswrapsr   r   )r<   rC   rV   s   `` r-   __call__zdisallow.__call__K   sG    				 	 	 	 	 
		$ Ar{{r/   )r2   r   r'   r(   r'   r&   )rC   r   r'   r   )rM   
__module____qualname__r:   rB   rZ   __classcell__)r=   s   @r-   r1   r1   C   so        J J J J J JQ Q Q Q       r/   r1   c                       e Zd Zdd	dZd
dZdS )bottleneck_switchNr'   r(   c                "    || _         || _        d S r*   )namerR   )r<   rb   rR   s      r-   r:   zbottleneck_switch.__init__c   s    	r/   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skipnarK   
np.ndarrayrf   AxisInt | Nonerg   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maskrf   re   )lenrR   itemssizeget_na_for_min_countr,   _bn_ok_dtyper7   pop	_has_infs)rK   rf   rg   kwdskr%   resultrc   bn_funcbn_namer<   s          r-   rC   z%bottleneck_switch.__call__.<locals>.fo   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Mr/   )rK   rh   rf   ri   rg   r&   )
rb   rM   getattrbnAttributeError	NameErrorrX   rY   r   r   )r<   rc   rC   rx   ry   s   `` @@r-   rZ   zbottleneck_switch.__call__g   s    )+s|	b'**GG	* 	 	 	GGG	 
		 $(	%	 %	 %	 %	 %	 %	 %	 %	 %	 %	 
	%	N Aqzzs   * A A r*   )r'   r(   )rc   r   r'   r   )rM   r\   r]   r:   rZ    r/   r-   r`   r`   b   sA            0 0 0 0 0 0r/   r`   r7   r   rb   strc                B    | t           k    rt          |           s|dvS dS )N)nansumnanprodnanmeanF)objectr   )r7   rb   s     r-   rr   rr      s+    2599 ;;;5r/   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)
isinstancenpndarrayr7   r   has_infsravelisinfrL   rO   NotImplementedError)rw   s    r-   rt   rt      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   rG   infr   i8maxr
   )r7   r   fill_value_typs      r-   _get_fill_valuer      s`     E !6M''vwV##9Kr/   rK   rh   rg   rl   npt.NDArray[np.bool_] | Nonec                h    |/| 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)r7   kindr   )rK   rg   rl   s      r-   _maybe_get_maskr      sF    B |<%%4 	 V\&$..<<DKr/   r   r   
str | None/tuple[np.ndarray, npt.NDArray[np.bool_] | None]c                   t          | ||          }| j        }d}| j        j        dv r)t          j        |                     d                    } d}|r}|{t          |||          }|g|                                rS|st          |          r+| 	                                } t          j
        | ||           nt          j        | | |          } | |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   r7   r   r   asarrayviewr   rL   r   copyputmaskwhere)rK   rg   r   r   rl   r7   datetimelikes          r-   _get_valuesr      s    R 66400DLEL|D   FKK--.. A4# %j
 
 

 !xxzz A A<#6#6 A#[[]]FJvtZ8888  XteVZ@@F4<r/   np.dtypec                    | }| j         dv rt          j        t          j                  }nS| j         dk    rt          j        t          j                  }n)| j         dk    rt          j        t          j                  }|S )NbiurC   )r   r   r7   int64uint64float64)r7   	dtype_maxs     r-   _get_dtype_maxr   D  sk    IzTHRX&&			s		HRY''			s		HRZ((	r/   c                d    t          |           rdS t          | j        t          j                   S )NF)r   r@   r5   r   integerr7   s    r-   r   r   P  s.    5!! u%*bj1111r/   c                   | t           u rn|j        dk    r|t          }t          | t          j                  st          |          r
J d            | |k    rt          j        } t          |           r)t	          j        dd          	                    |          } n't	          j
        |                               |          } | 	                    |d          } n | 	                    |          } n|j        dk    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 neededMNzExpected non-null fill_valuer   nsFr   mzoverflow in timedelta operationm8[ns])r   r   r
   r   r   r   r   rG   
datetime64astyper   r   isnantimedelta64fabsr   r   rP   )rw   r7   r   s      r-   _wrap_resultsr   V  s   }}	s		J&"*-- 	*J''GG)GGGG##F|| 6ud33::5AA&))..u55]]5u]55FF ]]5))FF	s		&"*-- 	9##rx'7'7#..55e<<39,, !BCCC &))00U0CC ]]8,,11%88FMr/   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rf   rg   rl   rK   rh   rf   ri   rg   r&   rl   r   c                   | }| j         j        dv }|r|t          |           } | f|||d|}|r4t          ||j         t                    }|s|J t          ||||          }|S )Nr   r   )r   )r7   r   r   r   r
   _mask_datetimelike_result)	rK   rf   rg   rl   rR   orig_valuesr   rw   r   s	           r-   new_funcz&_datetimelike_compat.<locals>.new_func  s     |(D0 	 DL<<DfL4TLLVLL 	T"6;+<NNNF T'''264{SSr/   rK   rh   rf   ri   rg   r&   rl   r   rW   )r   r   s   ` r-   _datetimelike_compatr     s_     _T  $-1       0 8r/   rf   ri   Scalar | np.ndarrayc                   | j         j        dv 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.
    iufcbr      Nr   )r7   r   r   r    ndimshaper   full)rK   rf   r   result_shapes       r-   rq   rq     s    " |G##y))#FL11J{a	|ETE*V\$(**-EEw|Zv|DDDDr/   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rf   rK   rh   rf   ri   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   rl   c                >    g | ]} |         fd |         iS rl   r~   )r6   iarrsr   rR   rl   s     r-   
<listcomp>z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>  sE       >?DDa99tAw9&99  r/   c                "    g | ]} |fi S r~   r~   )r6   xr   rR   s     r-   r   z:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>  s+    ;;;44,,V,,;;;r/   rf   )r   flagsr   r7   r   r&   listrp   rs   rangerm   r   array)rK   rf   rR   resultsr   rl   r   s     ` @@r-   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0r/   )rK   rh   rf   ri   rW   )r   r   s   ` r-   maybe_operate_rowwiser     sW     _T>B 1 1 1 1 1 1 1 1. 7r/   r   c               f   | j         j        dv r||                     |          S | j         j        dk    r(t          j        dt
          t                                 t          | |d|          \  } }| j         t          k    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.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   rl   )r7   r   rL   warningsr#   FutureWarningr   r   r   r   r&   rK   rf   rg   rl   _s        r-   nananyr     s    D |E!!dl zz$|CJ'))		
 	
 	
 	
 FFu4HHHIFA |vt$$ ::dr/   c               f   | j         j        dv r||                     |          S | j         j        dk    r(t          j        dt
          t                                 t          | |d|          \  } }| j         t          k    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.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   )r7   r   allr   r#   r   r   r   r   r   r&   r   s        r-   nanallr     s    D |E!!dl zz$|CJ'))		
 	
 	
 	
 FFt$GGGIFA |vt$$ ::dr/   M8)rf   rg   rk   rl   rk   intfloatc               ,   | j         }t          | |d|          \  } }t          |          }|j        dk    r|}n)|j        dk    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.values)
    3.0
    r   r   rC   r   r   rk   )	r7   r   r   r   r   r   sum_maybe_null_outr   )rK   rf   rg   rk   rl   r7   	dtype_sumthe_sums           r-   r   r   \  s    D LEvv!$GGGLFDu%%IzS			s		HRZ((	jjYj//GgtT6<9UUUGNr/   rw   +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   r7   rL   r
   r   )rw   rf   rl   r   	axis_masks        r-   r   r     s     &"*%% 	:t$$))+*;<<HH$H''	 !y88:: 	:8D>>&&{'8999Mr/   c                  | j         }t          | |d|          \  } }t          |          }t          j         t          j                  }|j        dv rt          j         t          j                  }n7|j        dv rt          j         t          j                  }n|j        dk    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.values)
    1.5
    r   r   r   iurC   r   Nr   Fignore)r   )r7   r   r   r   r   r   _get_countsr   r   _ensure_numericrz   r   r   errstaterL   rG   )rK   rf   rg   rl   r7   r   dtype_countcountr   the_meanct_masks              r-   r   r     s   B LEvv!$GGGLFDu%%I(2:&&K zTHRZ((			t		HRZ((			s			dDDDDEjjYj//Gg&&GGGVU;;RZ''[X&&& 	' 	'H	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 1*;;== 	' "HW&+aii7U??RVOs   *D<<E E c               @   | j         j        dk    o|du }dfd	}| j         }t          | |d          \  } }| j         j        dk    r| j         t          k    r+t	          j        |           }|dv rt          d|  d          	 |                     d          } n/# t          $ r"}t          t          |                    |d}~ww xY w|s1|/| j
        j        s|                                 } t          j        | |<   | j        }	| j        d	k    r||	r͉st          j        |||           }
nt%          j                    5  t%          j        d
dt*                     | j        d	         d	k    r|dk    s| j        d         d	k    r/|d	k    r)t          j        t          j        |           d          }
nt          j        | |          }
ddd           n# 1 swxY w Y   n0t3          | j        |          }
n|	r || |          nt          j        }
t5          |
|          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
    rC   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 )Nr  All-NaN slice encountered)	r!   r   r   rG   r   catch_warningsfilterwarningsRuntimeWarning	nanmedian)r   _maskresrg   s      r-   
get_medianznanmedian.<locals>.get_median  s    =!HHEEFE 	eiikk 	6M$&& 	) 	)#5~   ,qx((C	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 
s   6BBB)rl   r   stringmixedzCannot convert  to numericr   r   r  r  r   T)keepdimsr   r*   )r7   r   r   r   r   infer_dtyperO   r   rP   r   r   	writeabler   r   rG   ro   r   apply_along_axisr   r  r  r  r   r  squeeze_get_empty_reduction_resultr   )rK   rf   rg   rl   using_nan_sentinelr  r7   inferrederrnotemptyr  s     `        r-   r  r    s   6  *c1Bddl      LEvvDTJJJLFD|C<6!!v..H... E& E E EFFF	/]]4((FF 	/ 	/ 	/CHH%%3.	/  $"2|% 	#[[]]Fvt{H {Q4+ 	B >)*dFCC ,.. > >+ "=~   Q1,,Q1,, !l2:f+=+=MMM l6===> > > > > > > > > > > > > > >$ .flDAACC +3>jj&&&e$$$s+   B 
C%CC?B	GGGr   r   r   c                   t          j        |           }t          j        t          |                     }t          j        |||k             t           j                  }|                    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   arangerm   emptyr   fillrG   )r   rf   shpdimsrets        r-   r  r  C  s^      (5//C9SZZ  D
(3tt|$BJ
7
7
7CHHRVJr/   values_shape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  r5   r   r   rG   r   r   rL   r   )r*  rl   rf   r+  r7   r  ds          r-   _get_counts_nanvarr/  Z  s    : dD>>>E

4   A  ,D== FEA RZ''}88:: 	,Jq$'''JudBF+++!8Or/   r   r+  rf   rg   r+  rl   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.values)
    1.0
    zM8[ns]r   r   r1  )r7   r   r   r   sqrtnanvarr   )rK   rf   rg   r+  rl   
orig_dtyperw   s          r-   nanstdr6    st    H |xX&&JvvD999LFDWVFf4dSSSTTF,,,r/   m8c                  | j         }t          | ||          }|j        dv r&|                     d          } |t          j        | |<   | j         j        dk    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  }
|j        dk    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.values)
    1.0
    r  r   NrC   r   )rf   r7   r   Fr   )r7   r   r   r   r   rG   r/  r   r   r   r  r   r   expand_dims)rK   rf   rg   r+  rl   r7   r  r.  avgsqrrw   s              r-   r4  r4    st   J LE66400DzTt$$6F4L|C%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
 zSu511Mr/   c                  t          | ||||           t          | ||          }| j        j        dk    r|                     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.values)
     0.5773502691896258
    r1  rC   r   )r4  r   r7   r   r   rL   r   rG   r/  r   r3  )rK   rf   rg   r+  rl   r  r   vars           r-   nansemr>    s    L 6V$TBBBB66400D|Ct$$ d&488::&v!&,dD&,OOHE1
d64
H
H
HC73<<"'%..((r/   c                n     t          d            t          d dd dd fd                        }|S )NrG   )rb   Tr   rK   rh   rf   ri   rg   r&   rl   r   c                   | j         dk    rt          | |          S t          | ||          \  } } t          |           |          }t	          |||| j                  }|S )Nr   r   rl   )ro   rq   r   rz   r   r   )rK   rf   rg   rl   rw   r   meths        r-   	reductionz_nanminmax.<locals>.reduction;  sx     ;!$VT222"F>
 
 
 '&&t,, tV\BBr/   r   )r`   r   )rB  r   rC  s   `` r-   
_nanminmaxrD  :  sk    L$LL)))  $-1         *)" r/   minr   )r   max-inf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])
    TrG  rA  )r   argmax_maybe_arg_null_outrK   rf   rg   rl   rw   s        r-   	nanargmaxrM  U  J    L vtFNNNLFD]]4  F !tV<<FMr/   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   rA  )r   argminrK  rL  s        r-   	nanargminrQ    rN  r/   c               4   t          | ||          }| j        j        dk    r,|                     d          } t	          | j        ||          }nt	          | j        ||| j                  }|r-|+|                                 } t          j        | |d           n$|s"| |	                                rt          j
        S t          j        dd          5  |                     |t          j                  |z  }ddd           n# 1 swxY w Y   |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        }|j        dk    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.values)
    1.7320508075688787
    rC   r   r   Nr   r  invaliddivider   r   g      ?g      ?Fr      )r   r7   r   r   r  r   r   r   r   rL   rG   r  r   r   r9  _zero_out_fperrr   r   r   r5   )rK   rf   rg   rl   r  meanadjusted	adjusted2	adjusted3m2m3rw   r7   s                r-   nanskewr^    s   J 66400D|Ct$$FL$55FL$FLIII $"

64#### (TXXZZ(v	Xh	7	7	7 : :zz$bjz11E9: : : : : : : : : : : : : : :~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zSu511&"*%% "'1f--Fuqy"$''Av1996MMs$   %DD	D	G--G14G1c                  t          | ||          }| j        j        dk    r,|                     d          } t	          | j        ||          }nt	          | j        ||| j                  }|r-|+|                                 } t          j        | |d           n$|s"| |	                                rt          j
        S t          j        dd          5  |                     |t          j                  |z  }ddd           n# 1 swxY w Y   |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                  s2|dk     rt          j
        S |dk    r| j                            d          S t          j        dd          5  ||z  |z
  }ddd           n# 1 swxY w Y   | j        }|j        dk    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.values)
    -1.2892561983471076
    rC   r   r   Nr   r  rS  r   rV  r      Fr   )r   r7   r   r   r  r   r   r   r   rL   rG   r  r   r   r9  rW  r   r   r5   r   )rK   rf   rg   rl   r  rX  rY  rZ  	adjusted4r\  m4adj	numeratordenominatorrw   r7   s                   r-   nankurtrf  	  s   J 66400D|Ct$$FL$55FL$FLIII $"

64#### (TXXZZ(v	Xh	7	7	7 : :zz$bjz11E9: : : : : : : : : : : : : : :~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!<$$Q'''	Xh	7	7	7 / /[(3./ / / / / / / / / / / / / / / LEzSu511&"*%% #+*Av66FuqyMs6   %DD	D	(:G..G25G29	JJJ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.values)
    6.0
    Nr   r   )r   r   prodr   r   )rK   rf   rg   rk   rl   rw   s         r-   r   r   j  sp    @ 66400D $"t[[F dFLI   r/   np.ndarray | intc                    || S |t          | dd          s0|r|                                rdS n]|                                rdS nF|r|                    |          }n|                    |          }|                                rd| |<   | S )Nr   F)rz   r   rL   )rw   rf   rl   rg   na_masks        r-   rK  rK    s     ||766599| 	xxzz r xxzz r  	%hhtnnGGhhtnnG;;== 	! F7OMr/   np.dtype[np.floating]&np.floating | npt.NDArray[np.floating]c                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   )ro   r   r   rh  r5   r   r   r   )r*  rl   rf   r7   nr  s         r-   r  r    s    0 |	DHHJJ&AA%%Azz!}}
4 488D>>1T"% !zz%   <<E<***r/   np.ndarray | float | NaTTypetuple[int, ...]c                   ||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   r7   rG   )r   r   r   r   r   broadcast_torL   r   iscomplexobjr   r   rG   r   check_below_min_countrz   r5   )	rw   rf   rl   r   rk   	null_maskbelow_count	new_shaperesult_dtypes	            r-   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Mr/   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   rh  ro   r   )r   rl   rk   	non_nullss       r-   rw  rw    sJ    ( 1}}<II	DHHJJ.Iy  45r/   c                    t          | t          j                  r,t          j        t          j        |           dk     d|           S t          j        |           dk     r| j                            d          n| S )Ng+=r   )r   r   r   r   absr7   r5   )args    r-   rW  rW  *  sc    #rz"" Axse+Q444$&F3KK%$7$7sy~~a   S@r/   pearson)methodmin_periodsabr  r   r  
int | Nonec                  t          |           t          |          k    rt          d          |d}t          |           t          |          z  }|                                s| |         } ||         }t          |           |k     rt          j        S t          |           } t          |          }t          |          } || |          S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNr   )rm   AssertionErrorr!   r   r   rG   r  get_corr_func)r  r  r  r  validrC   s         r-   nancorrr  2  s     1vvQFGGG!HHuQxxE99;; eHeH
1vvvAAfA1Q77Nr/   )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     r-   r   zget_corr_func.<locals>.funcX  s    :a##A&&r/   spearman)	spearmanrc                (     | |          d         S r  r~   )r  r  r  s     r-   r   zget_corr_func.<locals>.func_  s    9Q??1%%r/   r  c                8    t          j        | |          d         S )Nr   r   )r   corrcoef)r  r  s     r-   r   zget_corr_func.<locals>.funce  s    ;q!$$T**r/   zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)scipy.statsr  r  callablerP   )r  r   r  r  s     @@r-   r  r  R  s     ******	' 	' 	' 	' 	' 	:		))))))	& 	& 	& 	& 	& 	9			+ 	+ 	+ 	&		 
	86 	8 	8 	8  r/   )r  r+  c                  t          |           t          |          k    rt          d          |d}t          |           t          |          z  }|                                s| |         } ||         }t          |           |k     rt          j        S t          |           } t          |          }t	          j        | ||          d         S )Nz&Operands to nancov must have same sizer   r0  r  )rm   r  r!   r   r   rG   r  cov)r  r  r  r+  r  s        r-   nancovr  r  s     1vvQEFFF!HHuQxxE99;; eHeH
1vvvAA6!QT"""4((r/   c                   t          | t          j                  r| j        j        dv r!|                     t          j                  } n| j        t          k    rt          j	        |           }|dv rt          d|  d          	 |                     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!          |           st#          |           st%          |           st          | t&                    rt          d|  d          	 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 )Nr   r  zCould not convert r  zCould not convert string 'z' to numeric)r   r   r   r7   r   r   r   r   r   r  rO   
complex128rL   imagrealrP   r   r   r   r   r   complex)r   r   r!  s      r-   r  r    s6   !RZ   N7<5  $$AAWq))H... CQ C C CDDD
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a 	JHHHHIII	NaAA:& 	N 	N 	NNAJJ N N N CQ C C CDD#MN 	N Hsl   C D0'DD0
D*D%%D**D0/D0
F G%,F<;G%<
GGGG%$G%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   cumprodrG   maximum
accumulater   cumsumminimumr7   r   r@   r5   r   bool_r   r   )rK   
accum_funcrg   mask_amask_bvalsrl   rw   s           r-   na_accum_funcr    s     	
S"&M

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

/	
 NFF <D((((  ,j!2RZ4JKK ,{{}}DzzT
Dq)))tF+++Mr/   )T)r%   r&   r'   r(   )r7   r   rb   r   r'   r&   r[   )NN)r7   r   r   r   )rK   rh   rg   r&   rl   r   r'   r   )NNN)rK   rh   rg   r&   r   r   r   r   rl   r   r'   r   )r7   r   r'   r   )r7   r   r'   r&   r*   )r7   r   )r   r   r'   r   )rK   rh   rf   ri   r'   r   )
rK   rh   rf   ri   rg   r&   rl   r   r'   r&   )rK   rh   rf   ri   rg   r&   rk   r   rl   r   r'   r   )
rw   r   rf   ri   rl   r   r   rh   r'   r   )
rK   rh   rf   ri   rg   r&   rl   r   r'   r   )rf   ri   rg   r&   )r   r   rf   r   r'   rh   )r*  r   rl   r   rf   ri   r+  r   r7   r   r'   r,  )rf   ri   rg   r&   r+  r   )rK   rh   rf   ri   rg   r&   r+  r   )rK   rh   rf   ri   rg   r&   r+  r   rl   r   r'   r   )
rK   rh   rf   ri   rg   r&   rl   r   r'   rH  )
rw   rh   rf   ri   rl   r   rg   r&   r'   ri  )
r*  r   rl   r   rf   ri   r7   rm  r'   rn  )r   )rw   rq  rf   ri   rl   r   r   rr  rk   r   r'   rq  )r   rr  rl   r   rk   r   r'   r&   )
r  rh   r  rh   r  r   r  r  r'   r   )r  r   r'   r  )
r  rh   r  rh   r  r  r+  r  r'   r   )rK   r   rg   r&   r'   r   )]
__future__r   rX   rI   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!   r{   r+   r,   r.   r1   r`   rr   rt   r   r   r   r   r   r   r   rq   r   r   r   r   r   r   r  r  r7   r   r/  r6  r4  r>  rD  nanminnanmaxrM  rQ  r^  rf  r   rK  r  r   rw  rW  r  r  r  r  r  r~   r/   r-   <module>r     s   " " " " " "                 
      % % % % % %           
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ? > > > > > 4 4 4 4 4 4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	           V<<<$       ::677 8 8 8       >5 5 5 5 5 5 5 5p   (
 
 
 
 GK    ,) ) ) )^ !%)-D D D D DN	 	 	 	2 2 2 2& & & & &R   DE E E E>   J  )-: : : : : :@  )-: : : : : :z 
$  )-* * * * *   *Z   &   )-< < < < <  <~ 04TPT _% _% _% _% _% _%D   8 bhrz**/ / / / /d   	*- *- *- *- *- *-Z 
$  	F F F F F  FR 
$  )-1) 1) 1) 1) 1) 1)h  . 
E&	1	1	1	E&	1	1	1  )-+ + + + + +b  )-+ + + + + +\ 
$  )-S S S S S  Sl 
$  )-\ \ \ \ \  \~ 
$  )-( ( ( ( (  (V   > $,28BJ#7#7	&+ &+ &+ &+ &+\ - - - - -`   >A A A 
$
 !*"     >   @ 
$
 #) ) ) ) ) )6! ! !H" " " " " "r/   