
    `Vg                       d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	Z	d dl
Zd dlmZ d dlmZmZmZmZ d dlmZmZmZmZmZmZmZ d dlmZ d dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d d	l,m-Z- d d
l.m/Z/m0Z0m1Z1 d dl2m3Z3  edd      Z4e4duZ5da6dMdNdZ7 e7 ed              G d d      Z8 G d d      Z9dOdZ:dPdZ;	 dQ	 	 	 dRdZ<	 	 	 	 	 	 	 	 dSdZ=	 	 	 dT	 	 	 	 	 	 	 	 	 	 	 dUdZ>dVdZ?dWdXdZ@dYdZAdZdZBdYd ZCdddd!	 	 	 	 	 	 	 	 	 d[d"ZDdddd!	 	 	 	 	 	 	 	 	 d[d#ZE e8d$      eAeCddd dd%	 	 	 	 	 	 	 	 	 	 	 d\d&                     ZF	 	 	 	 	 	 	 	 	 	 d]d'ZG e8e-       e9       eAdddd!	 	 	 	 	 	 	 	 	 d^d(                     ZH e9       dddd!d)       ZI	 	 	 	 	 	 	 	 	 	 d_d*ZJ ej                  ej                        f	 	 	 	 	 	 	 	 	 	 	 d`d+ZM e9d,-      ddd,dd.d/       ZN e8d$d0       e9d,-      ddd,dd.d1              ZO e8d$d0      ddd,dd.	 	 	 	 	 	 	 	 	 	 	 dad2       ZPd3 ZQ eQd4d56      ZR eQd7d86      ZS e8d9      dddd!	 	 	 	 	 	 	 	 	 dbd:       ZT e8d9      dddd!	 	 	 	 	 	 	 	 	 dbd;       ZU e8d$d0      eCdddd!	 	 	 	 	 	 	 	 	 d^d<              ZV e8d$d0      eCdddd!	 	 	 	 	 	 	 	 	 d^d=              ZW e8d$d0      eCddd dd%	 	 	 	 	 	 	 	 	 	 	 d\d>              ZX	 	 	 	 	 	 	 	 	 	 dcd?ZY ej                  ej                        f	 	 	 	 	 	 	 	 	 ddd@ZZ	 de	 	 	 	 	 	 	 	 	 	 	 dfdAZ[	 	 	 	 	 	 	 	 dgdBZ\dC Z] e8d$d0      dDddE	 	 	 	 	 	 	 dhdF       Z^didGZ_ e8d$d0      dd,dH	 	 	 	 	 	 	 	 	 djdI       Z`dJ ZadK Zb ebej                        Zd ebej                        Zf ebej                        Zh ebej                        Zj ebej                        Zl ebej                        ZndkdLZoy)l    )annotationsN)AnyCallablecast)
get_option)NaTNaTTypeiNaTlib)	ArrayLikeDtypeDtypeObjFScalarShapenpt)import_optional_dependency)is_any_int_dtypeis_bool_dtype
is_complexis_datetime64_any_dtypeis_floatis_float_dtype
is_integeris_integer_dtypeis_numeric_dtypeis_object_dtype	is_scalaris_timedelta64_dtypeneeds_i8_conversionpandas_dtype)PeriodDtype)isnana_value_for_dtypenotna)extract_array
bottleneckwarn)errorsFTc                    t         r| ay y N)_BOTTLENECK_INSTALLED_USE_BOTTLENECK)vs    S/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/nanops.pyset_use_bottleneckr0   @   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>M   s     IL/44Is   !)super__init__tupledtypes)selfr=   	__class__s     r/   r;   zdisallow.__init__K   s     I&IIr1   c                r    t        |d      xr* t        |j                  j                  | j                        S )Nr8   )hasattr
issubclassr8   r6   r=   )r>   objs     r/   checkzdisallow.checkO   s'    sG$PCIINNDKK)PPr1   c                b     t        j                         fd       }t        t        |      S )Nc                    t        j                  | |j                               }t        fd|D              r+j                  j                  dd      }t        d| d      	 t        j                  d      5   | i |cd d d        S # 1 sw Y   y xY w# t        $ r }t        | d         rt        |      | d }~ww xY w)	Nc              3  @   K   | ]  }j                  |        y wr+   )rD   )r7   rC   r>   s     r/   r9   z0disallow.__call__.<locals>._f.<locals>.<genexpr>V   s     7s4::c?7s   nan zreduction operation 'z' not allowed for this dtypeignoreinvalidr   )	itertoolschainvaluesany__name__replace	TypeErrornperrstate
ValueErrorr   )argskwargsobj_iterf_nameefr>   s        r/   _fzdisallow.__call__.<locals>._fS   s     tV]]_=H7h77++E26+F83OP 
[[2 .d-f-. . . 
 #47+#A,A-s6   &B <B	B BB B 	C#B>>C	functoolswrapsr   r   )r>   r\   r]   s   `` r/   __call__zdisallow.__call__R   s,    			 
	& Ar{r1   )r=   r   returnNonerb   bool)r\   r   rb   r   )rQ   
__module____qualname__r;   rD   ra   __classcell__)r?   s   @r/   r3   r3   J   s    JQr1   r3   c                      e Zd ZdddZddZy)bottleneck_switchNc                     || _         || _        y r+   )namerX   )r>   rl   rX   s      r/   r;   zbottleneck_switch.__init__k   s    	r1   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maskro   rn   )lenrX   itemssizeget_na_for_min_countr-   _bn_ok_dtyper8   pop	_has_infs)rO   ro   rp   kwdskr.   resultaltbn_funcbn_namer>   s          r/   r\   z%bottleneck_switch.__call__.<locals>.fw   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Mr1   )rO   
np.ndarrayro   
int | Nonerp   re   )
rl   rQ   getattrbnAttributeError	NameErrorr_   r`   r   r   )r>   r   r\   r   r   s   `` @@r/   ra   zbottleneck_switch.__call__o   s    ))+s||	b'*G 
	  $	%	%	 %	 	%	 
