
    Owg(                       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/dKdLdZ0 e0 ed              G d d      Z1 G d d      Z2dMdZ3dNdZ4	 dO	 	 	 dPdZ5	 	 	 	 	 	 	 	 dQdZ6	 	 	 dR	 	 	 	 	 	 	 	 	 	 	 dSdZ7dTdZ8dUdZ9dVdWdZ:dXdZ;dYdZ<dXd Z=dddd!	 	 	 	 	 	 	 	 	 dZd"Z>dddd!	 	 	 	 	 	 	 	 	 dZd#Z? e1d$      e;e=ddd dd%	 	 	 	 	 	 	 	 	 	 	 d[d&                     Z@	 	 	 	 	 	 	 	 	 	 d\d'ZA e2       e;dddd!	 	 	 	 	 	 	 	 	 d]d(              ZB e2       dddd!d^d)       ZC	 	 	 	 	 	 d_d*ZD e
j                  e
j                        f	 	 	 	 	 	 	 	 	 	 	 d`d+ZG e2d,-      ddd,dd.	 	 	 	 	 dad/       ZH e1d$d0       e2d,-      ddd,dd.	 	 	 	 	 	 	 dbd1              ZI e1d$d0      ddd,dd.	 	 	 	 	 	 	 	 	 	 	 dcd2       ZJd3 ZK eKd4d56      ZL eKd7d86      ZMdddd!	 	 	 	 	 	 	 	 	 ddd9ZNdddd!	 	 	 	 	 	 	 	 	 ddd:ZO e1d$d0      e=dddd!	 	 	 	 	 	 	 	 	 d]d;              ZP e1d$d0      e=dddd!	 	 	 	 	 	 	 	 	 d]d<              ZQ e1d$d0      e=ddd dd%	 	 	 	 	 	 	 	 	 	 	 d[d=              ZR	 	 	 	 	 	 	 	 	 	 ded>ZS e
j                  e
j                        f	 	 	 	 	 	 	 	 	 dfd?ZT	 dg	 	 	 	 	 	 	 	 	 	 	 dhd@ZU	 	 	 	 	 	 	 	 didAZVdB ZW e1d$d0      dCddD	 	 	 	 	 	 	 	 	 djdE       ZX	 	 	 	 dkdFZY e1d$d0      dd,dG	 	 	 	 	 	 	 	 	 dldH       ZZdI Z[dmdJZ\y)n    )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)errorsFTc                    t         r| ay y N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)vs    I/var/www/horilla/myenv/lib/python3.12/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 )disallowc                P    t         |           t        d |D              | _        y )Nc              3  F   K   | ]  }t        |      j                    y wr&   )r   type).0dtypes     r*   	<genexpr>z$disallow.__init__.<locals>.<genexpr>F   s     IL/44Is   !)super__init__tupledtypes)selfr8   	__class__s     r*   r6   zdisallow.__init__D   s     I&IIr,   c                r    t        |d      xr* t        |j                  j                  | j                        S )Nr3   )hasattr
issubclassr3   r1   r8   )r9   objs     r*   checkzdisallow.checkH   s'    sG$PCIINNDKK)PPr,   c                b     t        j                         fd       }t        t        |      S )Nc                 4   t        j                  | |j                               }t        fd|D              r+j                  j                  dd      }t        d| d      	  | i |S # t        $ r }t        | d         rt        |      | d }~ww xY w)Nc              3  @   K   | ]  }j                  |        y wr&   )r?   )r2   r>   r9   s     r*   r4   z0disallow.__call__.<locals>._f.<locals>.<genexpr>O   s     7s4::c?7s   nan zreduction operation 'z' not allowed for this dtyper   )		itertoolschainvaluesany__name__replace	TypeError
ValueErrorr   )argskwargsobj_iterf_nameefr9   s        r*   _fzdisallow.__call__.<locals>._fL   s     tV]]_=H7h77++E26+F83OP 	$)&)) 
 #47+#A,A-s   &A. .	B7BB	functoolswrapsr   r   )r9   rR   rS   s   `` r*   __call__zdisallow.__call__K   s,    			 
	$ Ar{r,   )r8   r   returnNonerX   bool)rR   r   rX   r   )rI   
__module____qualname__r6   r?   rW   __classcell__)r:   s   @r*   r.   r.   C   s    JQr,   r.   c                      e Zd ZdddZddZy)bottleneck_switchNc                     || _         || _        y r&   )namerN   )r9   rb   rN   s      r*   r6   zbottleneck_switch.__init__c   s    	r,   c                     j                   xs j                  	 t        t              t        j                        d dd	 	 	 	 	 d fd       }t        t        |      S # t        t
        f$ r d Y Mw xY w)NTaxisskipnac                  t        
j                        dkD  r,
j                  j                         D ]  \  }}||vs|||<    | j                  dk(  r|j	                  d      t        | |      S t        rn|rlt        | j                  	      rV|j	                  dd       6|j                  dd         | fd|i|}t        |      r | f||d|}|S  | f||d|}|S  | f||d|}|S )Nr   	min_countmaskre   rd   )lenrN   itemssizeget_na_for_min_countr(   _bn_ok_dtyper3   pop	_has_infs)rG   re   rf   kwdskr)   resultaltbn_funcbn_namer9   s          r*   rR   z%bottleneck_switch.__call__.<locals>.fo   s    4;;!# KK--/ $DAq}"#Q$ {{aDHH[$9$A )666l6<<.Q88FD)1 HHVT*$V?$?$?F !(!$V!N$v!N!N M	 !Jd6JTJF M VF$vFFMr,   )rG   
np.ndarrayre   AxisInt | Nonerf   r[   )
rb   rI   getattrbnAttributeError	NameErrorrU   rV   r   r   )r9   ru   rR   rv   rw   s   `` @@r*   rW   zbottleneck_switch.__call__g   s    ))+s||	b'*G 
	 $(	%	%	 !%	 	%	 
%	N AqzW 	* 	G	s   A* *A>=A>r&   )rX   rY   )ru   r   rX   r   )rI   r\   r]   r6   rW    r,   r*   r`   r`   b   s    0r,   r`   c                4    | t         k7  rt        |       s|dvS y)N)nansumnanprodnanmeanF)objectr   )r3   rb   s     r*   ro   ro      s"    259 ;;;r,   c                   t        | t        j                        r2| j                  dv r$t	        j
                  | j                  d            S 	 t        j                  |       j                         S # t        t        f$ r Y yw xY w)N)f8f4KF)