%	N AqzW 	* 	G	s   A* *A>=A>r+   )rb   rc   )r   r   rb   r   )rQ   rf   rg   r;   ra    r1   r/   rj   rj   j   s    0r1   rj   c                8    t        |       st        |       s|dvS y)N)nansumnanprodnanmeanF)r   r    )r8   rl   s     r/   ry   ry      s#    5!*=e*D ;;;r1   c                ,   t        | t        j                        rB| j                  dk(  s| j                  dk(  r$t	        j
                  | j                  d            S 	 t        j                  |       j                         S # t        t        f$ r Y yw xY w)Nf8f4KF)
isinstancerT   ndarrayr8   r   has_infsravelisinfrP   rS   NotImplementedError)r~   s    r/   r{   r{      sv    &"**%<<46<<4#7 <<S 122xx##%%*+ s   "B 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_dtyperT   rH   infr   i8maxr
   )r8   
fill_valuefill_value_typs      r/   _get_fill_valuer      sZ     E!66M'vvwV#99Kr1   c                    |Mt        | j                        st        | j                        ry|st        | j                        rt	        |       }|S )a  
    Compute a mask if and only if necessary.

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

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

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

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

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

    Returns
    -------
    Optional[np.ndarray[bool]]
    N)r   r8   r   r    r#   )rO   rp   rs   s      r/   _maybe_get_maskr      sB    B |&*:6<<*H(6<DKr1   c                   t        |      sJ t        | d      } t        | ||      }| j                  }d}t	        | j                        r&t        j                  | j                  d            } d}t        |      }t        |||      }|rX|V|T|j                         rD|s|r(| j                         } t        j                  | ||       nt        j                  | | |      } |}t        |      st        |      r$t        j                  t
        j                         }n.t#        |      r#t        j                  t
        j$                        }| ||||fS )a7  
    Utility to get the values view, mask, dtype, dtype_max, and fill_value.

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

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

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

    Returns
    -------
    values : ndarray
        Potential copy of input value array
    mask : Optional[ndarray[bool]]
        Mask for values, if deemed necessary to compute
    dtype : np.dtype
        dtype for values
    dtype_max : np.dtype
        platform independent dtype
    fill_value : Any
        fill value used
    Textract_numpyFi8)r   r   )r   r&   r   r8   r    rT   asarrayviewr   r   rP   copyputmaskwherer   r   int64r   float64)	rO   rp   r   r   rs   r8   datetimelikedtype_ok	dtype_maxs	            r/   _get_valuesr     s%   \ Z    66F6640DLLEL6<<( FKK-.E"H !*^J 4#**@88:<

644 4%< I-"6HHRXX&			HHRZZ(	4	:55r1   c                d    t        |       ryt        | j                  t        j                         S )NF)r    rB   r6   rT   integerr8   s    r/   r   r   ^  s%    5!%**bjj111r1   c                \   | t         u r	 | S t        |      r|t        }t        | t        j
                        st        |      rJ d       | |k(  rt        j                  } t        |       rt	        j                  dd      } n$t	        j                  |       j                  d      } | j                  |d      } | S | j                  |      } | S t        |      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 neededzExpected non-null fill_valuer   nszdatetime64[ns]Fr   zoverflow in timedelta operationm8[ns])r   r   r
   r   rT   r   r#   rH   
datetime64r   r   astyper   isnantimedelta64fabsr   r   rV   )r~   r8   r   s      r/   _wrap_resultsr   d  sr   }F MC 
!	'J&"**-J'G)GG'#F|ud3&)../?@]]5u]5F& M! ]]5)F  M 
e	$&"**-#rxx'7.55e< M 399, !BCC &)00U0C
 M ]]8,11%8FMr1   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ro   rp   rs   c                   | }| j                   j                  dv }|r|t        |       } | f|||d|}|r0t        ||j                   t              }|s|J t        ||||      }|S )NmMr   )r   )r8   kindr#   r   r
   _mask_datetimelike_result)	rO   ro   rp   rs   rX   orig_valuesr   r~   funcs	           r/   new_funcz&_datetimelike_compat.<locals>.new_func  s     ||((J6DL<DfL4TLVL"6;+<+<NF'''264{Sr1   )rO   r   ro   r   rp   re   rs   npt.NDArray[np.bool_] | Noner^   )r   r   s   ` r/   _datetimelike_compatr     s`     __T  -1  	
 + 0 8r1   c                   t        |       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.
    r      Nr   )r   r   r$   r8   ndimshaperT   full)rO   ro   r   result_shapes       r/   rx   rx     s    " y)#FLL1J{{a	||ET*V\\$(*-EEww|Zv||DDr1   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ro   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   rs   ro   )r   flagsr   r8   objectre   listrw   rz   rangert   rT   array)	rO   ro   rX   arrsrs   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)rO   r   ro   r   r^   )r   r   s   ` r/   maybe_operate_rowwiser     s2     __T:> 1 1. 7r1   r   c                   t        | |d|      \  } }}}}t        |       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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 2])
    >>> nanops.nanany(s)
    True

    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([np.nan])
    >>> nanops.nanany(s)
    False
    Fr   rs   )r   r   r   re   rP   rO   ro   rp   rs   _s        r/   nananyr     sI    D %VVDQFAq!Q vt$ ::dr1   c                   t        | |d|      \  } }}}}t        |       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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanall(s)
    True

    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 0])
    >>> nanops.nanall(s)
    False
    Tr   )r   r   r   re   allr   s        r/   nanallr     sI    D %VV4PFAq!Q vt$ ::dr1   M8)ro   rp   rr   rs   c                  t        | |d|      \  } }}}}|}t        |      r|}n.t        |      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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nansum(s)
    3.0
    r   r   r   rr   )	r   r   r   rT   r8   r   sum_maybe_null_outr   )