isinstancenpndarrayr3   r   has_infsravelisinfrH   rK   NotImplementedError)rt   s    r*   rq   rq      sk    &"**%<<<' <<S 122xx##%%*+ s   "A1 1BBc                    ||S t        |       r8|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 values+inf)_na_ok_dtyper   rC   infr   i8maxr
   )r3   
fill_valuefill_value_typs      r*   _get_fill_valuer      sZ     E!66M'vvwV#99Kr,   c                    |>| j                   j                  dv ry|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)r3   kindr   )rG   rf   ri   s      r*   _maybe_get_maskr      sA    B |<<%V\\&&$.<DKr,   c                   t        | ||      }| j                  }d}| j                  j                  dv r&t        j                  | j                  d            } d}|rr|pt        |||      }|`|j                         rP|st        |      r+| j                         } t        j                  | ||       | |fS 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   i8T)r   r   )r   r3   r   r   asarrayviewr   rH   r   copyputmaskwhere)rG   rf   r   r   ri   r3   datetimelikes          r*   _get_valuesr      s    R 6640DLLEL||D  FKK-.4# %j

 !xxz<#6#[[]FJJvtZ8
 4<  XXteVZ@F4<r,   c                <   | }| j                   dv r%t        j                  t        j                        }|S | j                   dk(  r%t        j                  t        j                        }|S | j                   dk(  r#t        j                  t        j
                        }|S )NbiurR   )r   r   r3   int64uint64float64)r3   	dtype_maxs     r*   _get_dtype_maxr   D  s{    IzzTHHRXX&	
 	 
s	HHRYY'	  
s	HHRZZ(	r,   c                d    t        |       ryt        | j                  t        j                         S )NF)r   r=   r1   r   integerr3   s    r*   r   r   P  s%    5!%**bjj111r,   c                   | t         u r	 | S |j                  dk(  r|t        }t        | t        j
                        st        |      rJ d       | |k(  rt        j                  } t        |       r&t	        j                  dd      j                  |      } n$t	        j                  |       j                  |      } | j                  |d      } | S | j                  |      } | S |j                  dk(  rt        | t        j
                        s| |k(  st	        j                  |       r&t	        j                  d      j                  |      } | S t	        j                  |       t        j                   kD  rt#        d      t	        j                  |       j                  |d      } | S | j                  d	      j                  |      } | S )
zwrap our results if neededMzExpected non-null fill_valuer   nsFr   mzoverflow in timedelta operationm8[ns])r   r   r
   r   r   r   r   rC   