rO   ro   rp   rr   rs   r8   r   r   	dtype_sumthe_sums
             r/   r   r   L  s~    D )414)%FD%A Ie		e	$HHRZZ(	jjYj/GgtT6<<9UGNr1   c                L   t        | t        j                        rG| j                  d      j	                  |j
                        } |j                  |      }t        | |<   | S |j                         r2t        j                  t              j	                  |j
                        S | S )Nr   r   )	r   rT   r   r   r   r8   rP   r
   r   )r~   ro   rs   r   	axis_masks        r/   r   r   }  s     &"**%t$))+*;*;<HH$H'	 !y M 88:88D>&&{'8'899Mr1   c                  t        | |d|      \  } }}}}|}t        j                  t        j                        }|j                  dv r$t        j                  t        j                        }n>t        |      r$t        j                  t        j                        }nt        |      r|}|}t        | j                  |||      }	t        | j                  ||            }
|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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanmean(s)
    1.5
    r   r   r   r   Nr   FrJ   r   )r   rT   r8   r   r   r   r   _get_countsr   _ensure_numericr   r   r   r   rU   rP   rH   )rO   ro   rp   rs   r8   r   r   r   dtype_countcountr   the_meanct_masks                r/   r   r     sC   D )414)%FD%A I((2::&K zzZHHRZZ(		%	 HHRZZ(				dDDEfjjYj?@GGGVU;RZZ'[[X& 	'H	' 1*;;= "HW O ',ai7U?RVVO	' 	's   E33E<c                  fd}t        | |      \  } }}}}t        | j                        s'	 | j                  d      } |t        j                  | |<   | j                  }| j                  dkD  r||rdst        j                  |||       }	nt        j                         5  t        j                  dd       t        j                  | |      }	ddd       nOt!        | j"                  |t        j$                  t        j                        }	n|r ||       nt        j                  }	t'        	|      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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 2, 2])
    >>> nanops.nanmedian(s)
    2.0
    c                   t        |       }s |j                         st        j                  S t	        j
                         5  t	        j                  dd       t        j                  | |         }d d d        |S # 1 sw Y   S xY w)NrJ   All-NaN slice encountered)r%   r   rT   rH   warningscatch_warningsfilterwarnings	nanmedian)r   rs   resrp   s      r/   
get_medianznanmedian.<locals>.get_median  sm    Qxdhhj66M$$& 	(##H.IJ,,qw'C	( 
		( 
s   /A<<Brs   r   Nr   rJ   r   )r   r   r8   r   rV   rS   strrT   rH   rv   r   apply_along_axisr   r   r   r   get_empty_reduction_resultr   float_r   )
rO   ro   rp   rs   r  r8   r   errnotemptyr   s
     `       r/   r   r     s:   2 !,FF FFD%A&,,'	/]]4(F 66F4L{{H {{Q4+ ))*dFC ,,. 5++H6QR,,vt4C5 5 -V\\4BFFSC %-j "&&e$$C  	/CH%3.	/$5 5s#   D5 $-E5	E>EEE$c                    t        j                  |       }t        j                  t        |             }t        j                  |||k7     |      }|j                  |       |S )z
    The result from a reduction on an empty ndarray.

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

    Returns
    -------
    np.ndarray
    r   )rT   r   arangert   emptyfill)r   ro   r8   r   shpdimsrets          r/   r  r    sM    ( ((5/C99SZ D
((3tt|$E
2CHHZJr1   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   r6   r   rT   rH   r   r   rP   r   )values_shapers   ro   ddofr8   r   ds          r/   _get_counts_nanvarr  8  s    : dD>E

4  A D=FFEA !8O RZZ'}88:JJq$'JJudBFF+!8Or1   r   r  ro   rp   r  rs   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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanstd(s)
    1.0
    M8[ns]r   r  r  )r8   r   r   rT   sqrtnanvarr   )rO   ro   rp   r  rs   
orig_dtyper   r~   s           r/   nanstdr  g  sh    : ||xX&J'TBFD!QWWVFf4dSTF,,r1   m8c                  t        | d      } | j                  }t        | ||      }t        |      r&| j	                  d      } |t
        j                  | |<   t        | j                        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  }
t        |      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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanvar(s)
    1.0
    Tr   r   r   )ro   r8   r   Fr   )r&   r8   r   r   r   rT   rH   r   r  r   r   r   r   r   r   expand_dims)rO   ro   rp   r  rs   r8   r   r  avgsqrr~   s              r/   r  r    sR   < 66FLLE6640Dt$66F4Lfll#%fllD$fllSq%fllD$Eq$"


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


3a WW$bjjW1A5F
 eu51Mr1   c               H   t        | ||||       t        | ||      }t        | j                        s| j	                  d      } 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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nansem(s)
     0.5773502691896258
    r  r   )ro   rp   r  )	r  r   r   r8   r   r  r   rT   r  )rO   ro   rp   r  rs   r   r   vars           r/   nansemr$    s    L 6V$TB6640D&,,'t$!&,,dD&,,OHE1
d6
=C773<"''%.((r1   c                j     t        d z         t        d dd d	 	 	 	 	 	 	 	 	 d fd              }|S )NrH   )rl   Tr   c                  t        | ||      \  } }}}}|| j                  |   dk(  s| j                  dk(  r5	  t        | 	      ||      }|j	                  t
        j                         n t        | 	      |      }t        |||| j                        }|S # t        t        t        f$ r t
        j                  }Y @w xY w)Nr   rs   r   r   )r   r   rv   r   r  rT   rH   r   rS   rV   r   )
rO   ro   rp   rs   r8   r   r   r~   r   meths
           r/   	reductionz_nanminmax.<locals>.reduction  s     6AF>6
2eY
 d!3q!8V[[A=M ..t9EBFF# +WVT*40F tV\\B #Iz:   s   3B $CC)
rO   r   ro   r   rp   re   rs   r   rb   r   )rj   r   )r(  r   r)  s   `` r/   
_nanminmaxr*    si    EDL)  -1  	
 + 
  *0 r1   minr   )r   max-infOc               n    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
    --------
    >>> import pandas.core.nanops as nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmax(arr)
    4

    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 2] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [ 6.,  7., nan],
           [ 9., 10., nan]])
    >>> nanops.nanargmax(arr, axis=1)
    array([2, 2, 1, 1])
    Tr-  r'  )r   argmax_maybe_arg_null_outrO   ro   rp   rs   r   r~   s         r/   	nanargmaxr3  '  D    N (VRVWFD!Q]]4 F tV<FMr1   c               n    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
    --------
    >>> import pandas.core.nanops as nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmin(arr)
    0

    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 0] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [nan,  7.,  8.],
           [nan, 10., 11.]])
    >>> nanops.nanargmin(arr, axis=1)
    array([0, 0, 1, 1])
    Tr   r'  )r   argminr1  r2  s         r/   	nanargminr7  U  r4  r1   c                  t        | d      } t        | ||      }t        | j                        s)| j	                  d      } t        | j                  ||      }n#t        | j                  ||| j                        }|r)|'| j                         } t        j                  | |d       | j                  |t        j                        |z  }|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                  }t        |      rj	                  |d      }t        t        j                         r2t        j"                  |	dk(  d|      }t        j$                  ||dk  <   |S |	dk(  rdn|}|dk  rt        j$                  S |S # 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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 1, 2])
    >>> nanops.nanskew(s)
    1.7320508075688787
    Tr   r   r   Nr   r   rJ   rL   divider   g      ?g      ?Fr      )r&   r   r   r8   r   r   r   r   rT   r   r   r   r  _zero_out_fperrrU   r   r   r   rH   )rO   ro   rp   rs   r   meanadjusted	adjusted2	adjusted3m2m3r~   r8   s                r/   nanskewrC    s   N 66F6640D&,,'t$FLL$5FLL$FLLI$"


64#::d"**:-5D~~dD)}H$"


8T1%!IH$I	t2::	.B	t2::	.B 
	B		B	Xh	7 M519,,	:rBG|LM LLEeu51&"**%"'1f-FFuqy M	 Ag61966MMM Ms   <H55H>c               R   t        | d      } t        | ||      }t        | j                        s)| j	                  d      } t        | j                  ||      }n#t        | j                  ||| j                        }|r)|'| j                         } t        j                  | |d       | j                  |t        j                        |z  }|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                         s|dk  rt        j"                  S |dk(  ryt        j                  dd	      5  ||z  z
  }ddd       | j                  }t        |      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)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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, np.nan, 1, 3, 2])
    >>> nanops.nankurt(s)
    -1.2892561983471076
    Tr   r   r   Nr   r   rJ   r9  r;  r      Fr   )r&   r   r   r8   r   r   r   r   rT   r   r   r   r  rU   r<  r   r   rH   r   )rO   ro   rp   rs   r   r=  r>  r?  	adjusted4rA  m4adj	numeratordenominatorr~   r8   s                   r/   nankurtrK    si   N 66F6640D&,,'t$FLL$5FLL$FLLI$"


64#::d"**:-5D~~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!	Xh	7 /[(3./ LLEeu51&"**%+*Av6FFuqyM?8 8(/ /s   &:J
	JJJ&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
    --------
    >>> import pandas.core.nanops as nanops
    >>> s = pd.Series([1, 2, 3, np.nan])
    >>> nanops.nanprod(s)
    6.0
    r   r   )r   r   prodr   r   )rO   ro   rp   rr   rs   r~   s         r/   r   r   <  s[    @ 6640D$"t[[F dFLLI r1   c                    || S |t        | dd      s&|r|j                         ry|j                         ry| S |r|j                  |      }n|j                  |      }|j                         rd| |<   | S )Nr   F)r   r   rP   )r~   ro   rs   rp   na_masks        r/   r1  r1  i  sv     ||76659xxzxxz M hhtnGhhtnG;;= F7OMr1   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   )rv   r   rT   rM  r6   r   r   r   )r  rs   ro   r8   nr   s         r/   r   r     s    0 |		DHHJ&A%Azz!}

4 488D>1T"zz%  <<E<**r1   c                <   |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rt        |||      rt        j                  } | S )zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nr   r   c16r   Fr   )r   rT   r   r   r   broadcast_torP   r   iscomplexobjr   r   rH   r   check_below_min_count)r~   ro   rs   r   rr   	null_maskbelow_count	new_shapes           r/   r   r     s    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VVFMr1   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)rT   rM  rv   r   )r   rs   rr   	non_nullss       r/   rW  rW    s?    ( 1}<I		DHHJ.Iy r1   c                R   t        | t        j                        rMt        j                  d      5  t        j                  t        j
                  |       dk  d|       cd d d        S t        j
                  |       dk  r| j                  j                  d      S | S # 1 sw Y   y xY w)NrJ   rK   g+=r   )r   rT   r   rU   r   absr8   r6   )args    r/   r<  r<    s|    #rzz"[[* 	988BFF3K%/C8	9 	9 %'FF3K%$7syy~~a @S@	9 	9s   -BB&pearson)methodmin_periodsc                  t        |       t        |      k7  rt        d      |d}t        |       t        |      z  }|j                         s
| |   } ||   }t        |       |k  rt        j
                  S t        |      } || |      S )z
    a, b: ndarrays
    z'Operands to nancorr must have same sizer   )rt   AssertionErrorr%   r   rT   rH   get_corr_func)abra  rb  validr\   s         r/   nancorrri    s     1vQFGG!HuQxE99;eHeH
1vvvfAQ7Nr1   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   )rf  rg  rl  s     r/   r   zget_corr_func.<locals>.func  s    a#A&&r1   spearman)	spearmanrc                     | |      d   S rn  r   )rf  rg  rp  s     r/   r   zget_corr_func.<locals>.func   s    Q?1%%r1   r`  c                4    t        j                  | |      d   S )Nr   r   )rT   corrcoef)rf  rg  s     r/   r   zget_corr_func.<locals>.func&  s    ;;q!$T**r1   zUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)scipy.statsrl  rp  callablerV   )ra  r   rl  rp  s     @@r/   re  re    sp    *	' 	:	)	& 	9		+ 	&	