datetime64astyper   r   isnantimedelta64fabsr   r   rL   )rt   r3   r   s      r*   _wrap_resultsr   V  s   }F MC 
s	J&"**-J'G)GG'#F|ud3::5A&)..u5]]5u]5F& M! ]]5)F  M 
s	&"**-#rxx'7.55e< M 399, !BCC &)00U0C
 M ]]8,11%8FMr,   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re   rf   ri   c                   | }| j                   j                  dv }|r|t        |       } | f|||d|}|r0t        ||j                   t              }|s|J t        ||||      }|S )Nr   r   )r   )r3   r   r   r   r
   _mask_datetimelike_result)	rG   re   rf   ri   rN   orig_valuesr   rt   funcs	           r*   new_funcz&_datetimelike_compat.<locals>.new_func  s     ||((D0DL<DfL4TLVL"6;+<+<NF'''264{Sr,   rG   rx   re   ry   rf   r[   ri   npt.NDArray[np.bool_] | NonerT   )r   r   s   ` r*   _datetimelike_compatr     s`     __T  $-1  	
 + 0 8r,   c                0   | j                   j                  dv r| j                  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   )r3   r   r   r    ndimshaper   full)rG   re   r   result_shapes       r*   rn   rn     s    " ||G#y)#FLL1J{{a	||ET*V\\$(*-EEww|Zv||DDr,   c                f     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re   c          	        |dk(  r| j                   dk(  r| j                  d   r| j                  d   dz  | j                  d   kD  r| j                  t        k7  r| j                  t
        k7  rt        |       }|j                  d      B|j                  d      }t        t        |            D cg c]  } ||   fd||   i| }}n|D cg c]  } |fi | }}t        j                  |      S  | fd|i|S c c}w c c}w )Nr      C_CONTIGUOUSi  r   ri   re   )r   flagsr   r3   r   r[   listrm   rp   rangerj   r   array)	rG   re   rN   arrsri   iresultsxr   s	           r*   newfuncz&maybe_operate_rowwise.<locals>.newfunc  s    AIq ^, a4'6<<?:&$<Dzz&!-zz&)CHTCS>?Da9tAw9&9  7;;4,V,;;88G$$F0000 <s   0DD)rG   rx   re   ry   rT   )r   r   s   ` r*   maybe_operate_rowwiser     s2     __T>B 1 1. 7r,   r   c               h   | j                   j                  dv r|| j                  |      S | j                   j                  dk(  r$t        j                  dt
        t                      t        | |d|      \  } }| j                   t        k(  r| j                  t              } | j                  |      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
    iubr   zz'any' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).any() instead.
stacklevelFr   ri   )r3   r   rH   warningsr#   FutureWarningr   r   r   r   r[   rG   re   rf   ri   _s        r*   nananyr     s    D ||E!dl zz$||CJ')		
 FFu4HIFA ||vt$ ::dr,   c               h   | j                   j                  dv r|| j                  |      S | j                   j                  dk(  r$t        j                  dt
        t                      t        | |d|      \  } }| j                   t        k(  r| j                  t              } | j                  |      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   r   zz'all' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).all() instead.r   Tr   )r3   r   allr   r#   r   r   r   r   r   r[   r   s        r*   nanallr     s    D ||E!dl zz$||CJ')		
 FFt$GIFA ||vt$ ::dr,   M8)re   rf   rh   ri   c               :   | j                   }t        | |d|      \  } }t        |      }|j                  dk(  r|}n2|j                  dk(  r#t	        j                   t        j
                        }| 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   rR   r   r   rh   )	r3   r   r   r   r   r   sum_maybe_null_outr   )rG   re   rf   rh   ri   r3   	dtype_sumthe_sums           r*   r   r   \  s    D LLEvv!$GLFDu%IzzS		s	HHRZZ(	jjYj/GgtT6<<9UGNr,   c                L   t        | t        j                        rG| j                  d      j	                  |j
                        } |j                  |      }t        | |<   | S |j                         r2t        j                  t              j	                  |j
                        S | S )Nr   r   )	r   r   r   r   r   r3   rH   r
   r   )rt   re   ri   r   	axis_masks        r*   r   r     s     &"**%t$))+*;*;<HH$H'	 !y M 88:88D>&&{'8'899Mr,   c               4   | j                   }t        | |d|      \  } }t        |      }t        j                   t        j                        }|j
                  dv r$t        j                   t        j                        }nE|j
                  dv r$t        j                   t        j                        }n|j
                  dk(  r|}|}t        | j                  |||      }| j                  ||      }t        |      }|ut        |dd	      rht        t        j                  |      }t        j                  d
      5  ||z  }	ddd       |dk(  }
|
j                         rt        j                  	|
<   	S |dkD  r||z  nt        j                  }	|	S # 1 sw Y   OxY w)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   iurR   r   Nr   Fignore)r   )r3   r   r   r   r   r   _get_countsr   r   _ensure_numericrz   r   r   errstaterH   rC   )rG   re   rf   ri   r3   r   dtype_countcountr   the_meanct_masks              r*   r   r     sR   B LLEvv!$GLFDu%I((2::&K zzTHHRZZ(		t	HHRZZ(		s		dDDEjjYj/Gg&GGGVU;RZZ'[[X& 	'H	' 1*;;= "HW O ',ai7U?RVVO	' 	's   :FFc               t   | j                   j                  dk(  xr |du }dfd	}| j                   }t        | |d      \  } }| j                   j                  dk7  rM| j                   t        k(  r(t	        j
                  |       }|dv rt        d|  d      	 | j                  d      } |s;|9| j                  j                  s| j                         } t        j                  | |<   | j                  }	| j                   d	kD  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(  r0|d	k(  r+t        j.                  t        j0                  |       d      }
nt        j.                  | |      }
ddd       n2t3        | j,                  |      }
n|	r	 || |      nt        j                  }
t5        
|      S # t        $ r}t        t        |            |d}~ww xY w# 1 sw Y   ;xY w)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
    rR   Nc                (   |t        |       }n| }s |j                         st        j                  S t	        j
                         5  t	        j                  ddt               t        j                  | |         }d d d        |S # 1 sw Y   S xY w)Nr   All-NaN slice encountered)	r!   r   r   rC   r   catch_warningsfilterwarningsRuntimeWarning	nanmedian)r   _maskresrf   s      r*   
get_medianznanmedian.<locals>.get_median  s    =!HEFEeiik66M$$& 	)##5~ ,,qx(C	) 
	) 