6( #8 	8 r1   )rb  r  c               "   t        |       t        |      k7  rt        d      |d}t        |       t        |      z  }|j                         s
| |   } ||   }t        |       |k  rt        j
                  S t	        j                  | ||      d   S )Nz&Operands to nancov must have same sizer   r  rs  )rt   rd  r%   r   rT   rH   cov)rf  rg  rb  r  rh  s        r/   nancovry  3  s     1vQEFF!HuQxE99;eHeH
1vvv66!QT"4((r1   c                   t        | t        j                        rt        |       st	        |       r!| j                  t        j                        } | S t        |       rV	 | j                  t        j                        } t        j                  t        j                  |             s| j                  } | S | S t        |       s$t        |       st!        |       s	 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)NzCould not convert z to numeric)r   rT   r   r   r   r   r   r   
complex128rP   imagrealrS   rV   r   r   r   floatcomplex)r   r  s     r/   r   r   L  so   !RZZ A-"2$A. H- Q
HHR]]+ vvbggaj)A H1H qkZ]jm	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`   C& D> &D;6DD;	D4D//D44D;:D;>E>E	E:%E55E::E>c                      fd}|S )Nc                H   t        |       }t        |      }||z  }t        j                  d      5   | |      }d d d        |j                         rAt	              r|j                  d      }t        j                  ||t        j                         S # 1 sw Y   \xY w)NrJ   r   r.  )r#   rT   rU   rP   r   r   r   rH   )r   yxmaskymaskrs   r~   ops         r/   r\   zmake_nancomp.<locals>.fm  s    QQu}[[X& 	1XF	 88:V$s+JJvtRVV,	 	s   
BB!r   )r  r\   s   ` r/   make_nancompr  l  s     Hr1   c          	     v   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 rZ| j                  }t        |       }| j                  d      }|t         j                  j                  k(  }	 |rt        j                  ||<    ||d      }	|r
t        ||<   	 |r
t        |	|<   n[|t         j                  j                  k(  r>t        j                  |       j!                         d   }
t#        |
      rt        |	d|
d    t%        | j                  t         j                        r|	j                  |      }	|	S t%        |t         j                        r|nd}t'        |       j)                  |	j                  |      |	      }	|	S |rot+        | j                  j&                  t         j,                  t         j.                  f      s1| j1                         }t        |      }|||<    ||d      }	||	|<   |	S  || d      }	|	S # |r
t        ||<   w w xY w)
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   Nr  r   )rT   cumprodrH   maximum
accumulater   cumsumminimumr8   r   r#   r   r   r   r
   r   nonzerort   r   r6   _simple_newrB   r   bool_r   )rO   