s   	4BB)ri   r   stringmixedzCannot convert  to numericr   r   r   r   r   T)keepdimsr   r&   )r3   r   r   r   r   infer_dtyperK   r   rL   strr   	writeabler   r   rC   rl   r   apply_along_axisr   r   r   r  r   r  squeeze_get_empty_reduction_resultr   )rG   re   rf   ri   using_nan_sentinelr  r3   inferrederrnotemptyr  s     `        r*   r  r    s   6  **c1Bddl LLEvvDTJLFD||C<<6!v.H../& EFF	/]]4(F $"2||%%[[]Fvvt{{H {{Q4+))*dFC ,,. >++ "=~ Q1,Q1, !ll2::f+=M ll6=> >$ .fllDAC +3j&e$$U  	/CH%3.	/&> >s%   H 5BH.	H+H&&H+.H7c                    t        j                  |       }t        j                  t        |             }t        j                  |||k7     t         j
                        }|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   arangerj   emptyr   fillrC   )r   re   shpdimsrets        r*   r  r  C  sU      ((5/C99SZ D
((3tt|$BJJ
7CHHRVVJr,   c                   t        | |||      }||j                  |      z
  }t        |      r)||k  r t        j                  }t        j                  }||fS t        t        j                  |      }||k  }|j                         rJt        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   r1   r   r   rC   r   r   rH   r   )values_shaperi   re   ddofr3   r   ds          r*   _get_counts_nanvarr   Z  s    : dD>E

4  A D= FFEA !8O RZZ'}88:JJq$'JJudBFF+!8Or,   r   r  re   rf   r  ri   c          	         | j                   dk(  r| j                  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   )ri   r"  )r3   r   r   r   sqrtnanvarr   )rG   re   rf   r  ri   
orig_dtypert   s          r*   nanstdr'    sb    H ||xX&JvvD9LFDWWVFf4dSTF,,r,   m8c                  | j                   }t        | ||      }|j                  dv r&| j                  d      } |t        j
                  | |<   | j                   j                  dk(  r't        | j                  |||| j                         \  }}nt        | j                  |||      \  }}|r)|'| j                         } t	        j                  | |d       t        | j                  |t        j                              |z  }|t	        j                  ||      }t        || z
  dz        }	|t	        j                  |	|d       |	j                  |t        j                        |z  }
|j                  dk(  r|
j                  |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   rR   r   )re   r3   r   Fr   )r3   r   r   r   r   rC   r   r   r   r   r   r   r   expand_dims)rG   re   rf   r  ri   r3   r   r  avgsqrrt   s              r*   r%  r%    sU   J LLE6640DzzTt$66F4L||C%fllD$fllSq%fllD$Eq$"


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


3a WW$bjjW1A5F
 zzSu51Mr,   c                  t        | ||||       t        | ||      }| j                  j                  dk7  r| j	                  d      } |s"| |j                         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
    r"  rR   r   )r%  r   r3   r   r   rH   r   rC   r   r   r$  )rG   re   rf   r  ri   r   r   vars           r*   nansemr/    s    L 6V$TB6640D||Ct$d&488:vv!&,,dD&,,OHE1
d64
HC773<"''%.((r,   c                f     t        d        t        d dd d	 	 	 	 	 	 	 d fd              }|S )NrC   )rb   Tr   c                   | j                   dk(  rt        | |      S t        | ||      \  } } t        |       |      }t	        |||| j
                        }|S )Nr   r   ri   )rl   rn   r   rz   r   r   )rG   re   rf   ri   rt   r   meths        r*   	reductionz_nanminmax.<locals>.reduction;  sc     ;;!$VT22"F>
 '&t, tV\\Br,   r   )r`   r   )r3  r   r4  s   `` r*   
_nanminmaxr5  :  sa    c$L)  $-1  	
 +  *" r,   minr   )r   max-infc               h    t        | dd|      \  } }| j                  |      }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])
    Tr8  r2  )r   argmax_maybe_arg_null_outrG   re   rf   ri   rt   s        r*   	nanargmaxr=  U  >    L vtFNLFD]]4 F !tV<FMr,   c               h    t        | dd|      \  } }| j                  |      }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   r2  )r   argminr;  r<  s        r*   	nanargminrA    r>  r,   c               :   t        | ||      }| j                  j                  dk7  r)| j                  d      } t	        | j
                  ||      }n#t	        | j
                  ||| j                        }|r*|(| j                         } t        j                  | |d       n$|s"| |j                         rt        j                  S t        j                  dd      5  | j                  |t        j                        |z  }ddd       |t        j                  |      }| z
  }|r|t        j                  ||d       |dz  }||z  }|j                  |t        j                        }	|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       | j                  }|j                  dk(  rj                  |d      }t!        t        j"                        r2t        j$                  |	dk(  d|      }t        j                  ||dk  <   |S |	dk(  r|j'                  d      n|}|dk  rt        j                  S |S # 1 sw Y   xY w# 1 sw Y   xY w)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
    rR   r   r   Nr   r   invaliddivider   r   g      ?g      ?Fr      )r   r3   r   r   r   r   r   r   r   rH   rC   r   r   r   r*  _zero_out_fperrr   r   r   r1   )rG   re   rf   ri   r   meanadjusted	adjusted2	adjusted3m2m3rt   r3   s                r*   nanskewrN    sF   J 6640D||Ct$FLL$5FLL$FLLI$"


64#(TXXZvv	Xh	7 :zz$bjjz1E9:~~dD)}H$"


8T1%!IH$I	t2::	.B	t2::	.B 
	B		B	Xh	7 M519,,	:rBG|LM LLEzzSu51&"**%"'1f-FFuqy M	 #%'Av1966MMG: :(M Ms   %J8JJJc               "   t        | ||      }| j                  j                  dk7  r)| j                  d      } t	        | j
                  ||      }n#t	        | j
                  ||| j                        }|r*|(| j                         } t        j                  | |d       n$|s"| |j                         rt        j                  S t        j                  dd      5  | j                  |t        j                        |z  }ddd       |t        j                  |      }| z
  }|r|t        j                  ||d       |dz  }|dz  }|j                  |t        j                        }	|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       t              }t              }t!        |t        j"                        s5|dk  rt        j                  S |dk(  r| j                  j%                  d      S t        j                  dd      5  ||z  z
  }ddd       | j                  }|j                  dk(  rj                  |d      }t!        t        j"                        r0t        j&                  |dk(  d|      }t        j                  ||dk  <   |S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)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
    rR   r   r   Nr   r   rC  r   rF  r      Fr   )r   r3   r   r   r   r   r   r   r   rH   rC   r   r   r   r*  rG  r   r   r1   r   )rG   re   rf   ri   r   rH  rI  rJ  	adjusted4rL  m4adj	numeratordenominatorrt   r3   s                   r*   nankurtrV  	  s   J 6640D||Ct$FLL$5FLL$FLLI$"


64#(TXXZvv	Xh	7 :zz$bjjz1E9:~~dD)}H$"


8T1%!I1I	t2::	.B	t2::	.B	Xh	7 8519""uqyUQY&?@UQY'5195:	qyUQY/"a%78  	*I!+.Kk2::. 1966M!<<$$Q''	Xh	7 /[(3./ LLEzzSu51&"**%+*Av6FFuqyMY: :8 8(/ /s$   %K+":K8 	L+K58LLc                   t        | ||      }|r|| j                         } d| |<   | j                  |      }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
    r   r   )r   r   prodr   r   )rG   re   rf   rh   ri   rt   s         r*   r   r   j  s[    @ 6640D$"t[[F dFLLI r,   c                    || S |t        | dd      s&|r|j                         ry|j                         ry| S |r|j                  |      }n|j                  |      }|j                         rd| |<   | S )Nr   F)rz   r   rH   )rt   re   ri   rf   na_masks        r*   r;  r;    sv     ||76659xxzxxz M hhtnGhhtnG;;= F7OMr,   c                B   |F||j                   |j                         z
  }nt        j                  |       }|j	                  |      S |"|j
                  |   |j                  |      z
  }n| |   }t        |      r|j	                  |      S |j                  |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
    Fr   )rl   r   r   rX  r1   r   r   r   )r  ri   re   r3   nr   s         r*   r   r     s    0 |		DHHJ&A%Azz!}

4 488D>1T"%zz%  <<E<**r,   c                   ||dk(  r| S |t        | t        j                        r|(|j                  |   |j	                  |      z
  |z
  dk  }n/||   |z
  dk  }|d| ||dz   d z   }t        j
                  ||      }t        j                  |      rjt        |       rZt        j                  |       r| j                  d      } nt        |       s| j                  dd      } t        j                  | |<   | S d| |<   | S | t        urHt        |||      r;t        | dd      }t        |      r|j                  d	      } | S t        j                  } | S )
zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nr   r   c16r   Fr   r3   rC   )r   r   r   r   r   broadcast_torH   r   iscomplexobjr   r   rC   r   check_below_min_countrz   r1   )	rt   re   ri   r   rh   	null_maskbelow_count	new_shaperesult_dtypes	            r*   r   r     sU    |	QJvrzz:D)DHHTN:YF!KI  +	1A5KetuTAXZ'88IY?I66)'??6*#]]51F'/#]]4e]<F$&FFy! M %)y! M 
s	 i8"67D9Ll+%**51 M Mr,   c                    |dkD  r;|t        j                  |       }n|j                  |j                         z
  }||k  ryy)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   TF)r   rX  rl   r   )r   ri   rh   	non_nullss       r*   rb  rb    s?    ( 1}<I		DHHJ.Iy r,   c                    t        | t        j                        r-t        j                  t        j                  |       dk  d|       S t        j                  |       dk  r| j
                  j                  d      S | S )Ng+=r   )r   r   r   r   absr3   r1   )args    r*   rG  rG  *  sW    #rzz"xxse+Q44$&FF3K%$7syy~~a @S@r,   pearson)methodmin_periodsc               @   t        |       t        |      k7  rt        d      |d}t        |       t        |      z  }|j                         s
| |   } ||   }t        |       |k  rt        j
                  S t        |       } t        |      }t        |      } || |      S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizer   )rj   AssertionErrorr!   r   r   rC   r   get_corr_func)abrm  rn  validrR   s         r*   nancorrru  2  s     1vQFGG!HuQxE99;eHeH
1vvvAAfAQ7Nr,   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~   )rr  rs  rx  s     r*   r   zget_corr_func.<locals>.funcX  s    a#A&&r,   spearman)	spearmanrc                     | |      d   S rz  r~   )rr  rs  r|  s     r*   r   zget_corr_func.<locals>.func_  s    Q?1%%r,   rl  c                4    t        j                  | |      d   S )Nr   r   )r   corrcoef)rr  rs  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.statsrx  r|  callablerL   )rm  r   rx  r|  s     @@r*   rq  rq  R  sr     *	' 	:	)	& 	9		+ 	&	

6( #8 	8 r,   )rn  r  c               N   t        |       t        |      k7  rt        d      |d}t        |       t        |      z  }|j                         s
| |   } ||   }t        |       |k  rt        j
                  S t        |       } t        |      }t	        j                  | ||      d   S )Nz&Operands to nancov must have same sizer   r!  r  )rj   rp  r!   r   r   rC   r   cov)rr  rs  rn  r  rt  s        r*   nancovr  r  s     1vQEFF!HuQxE99;eHeH
1vvvAA66!QT"4((r,   c                   t        | t        j                        r| j                  j                  dv r!| j                  t        j                        } | S | j                  t        k(  r~t        j                  |       }|dv rt        d|  d      	 | j                  t        j                        } t        j                  t        j                  |             s| j                  } | S | S t!        |       sCt#        |       s8t%        |       s-t        | t&              rt        d|  d      	 t)        |       } | S | S # t        t        f$ rF 	 | j                  t        j                        } n!# t        $ r}t        d|  d      |d }~ww xY wY | S w xY w# t        t        f$ r1 	 t+        |       } Y | S # t        $ r}t        d|  d      |d }~ww xY ww xY w)Nr   r  zCould not convert r	  zCould not convert string 'z' to numeric)r   r   r   r3   r   r   r   r   r   r  rK   
complex128rH   imagrealrL   r   r   r   r  floatcomplex)r   r  r  s      r*   r   r     s   !RZZ 77<<5 $A< H; WWq)H.."4QC{ CDD
HHR]]+ vvbggaj)A H1H qkZ]jma8<HII	NaA H1H- z* RR,A! R#&8;$GHcQR ( H-R :& 	NNAJ H  N"4QC{ CD#MN		Ns`   D7 (F 7FE'&F'	F0F  FFFGF--	G6GGG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 |rot        | j                  j                  t         j                  t         j                  f      s1| j                         }t        |      }|||<    ||d      }|||<   |S  || 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   cumprodrC   maximum
accumulater   cumsumminimumr3   r   r=   r1   r   bool_r   r   )rG   
accum_funcrf   mask_amask_bvalsri   rt   s           r*   na_accum_funcr    s     	