accum_funcrp   mask_amask_br  rs   r  changedr~   nznpdtypevalss                r/   na_accum_funcr    s5    	

S"&&M


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


/	
 NFF ||J& \\
 F|KK

 5 55	))$*F$F4L2::000::d##,,.q1B2w"&wAfllBHH-[[,F* M! %/z288$Dj(G &\--G$J . F M 

6<<#4#4rzz2886LM{{}DzT
Dq)t M F+MG $ s   J* *J8)T)r.   re   rb   rc   )r8   r   rl   r  rb   re   rd   )NN)r8   r   r   zScalar | None)rO   r   rp   re   rs   r   rb   r   )NNN)rO   r   rp   re   r   r   r   z
str | Noners   r   rb   zHtuple[np.ndarray, npt.NDArray[np.bool_] | None, np.dtype, np.dtype, Any])r8   r   rb   re   r+   )r8   np.dtype)r   r   rb   r   )rO   r   ro   r   rb   zScalar | np.ndarray)
rO   r   ro   r   rp   re   rs   r   rb   re   )rO   r   ro   r   rp   re   rr   intrs   r   rb   r~  )
r~   z+np.ndarray | np.datetime64 | np.timedelta64ro   r   rs   znpt.NDArray[np.bool_]r   r   rb   z5np.ndarray | np.datetime64 | np.timedelta64 | NaTType)
rO   r   ro   r   rp   re   rs   r   rb   r~  )
r   tuple[int, ...]ro   r  r8   znp.dtype | type[np.floating]r   r   rb   r   )r  r   rs   r   ro   r   r  r  r8   r  rb   z-tuple[float | np.ndarray, float | np.ndarray])rO   r   ro   r   rp   re   r  r  rs   r   rb   r~  )
rO   r   ro   r   rp   re   rs   r   rb   zint | np.ndarray)
r~   r   ro   r   rs   r   rp   re   rb   znp.ndarray | int)
r  r   rs   r   ro   r   r8   r  rb   zfloat | np.ndarray)r   )r~   np.ndarray | float | NaTTypero   r   rs   r   r   r  rr   r  rb   r  )r   r  rs   r   rr   r  rb   re   )rf  r   rg  r   rb  r   rb   r~  )rb   z)Callable[[np.ndarray, np.ndarray], float])
rf  r   rg  r   rb  r   r  r   rb   r~  )rO   r   rp   re   rb   r   )p
__future__r   r_   rM   operatortypingr   r   r   r   numpyrT   pandas._configr   pandas._libsr   r	   r
   r   pandas._typingr   r   r   r   r   r   r   pandas.compat._optionalr   pandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r   r   r    r!   pandas.core.dtypes.dtypesr"   pandas.core.dtypes.missingr#   r$   r%   pandas.core.constructionr&   r   r,   r-   r0   r3   rj   ry   r{   r   r   r   r   r   r   rx   r   r   r   r   r   r   r   r  r8   r   r  r  r  r$  r*  nanminnanmaxr3  r7  rC  rK  r   r1  r   r   rW  r<  ri  re  ry  r   r  gtnangtgenangeltnanltlenanleeqnaneqnenanner  r   r1   r/   <module>r     sB   "    
   %    ?     2  3V<$  :67 8 @5 5p(
 GK!.,)) $),H)!)^ !%)-V6V6V6 V6 	V6
 'V6 NV6r2&RDE>J )-++ + 	+
 '+ 
+b )-++ + 	+
 '+ 
+\ 
$ )-++ + 	+
 + '+ +   +\7
   	
 ;& 
+ )-<< < 	<
 '< <   <~ "4d G% G%T
 ( 	
 @ bhhrzz*,,
&, , 	,
 , 3,^ 14 #- #-L 
$14 @  @F 
$ )-.).) .) 	.)
 .) '.) .) .)b< 
E&	1	E&	1 
# )-** * 	*
 '* * *Z 
# )-** * 	*
 '* * *Z 
$ )-SS S 	S
 'S S  Sl 
$ )-\\ \ 	\
 '\ \  \~ 
$ )-(( ( 	(
 ( '( (  (V
 ' 	
 > bhhrzz*	&+&+
&&+ &+ 	&+
 &+\ $($
$ '$ 	$
 $ "$N">KN	>A 
$,5QU DN
 0< 
$
 #))) 	)
 ) ) )0@& 	X[[!X[[!X[[!X[[!X[[!X[[!Lr1   