S"&&M


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


/	
 NFF <<D((( j!2!2RZZ4JK{{}DzT
Dq)t M F+Mr,   )T)r)   r[   rX   rY   )r3   r   rb   r  rX   r[   rZ   )NN)r3   r   r   zScalar | None)rG   rx   rf   r[   ri   r   rX   r   )NNN)rG   rx   rf   r[   r   r   r   z
str | Noneri   r   rX   z/tuple[np.ndarray, npt.NDArray[np.bool_] | None])r3   np.dtyperX   r  )r3   r   rX   r[   r&   )r3   r  )r   r   rX   r   )rG   rx   re   ry   rX   zScalar | np.ndarray)
rG   rx   re   ry   rf   r[   ri   r   rX   r[   )rG   rx   re   ry   rf   r[   rh   intri   r   rX   r  )
rt   z+np.ndarray | np.datetime64 | np.timedelta64re   ry   ri   znpt.NDArray[np.bool_]r   rx   rX   z5np.ndarray | np.datetime64 | np.timedelta64 | NaTType)
rG   rx   re   ry   rf   r[   ri   r   rX   r  )re   ry   rf   r[   )r   r   re   r   rX   rx   )r  r   ri   r   re   ry   r  r  r3   r  rX   z-tuple[float | np.ndarray, float | np.ndarray])re   ry   rf   r[   r  r  )rG   rx   re   ry   rf   r[   r  r  )rG   rx   re   ry   rf   r[   r  r  ri   r   rX   r  )
rG   rx   re   ry   rf   r[   ri   r   rX   zint | np.ndarray)
rt   rx   re   ry   ri   r   rf   r[   rX   znp.ndarray | int)
r  r   ri   r   re   ry   r3   znp.dtype[np.floating]rX   z&np.floating | npt.NDArray[np.floating])r   )rt   np.ndarray | float | NaTTypere   ry   ri   r   r   tuple[int, ...]rh   r  rX   r  )r   r  ri   r   rh   r  rX   r[   )
rr  rx   rs  rx   rm  r   rn  
int | NonerX   r  )rm  r   rX   z)Callable[[np.ndarray, np.ndarray], float])
rr  rx   rs  rx   rn  r  r  r  rX   r  )rG   r   rf   r[   rX   r   )]
__future__r   rU   rE   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+   r.   r`   ro   rq   r   r   r   r   r   r   r   rn   r   r   r   r   r   r   r  r  r3   r   r   r'  r%  r/  r5  nanminnanmaxr=  rA  rN  rV  r   r;  r   r   rb  rG  ru  rq  r  r   r  r~   r,   r*   <module>r     s   "   
   % 
 
 
 ? 4	 	 	   V<$  :67 8 >5 5p(
 GK!.,)) $),H)!)^ !%)-DDD D 	D
 'D 5DN	2&RDE>J  )-:: : 	:
 ': 
:@  )-:: : 	:
 ': 
:z 
$  )-** * 	*
 * '* *   *Z7
   	
 ;&   )-<< < 	<
 '< <  <~ 04TPT _% _%D
 8 bhhrzz*//
&/ / 	/
 / 3/d   	*- *- 	*-
 *- *-Z 
$  	FF F 	F
 F  FR 
$  )-1)1) 1) 	1)
 1) '1) 1) 1)h. 
E&	1	E&	1  )-++ + 	+
 '+ +b  )-++ + 	+
 '+ +\ 
$  )-SS S 	S
 'S S  Sl 
$  )-\\ \ 	\
 '\ \  \~ 
$  )-(( ( 	(
 ( '( (  (V
 ' 	
 > $,288BJJ#7	&+&+
&&+ &+ !	&+
 ,&+\ -(-
- '- 	-
 - "-`">KN	>A 
$
 !*" 	
   >.@ 
$
 #))) 	)
 ) ) )6!H"r,   