o
    ҷh                     @  s  d dl mZ d dlmZmZmZmZmZ d dlZd dl	Z
d dlmZmZ d dl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mZmZmZmZ d dl m!Z!m"Z" d dl#m$Z$ d d	l%m&Z& d d
l'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z;m<Z<mZm=Z=m>Z> d dl?m@Z@mAZAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZI d dlJmKZK d dlLmMZNmOZOmPZP d dlQmRZR d dlSmTZT erd dlUmVZVmWZW d dlXmYZY d dlZm[Z[ d dlm\Z\m]Z] d dl^m_Z` G dd deIeKZad%d#d$ZbdS )&    )annotations)TYPE_CHECKINGAnyCallableLiteraloverloadN)libmissing)get_unit_from_dtypeis_supported_unit)	ArrayLike	AstypeArgAxisIntDtypeObjFillnaOptionsNpDtypePositionalIndexerScalarScalarIndexerSelfSequenceIndexerShapenpt)IS64is_platform_windowsAbstractMethodError)doc)validate_fillna_kwargs)ExtensionDtype)is_boolis_integer_dtypeis_list_like	is_scalaris_string_dtypepandas_dtype)BaseMaskedDtype)array_equivalentis_valid_na_for_dtypeisnanotna)
algorithms	arrayliker	   nanopsops)factorize_arrayisintake)masked_accumulationsmasked_reductions)quantile_with_mask)OpsMixin)ExtensionArray)arrayensure_wrapped_if_datetimelikeextract_array)check_array_indexer)invalid_comparison)IteratorSequence)SeriesBooleanArray)NumpySorterNumpyValueArrayLike)functionc                      s  e Zd ZU dZded< ded< ded< eZeZedddZ		ddddZ
eddddddZeeejdddZddd d!Zedd#d$Zedd(d)Zedd+d)Zdd.d)Zdd/d0dd5d6Zeej	/ddd7d8Zedd9dd<d=Zd>d? Zd d@dAZd fdBdCZddEdFZddHdIZeddJdKZeddLdMZddNdOZdddSdTZddUdVZ ddWdXZ!eddYdZZ"ddd\d]Z#dd^d_Z$dd`daZ%ddbdcZ&ddddeZ'dde(j)fd	didjZ*eej+dkdl Z+ed
ddodpZ,ed
ddrdpZ,ed
ddudpZ,dddvdpZ,dwZ-dddydzZ.d{ed|< dddZ/dddZ0edddZ1dddZ2dd Z3e3Z4dddZ5dddZ6dddZ7edd Z8edddZ9e	PddddZ:dddPddddZ;dddZ<dddZ=dddZ>eej?		ddddZ?eej@	/ddddZ@eejAdddZAddddZBeejCdddZCdddZDd/ddÜdddȄZEdddʄZFdd̄ ZGddd΄ZHd/dPdPdϜdddӄZId/dPdPdϜdddՄZJd/dPd֜d dd؄ZKd/dPddڜd!dd݄ZLd/dPddڜd!dd߄ZMd/dPd֜d ddZNd/dPd֜d ddZOd/dPd֜d ddZPd/dPd֜d ddZQd/dd"ddZRd#ddZS  ZTS ($  BaseMaskedArrayzf
    Base class for masked arrays (which use _data and _mask to store the data).

    numpy based
    r   _internal_fill_value
np.ndarray_datanpt.NDArray[np.bool_]_maskvaluesmaskreturnr   c                 C  s   t | }||_||_|S N)rD   __new__rG   rI   )clsrJ   rK   result rQ   L/var/www/html/venv/lib/python3.10/site-packages/pandas/core/arrays/masked.py_simple_newy   s   
zBaseMaskedArray._simple_newFcopyboolNonec                 C  sX   t |tjr|jtjkstd|j|jkrtd|r$| }| }|| _	|| _
d S )NzGmask should be boolean numpy array. Use the 'pd.array' function insteadz"values.shape must match mask.shape)
isinstancenpndarraydtypebool_	TypeErrorshape
ValueErrorrT   rG   rI   )selfrJ   rK   rT   rQ   rQ   rR   __init__   s   
zBaseMaskedArray.__init__NrZ   rT   c                C  s   | j |||d\}}| ||S )Nra   )_coerce_to_array)rO   scalarsrZ   rT   rJ   rK   rQ   rQ   rR   _from_sequence   s   
zBaseMaskedArray._from_sequencer]   r   rZ   r   c                 C  s\   t j||jd}|| j t j|td}| ||}t|| r$||jkr,t	d| d|S )NrZ   z5Default 'empty' implementation is invalid for dtype='')
rX   emptytypefillrE   onesrU   rW   rZ   NotImplementedError)rO   r]   rZ   rJ   rK   rP   rQ   rQ   rR   _empty   s   

zBaseMaskedArray._emptyboxedCallable[[Any], str | None]c                 C  s   t S rM   )str)r_   rm   rQ   rQ   rR   
_formatter      zBaseMaskedArray._formatterr&   c                 C     t | rM   r   r_   rQ   rQ   rR   rZ         zBaseMaskedArray.dtypeitemr   r   c                 C     d S rM   rQ   r_   ru   rQ   rQ   rR   __getitem__   rq   zBaseMaskedArray.__getitem__r   c                 C  rv   rM   rQ   rw   rQ   rQ   rR   rx      rq   r   
Self | Anyc                 C  sD   t | |}| j| }t|r|r| jjS | j| S | | j| |S rM   )r:   rI   r    rZ   na_valuerG   rS   )r_   ru   newmaskrQ   rQ   rR   rx      s   


T)limitrT   methodr   r|   
int | Nonec          	      C  s~   | j }| r3tj|| jd}| jj}|j}|r | }| }||||d |r1| |j|jS | S |r;|  }|S | }|S N)ndim)r|   rK   )	rI   anyr	   get_fill_funcr   rG   TrT   rS   )	r_   r}   r|   rT   rK   funcnpvaluesnew_mask
new_valuesrQ   rQ   rR   _pad_or_backfill   s"   z BaseMaskedArray._pad_or_backfillc           
      C  s   t ||\}}| j}t||t| }| rV|d urCtj|| jd}| jj	}|j	}|r4|
 }|
 }||||d | |j	|j	S |rJ| 
 }	n| d d  }	||	|< |	S |r^| 
 }	|	S | d d  }	|	S r   )r   rI   r	   check_value_sizelenr   r   r   rG   r   rT   rS   )
r_   valuer}   r|   rT   rK   r   r   r   r   rQ   rQ   rR   fillna   s.   
zBaseMaskedArray.fillnarT   r   tuple[np.ndarray, np.ndarray]c                C  rr   rM   r   )rO   rJ   rZ   rT   rQ   rQ   rR   rb      s   z BaseMaskedArray._coerce_to_arrayc                 C  s|   | j j}|dkrt|r|S n!|dkr!t|st|r |S nt|s/t|r1| r1|S tdt| d| j  )zy
        Check if we have a scalar that we can cast losslessly.

        Raises
        ------
        TypeError
        bfzInvalid value 'z' for dtype )rZ   kindr   r    
is_integeris_floatr\   ro   )r_   r   r   rQ   rQ   rR   _validate_setitem_value  s   
z'BaseMaskedArray._validate_setitem_valuec                 C  sz   t | |}t|r't|| jrd| j|< d S | |}|| j|< d| j|< d S | j|| jd\}}|| j|< || j|< d S )NTFre   )r:   r#   r(   rZ   rI   r   rG   rb   )r_   keyr   rK   rQ   rQ   rR   __setitem__  s   





zBaseMaskedArray.__setitem__c                   sX   t |r$|| jjur$| jjjdkr$t|r$tt	| j| j
 @  S tt |S )Nr   )r)   rZ   rz   rG   r   r   r   rU   rX   isnanrI   r   super__contains__)r_   r   	__class__rQ   rR   r   .  s   zBaseMaskedArray.__contains__r<   c                 c  s~    | j dkr/| js| jD ]}|V  qd S | jj}t| j| jD ]\}}|r)|V  q|V  qd S tt| D ]}| | V  q5d S )N   )	r   _hasnarG   rZ   rz   ziprI   ranger   )r_   valrz   isna_irQ   rQ   rR   __iter__6  s   

zBaseMaskedArray.__iter__intc                 C  s
   t | jS rM   )r   rG   rs   rQ   rQ   rR   __len__F     
zBaseMaskedArray.__len__c                 C     | j jS rM   )rG   r]   rs   rQ   rQ   rR   r]   I  rt   zBaseMaskedArray.shapec                 C  r   rM   )rG   r   rs   rQ   rQ   rR   r   M  rt   zBaseMaskedArray.ndimc                 C  s(   | j ||}| j||}| ||S rM   )rG   swapaxesrI   rS   )r_   axis1axis2datarK   rQ   rQ   rR   r   Q  s   zBaseMaskedArray.swapaxesr   axisr   c                 C  s0   t j| j||d}t j| j||d}| ||S Nr   )rX   deleterG   rI   rS   )r_   locr   r   rK   rQ   rQ   rR   r   V     zBaseMaskedArray.deletec                 O  s0   | j j|i |}| jj|i |}| ||S rM   )rG   reshaperI   rS   r_   argskwargsr   rK   rQ   rQ   rR   r   [  r   zBaseMaskedArray.reshapec                 O  s2   | j j|i |}| jj|i |}t| ||S rM   )rG   ravelrI   rh   r   rQ   rQ   rR   r   `  s   zBaseMaskedArray.ravelc                 C  s   |  | jj| jjS rM   )rS   rG   r   rI   rs   rQ   rQ   rR   r   f  s   zBaseMaskedArray.Tdecimalsc                 O  s6   t || tj| jfd|i|}| || j S )a  
        Round each value in the array a to the given number of decimals.

        Parameters
        ----------
        decimals : int, default 0
            Number of decimal places to round to. If decimals is negative,
            it specifies the number of positions to the left of the decimal point.
        *args, **kwargs
            Additional arguments and keywords have no effect but might be
            accepted for compatibility with NumPy.

        Returns
        -------
        NumericArray
            Rounded values of the NumericArray.

        See Also
        --------
        numpy.around : Round values of an np.array.
        DataFrame.round : Round values of a DataFrame.
        Series.round : Round values of a Series.
        r   )nvvalidate_roundrX   roundrG   _maybe_mask_resultrI   rT   )r_   r   r   r   rJ   rQ   rQ   rR   r   j  s   zBaseMaskedArray.roundc                 C  s   |  | j | j S rM   rS   rG   rI   rT   rs   rQ   rQ   rR   
__invert__     zBaseMaskedArray.__invert__c                 C  s   |  | j | j S rM   r   rs   rQ   rQ   rR   __neg__  r   zBaseMaskedArray.__neg__c                 C  s   |   S rM   r   rs   rQ   rQ   rR   __pos__  s   zBaseMaskedArray.__pos__c                 C  s   |  t| j| j S rM   )rS   absrG   rI   rT   rs   rQ   rQ   rR   __abs__  s   zBaseMaskedArray.__abs__npt.DTypeLike | Nonerz   objectc                 C  s   |t ju rtj}|du rt}nt|}| jrT|tkr,t|s,|tju r,t	d| dt
  t
jdtd | j|}W d   n1 sHw   Y  ||| j< |S t
  t
jdtd | jj||d}W d   |S 1 ssw   Y  |S )aF  
        Convert to a NumPy Array.

        By default converts to an object-dtype NumPy array. Specify the `dtype` and
        `na_value` keywords to customize the conversion.

        Parameters
        ----------
        dtype : dtype, default object
            The numpy dtype to convert to.
        copy : bool, default False
            Whether to ensure that the returned value is a not a view on
            the array. Note that ``copy=False`` does not *ensure* that
            ``to_numpy()`` is no-copy. Rather, ``copy=True`` ensure that
            a copy is made, even if not strictly necessary. This is typically
            only possible when no missing values are present and `dtype`
            is the equivalent numpy dtype.
        na_value : scalar, optional
             Scalar missing value indicator to use in numpy array. Defaults
             to the native missing value indicator of this array (pd.NA).

        Returns
        -------
        numpy.ndarray

        Examples
        --------
        An object-dtype is the default result

        >>> a = pd.array([True, False, pd.NA], dtype="boolean")
        >>> a.to_numpy()
        array([True, False, <NA>], dtype=object)

        When no missing values are present, an equivalent dtype can be used.

        >>> pd.array([True, False], dtype="boolean").to_numpy(dtype="bool")
        array([ True, False])
        >>> pd.array([1, 2], dtype="Int64").to_numpy("int64")
        array([1, 2])

        However, requesting such dtype will raise a ValueError if
        missing values are present and the default missing value :attr:`NA`
        is used.

        >>> a = pd.array([True, False, pd.NA], dtype="boolean")
        >>> a
        <BooleanArray>
        [True, False, <NA>]
        Length: 3, dtype: boolean

        >>> a.to_numpy(dtype="bool")
        Traceback (most recent call last):
        ...
        ValueError: cannot convert to bool numpy array in presence of missing values

        Specify a valid `na_value` instead

        >>> a.to_numpy(dtype="bool", na_value=False)
        array([ True, False, False])
        Nzcannot convert to 'zZ'-dtype NumPy array with missing values. Specify an appropriate 'na_value' for this dtype.ignorecategoryr   )r   
no_default
libmissingNAr   rX   rZ   r   r$   r^   warningscatch_warningsfilterwarningsRuntimeWarningrG   astyperI   )r_   rZ   rT   rz   r   rQ   rQ   rR   to_numpy  s4   
B






zBaseMaskedArray.to_numpyc                 C  s:   | j dkrdd | D S | jrd n| jj}| j|d S )Nr   c                 S  s   g | ]}|  qS rQ   )tolist.0xrQ   rQ   rR   
<listcomp>  s    z*BaseMaskedArray.tolist.<locals>.<listcomp>re   )r   r   rG   rZ   r   r   r_   rZ   rQ   rQ   rR   r     s   
zBaseMaskedArray.tolist.npt.DTypeLikec                 C  rv   rM   rQ   r_   rZ   rT   rQ   rQ   rR   r     rq   zBaseMaskedArray.astyper6   c                 C  rv   rM   rQ   r   rQ   rQ   rR   r     rq   r   r   c                 C  rv   rM   rQ   r   rQ   rQ   rR   r     rq   c                 C  s8  t |}|| jkr|r|  S | S t|trRt  tjdtd | j	j
|j|d}W d    n1 s5w   Y  || j	u rB| jn| j }| }|||ddS t|trc| }|j| ||dS |jdkrltj}n|jdkrwtd}ntj}|jd	v r| jrtd
|jdkr| jrtd| j|||d}|S )Nr   r   r   Fra   r   MNaTiuzcannot convert NA to integerr   z cannot convert float NaN to bool)rZ   rz   rT   )r%   rZ   rT   rW   r&   r   r   r   r   rG   r   numpy_dtyperI   construct_array_typer   rd   r   rX   nan
datetime64r   r   r   r^   r   )r_   rZ   rT   r   rK   rO   eaclsrz   rQ   rQ   rR   r   
  s6   





i  NpDtype | Nonec                 C  s   | j |dS )z|
        the array interface, return my values
        We return an object array here to preserve our scalar values
        re   )r   r   rQ   rQ   rR   	__array__:  s   zBaseMaskedArray.__array__ztuple[type, ...]_HANDLED_TYPESufuncnp.ufuncro   c           	        sb  | dd}|| D ]}t|| jtf st  S q
tj| ||g|R i |}|tur.|S d|v r@tj| ||g|R i |S |dkrXtj| ||g|R i |}|turX|S t	j
t| td g }|D ]}t|trx |jO  ||j qe|| qed fddt|||i |}|jd	krtfd
d|D S |dkr| j r| jS |S |S )NoutrQ   reducere   r   rF   c                   s   ddl m}m}m} | jjdkr  }|| |S | jjdv r(  }|| |S | jjdkrC  }| jtjkr>| 	tj
} || |S tj|  < | S )Nr   )r@   FloatingArrayIntegerArrayr   r   r   )pandas.core.arraysr@   r   r   rZ   r   rT   rX   float16r   float32r   )r   r@   r   r   mrK   rQ   rR   reconstructj  s   



z4BaseMaskedArray.__array_ufunc__.<locals>.reconstructr   c                 3  s    | ]} |V  qd S rM   rQ   r   )r   rQ   rR   	<genexpr>  s    z2BaseMaskedArray.__array_ufunc__.<locals>.<genexpr>)r   rF   )getrW   r   rD   NotImplementedr,   !maybe_dispatch_ufunc_to_dunder_opdispatch_ufunc_with_outdispatch_reduction_ufuncrX   zerosr   rU   rI   appendrG   getattrnouttupler   	_na_value)	r_   r   r}   inputsr   r   r   rP   inputs2rQ   )rK   r   rR   __array_ufunc__C  s`   



zBaseMaskedArray.__array_ufunc__c                 C  s   ddl }|j| j| j|dS )z6
        Convert myself into a pyarrow Array.
        r   N)rK   rh   )pyarrowr7   rG   rI   )r_   rh   parQ   rQ   rR   __arrow_array__  s   zBaseMaskedArray.__arrow_array__c                 C  
   | j  S rM   )rI   r   rs   rQ   rQ   rR   r     s   
zBaseMaskedArray._hasnanpt.NDArray[np.bool_] | Nonec                 C  s^   |d u r(| j  }|tju r|dB }|S t|r&t|t|kr&|t|B }|S | j |B }|S )NT)rI   rT   r   r   r"   r   r)   )r_   rK   otherrQ   rQ   rR   _propagate_mask  s   


zBaseMaskedArray._propagate_maskc           	      C  sz  |j }d }t|ds t|r t|t| kr t|}t|dd}t|tr-|j|j	}}nt|rDt|t
s;t|}|jdkrDtdt|t| f}t|}t|}|dv rdt|tjrdt|}| ||}|tju rt| j}| jjdkr|dv rtd	| d
|dv rd}nd}||}n9d|v r| jjdkr|tj}n(| jjdv r|dv r|}tjdd || j|}W d    n1 sw   Y  |dkrt| jdk| j	 @ d|}|d urt|dk| @ d|}nD|tjurt|dkd|}n4|dkr7|d urt|dk| @ d|}n|tjur)t|dkd|}t| jdk| j	 @ d|}| ||S )NrZ   T)extract_numpyr   (can only perform ops with 1-d structures>   powrpowr   >   r  r	  truedivfloordivrtruediv	rfloordivz
operator 'z!' not implemented for bool dtypes>   modrmodint8rU   r
  r   r   )r  r  r   )allr  Fr   r	  ) __name__hasattrr"   r   pd_arrayr9   rW   rD   rG   rI   r6   rX   asarrayr   rk   r.   maybe_prepare_scalar_for_opget_array_opr8   r[   rU   r  r   r   	ones_likerZ   r   r   float64errstatewherer   )	r_   r  opop_nameomaskpd_oprK   rP   rZ   rQ   rQ   rR   _arith_method  sn   










zBaseMaskedArray._arith_methodr@   c                 C  s(  ddl m} d }t|tr|j|j}}nt|r3t|}|j	dkr't
dt| t|kr3td|tju rKtj| jjdd}tj| jjdd}n<t 0 tdd	t tdd	t t| jd
|j d
}||}|tu rxt| j||}W d    n1 sw   Y  | ||}|||ddS )Nr   r?   r   r  zLengths must match to comparerU   re   r   elementwise__Fr   )r   r@   rW   rD   rG   rI   r"   rX   r  r   rk   r   r^   r   r   r   r]   rj   r   r   r   FutureWarningDeprecationWarningr   r  r   r;   r  )r_   r  r  r@   rK   rP   r}   rQ   rQ   rR   _cmp_method  s0   




zBaseMaskedArray._cmp_methodrP   *np.ndarray | tuple[np.ndarray, np.ndarray]c           	      C  s   t |tr|\}}| ||| ||fS |jjdkr(ddlm} |||ddS |jjdkr;ddlm} |||ddS t	|jdrft
t|jrfdd	lm} |jd
||< t ||sd|j||jdS |S |jjdv ryddlm} |||ddS tj||< |S )z
        Parameters
        ----------
        result : array-like or tuple[array-like]
        mask : array-like bool
        r   r   )r   Fr   r   r?   r   )TimedeltaArrayr   re   r   r   )rW   r   r   rZ   r   r   r   r@   r   is_np_dtyper   r
   r'  rh   rS   r   rX   r   )	r_   rP   rK   divr  r   r@   r'  r   rQ   rQ   rR   r   8  s0   
	



z"BaseMaskedArray._maybe_mask_resultc                 C  r  rM   )rI   rT   rs   rQ   rQ   rR   r)   i  r   zBaseMaskedArray.isnac                 C  r   rM   rZ   rz   rs   rQ   rQ   rR   r   l  rt   zBaseMaskedArray._na_valuec                 C  s   | j j| jj S rM   )rG   nbytesrI   rs   rQ   rQ   rR   r,  p  s   zBaseMaskedArray.nbytes	to_concatSequence[Self]c                 C  s:   t jdd |D |d}t jdd |D |d}| ||S )Nc                 S     g | ]}|j qS rQ   rG   r   rQ   rQ   rR   r   z      z5BaseMaskedArray._concat_same_type.<locals>.<listcomp>r   c                 S  r/  rQ   )rI   r   rQ   rQ   rR   r   {  r1  )rX   concatenate)rO   r-  r   r   rK   rQ   rQ   rR   _concat_same_typet  s   
z!BaseMaskedArray._concat_same_type)
allow_fill
fill_valuer   r4  r5  Scalar | Nonec          	      C  sp   t |r| jn|}t| j||||d}t| j|d||d}|r2t|r2t|dk}|||< ||A }| ||S )N)r5  r4  r   T)	r)   rE   r1   rG   rI   r*   rX   r  rS   )	r_   indexerr4  r5  r   data_fill_valuerP   rK   	fill_maskrQ   rQ   rR   r1   ~  s    
zBaseMaskedArray.takec                   sr   ddl m} t|}t j|} jr)|jtko#t	 fdd|D }|| j
< tj jjtd}|||ddS )Nr   r?   c                 3  s    | ]	}| j ju V  qd S rM   r+  )r   r   rs   rQ   rR   r     s    
z'BaseMaskedArray.isin.<locals>.<genexpr>re   Fr   )r   r@   rX   r  r0   rG   r   rZ   r   r   rI   r   r]   rU   )r_   rJ   r@   
values_arrrP   values_have_NArK   rQ   rs   rR   r0     s   

zBaseMaskedArray.isinc                 C  s    | j  }| j }| ||S rM   )rG   rT   rI   rS   )r_   r   rK   rQ   rQ   rR   rT     s   

zBaseMaskedArray.copyc                 C  s    t | j| j\}}| ||S )z
        Compute the BaseMaskedArray of unique values.

        Returns
        -------
        uniques : BaseMaskedArray
        )algosunique_with_maskrG   rI   rS   )r_   uniquesrK   rQ   rQ   rR   unique  s   zBaseMaskedArray.uniqueleftr   $NumpyValueArrayLike | ExtensionArraysideLiteral['left', 'right']sorterNumpySorter | Nonenpt.NDArray[np.intp] | np.intpc                 C  s4   | j rtdt|tr|t}| jj|||dS )NzOsearchsorted requires array to be sorted, which is impossible with NAs present.)rC  rE  )r   r^   rW   r6   r   r   rG   searchsorted)r_   r   rC  rE  rQ   rQ   rR   rH    s   

zBaseMaskedArray.searchsorteduse_na_sentinel!tuple[np.ndarray, ExtensionArray]c                 C  s   | j }| j}t|d|d\}}|j| jjksJ |j| jf| }|s&|s+t|}nt|d }tj|t	d}|so|ro|
 }	|	dkrJtd}
n
|d |	  d }
|||
k  d7  < |
||dk< t||
d}d||
< | ||}||fS )NT)rI  rK   r   re   r   r7  )rG   rI   r/   rZ   r   r   r   rX   r   rU   argmaxintpmaxinsertrS   )r_   rI  arrrK   codesr?  has_nasizeuniques_maskna_indexna_code
uniques_earQ   rQ   rR   	factorize  s(   
zBaseMaskedArray.factorizec                 C  s   | j S rM   r0  rs   rQ   rQ   rR   _values_for_argsort  s   z#BaseMaskedArray._values_for_argsortdropnar>   c                 C  s   ddl m}m} ddlm} tj| jd| jd\}}|r3|||ddd}|j	
| j|_	|
d	}|S tjt|d
 dd}||dd< | j |d< ||| jdt|| jj}	|	
| j}	tjt|dd}
|||
}|||	dddS )aA  
        Returns a Series containing counts of each unique value.

        Parameters
        ----------
        dropna : bool, default True
            Don't include counts of missing values.

        Returns
        -------
        counts : Series

        See Also
        --------
        Series.value_counts
        r   )Indexr>   r(  T)rY  rK   countF)indexnamerT   Int64r   int64re   Nr7  rU   )pandasrZ  r>   pandas.arraysr   r=  value_counts_arraylikerG   rI   r\  r   rZ   rX   rg   r   sumrN  rz   r   )r_   rY  rZ  r>   r   keysvalue_countsrescountsr\  rK   counts_arrayrQ   rQ   rR   re     s$   



zBaseMaskedArray.value_countsc                 C  sd   t | t |kr
dS |j| jkrdS t| j|jsdS | j| j  }|j|j  }t||dddS )NFT)
strict_nandtype_equal)rh   rZ   rX   array_equalrI   rG   r'   )r_   r  rA  rightrQ   rQ   rR   equals.  s   zBaseMaskedArray.equalsqsnpt.NDArray[np.float64]interpolationc                 C  s   t | j| jtj||d}| jr=| jdkrt|  	 r4tj
|jtd}t| jr3tj|j| jjd}ntj|jtd}ntj|jtd}| j||dS )z
        Dispatch to quantile_with_mask, needed because we do not have
        _from_factorized.

        Notes
        -----
        We assume that all impacted cases are 1D-only.
        )rK   r5  rn  rp     re   r   )r4   rG   rI   rX   r   r   r   rk   r)   r  rj   r]   rU   r!   rZ   r   r   r   )r_   rn  rp  rf  out_maskrQ   rQ   rR   	_quantile>  s$   


zBaseMaskedArray._quantile)skipnakeepdimsr]  rt  ru  c          
      K  s   |dv rt | |dd|i|}n | j}| j}t td| }|dd }	||f|	||d|}|rQt|r?| j|dddS |d	}tj	d	t
d
}| ||S t|rXtjS |S )N>	   r  r   rM  minstdrc  varmeanprodrt  r   r   )r   rt  rK   r   )r   )r]  r   	mask_sizer   re   rQ   )r   rG   rI   r-   popr)   _wrap_na_resultr   rX   r   rU   r   r   r   )
r_   r]  rt  ru  r   rP   r   rK   r  r   rQ   rQ   rR   _reducej  s    
zBaseMaskedArray._reducec                C  s>   t |tjr|r| jj|d}n| jj|d}| ||S |S r   )rW   rX   rY   rI   r  r   r   )r_   r]  rP   rt  r   rK   rQ   rQ   rR   _wrap_reduction_result  s   z&BaseMaskedArray._wrap_reduction_resultc                C  s   t j|td}| jdkrdnd}|dv r|}n-|dv s!| jjdkr'| jjj}nt p,t }|r1dnd	}|r7d
nd}	|||	|d| jj	 }t j
dg|d}
| j|
|dS )Nre   Float32r   r  )ry  medianrx  rw  skewkurt)rv  rM     int32r_  uint32uint64)r   r   ur   r   r   )rX   rj   rU   rZ   itemsizer   r]  r   r   r   r7   r   )r_   r]  r   r{  rK   
float_dtypnp_dtypeis_windows_or_32bitint_dtyp	uint_dtypr   rQ   rQ   rR   r}    s   zBaseMaskedArray._wrap_na_resultc                C  s>   |dkrt |tjr| |tj|jtdS | j||||dS )Nr   re   rt  r   )rW   rX   rY   r   r   r]   rU   r  )r_   r]  rP   rt  	min_countr   rQ   rQ   rR    _wrap_min_count_reduction_result  s   z0BaseMaskedArray._wrap_min_count_reduction_resultrt  r  r   r  AxisInt | Nonec                K  8   t d| tj| j| j|||d}| jd||||dS )NrQ   r  rc  )r   validate_sumr3   rc  rG   rI   r  r_   rt  r  r   r   rP   rQ   rQ   rR   rc       
zBaseMaskedArray.sumc                K  r  )NrQ   r  rz  )r   validate_prodr3   rz  rG   rI   r  r  rQ   rQ   rR   rz    r  zBaseMaskedArray.prodr  c                K  4   t d| tj| j| j||d}| jd|||dS )NrQ   r  ry  )r   validate_meanr3   ry  rG   rI   r  r_   rt  r   r   rP   rQ   rQ   rR   ry       zBaseMaskedArray.meanr   rt  r   ddofr  c                K  :   t jd|dd tj| j| j|||d}| jd|||dS )NrQ   rx  fnamer  r  )r   validate_stat_ddof_funcr3   rx  rG   rI   r  r_   rt  r   r  r   rP   rQ   rQ   rR   rx       zBaseMaskedArray.varc                K  r  )NrQ   rw  r  r  r  )r   r  r3   rw  rG   rI   r  r  rQ   rQ   rR   rw    r  zBaseMaskedArray.stdc                K  r  )NrQ   r  rv  )r   validate_minr3   rv  rG   rI   r  r  rQ   rQ   rR   rv    r  zBaseMaskedArray.minc                K  r  )NrQ   r  rM  )r   validate_maxr3   rM  rG   rI   r  r  rQ   rQ   rR   rM    r  zBaseMaskedArray.maxc                K  s^   t d| | j }t|| j| j | }|r|S |s)t	| dks)| j s+|S | j
jS )aY  
        Return whether any element is truthy.

        Returns False unless there is at least one element that is truthy.
        By default, NAs are skipped. If ``skipna=False`` is specified and
        missing values are present, similar :ref:`Kleene logic <boolean.kleene>`
        is used as for logical operations.

        .. versionchanged:: 1.4.0

        Parameters
        ----------
        skipna : bool, default True
            Exclude NA values. If the entire array is NA and `skipna` is
            True, then the result will be False, as for an empty array.
            If `skipna` is False, the result will still be True if there is
            at least one element that is truthy, otherwise NA will be returned
            if there are NA's present.
        axis : int, optional, default 0
        **kwargs : any, default None
            Additional keywords have no effect but might be accepted for
            compatibility with NumPy.

        Returns
        -------
        bool or :attr:`pandas.NA`

        See Also
        --------
        numpy.any : Numpy version of this method.
        BaseMaskedArray.all : Return whether all elements are truthy.

        Examples
        --------
        The result indicates whether any element is truthy (and by default
        skips NAs):

        >>> pd.array([True, False, True]).any()
        True
        >>> pd.array([True, False, pd.NA]).any()
        True
        >>> pd.array([False, False, pd.NA]).any()
        False
        >>> pd.array([], dtype="boolean").any()
        False
        >>> pd.array([pd.NA], dtype="boolean").any()
        False
        >>> pd.array([pd.NA], dtype="Float64").any()
        False

        With ``skipna=False``, the result can be NA if this is logically
        required (whether ``pd.NA`` is True or False influences the result):

        >>> pd.array([True, False, pd.NA]).any(skipna=False)
        True
        >>> pd.array([1, 0, pd.NA]).any(skipna=False)
        True
        >>> pd.array([False, False, pd.NA]).any(skipna=False)
        <NA>
        >>> pd.array([0, 0, pd.NA]).any(skipna=False)
        <NA>
        rQ   r   )r   validate_anyrG   rT   rX   putmaskrI   _falsey_valuer   r   rZ   rz   r_   rt  r   r   rJ   rP   rQ   rQ   rR   r     s   ?
zBaseMaskedArray.anyc                K  sb   t d| | j }t|| j| j |j|d}|r|S |r+t	| dks+| j
 s-|S | jjS )aL  
        Return whether all elements are truthy.

        Returns True unless there is at least one element that is falsey.
        By default, NAs are skipped. If ``skipna=False`` is specified and
        missing values are present, similar :ref:`Kleene logic <boolean.kleene>`
        is used as for logical operations.

        .. versionchanged:: 1.4.0

        Parameters
        ----------
        skipna : bool, default True
            Exclude NA values. If the entire array is NA and `skipna` is
            True, then the result will be True, as for an empty array.
            If `skipna` is False, the result will still be False if there is
            at least one element that is falsey, otherwise NA will be returned
            if there are NA's present.
        axis : int, optional, default 0
        **kwargs : any, default None
            Additional keywords have no effect but might be accepted for
            compatibility with NumPy.

        Returns
        -------
        bool or :attr:`pandas.NA`

        See Also
        --------
        numpy.all : Numpy version of this method.
        BooleanArray.any : Return whether any element is truthy.

        Examples
        --------
        The result indicates whether all elements are truthy (and by default
        skips NAs):

        >>> pd.array([True, True, pd.NA]).all()
        True
        >>> pd.array([1, 1, pd.NA]).all()
        True
        >>> pd.array([True, False, pd.NA]).all()
        False
        >>> pd.array([], dtype="boolean").all()
        True
        >>> pd.array([pd.NA], dtype="boolean").all()
        True
        >>> pd.array([pd.NA], dtype="Float64").all()
        True

        With ``skipna=False``, the result can be NA if this is logically
        required (whether ``pd.NA`` is True or False influences the result):

        >>> pd.array([True, True, pd.NA]).all(skipna=False)
        <NA>
        >>> pd.array([1, 1, pd.NA]).all(skipna=False)
        <NA>
        >>> pd.array([True, False, pd.NA]).all(skipna=False)
        False
        >>> pd.array([1, 0, pd.NA]).all(skipna=False)
        False
        rQ   r   r   )r   validate_allrG   rT   rX   r  rI   _truthy_valuer  r   r   rZ   rz   r  rQ   rQ   rR   r  \  s   ?
zBaseMaskedArray.all)rt  c                K  s<   | j }| j}tt|}|||fd|i|\}}| ||S )Nrt  )rG   rI   r   r2   rS   )r_   r]  rt  r   r   rK   r  rQ   rQ   rR   _accumulate  s
   
zBaseMaskedArray._accumulatehowhas_dropped_nangroupsidsnpt.NDArray[np.intp]c                K  s   ddl m} ||}||||d}	| j}
|	jdkr|
 }ntj|td}|	j	| j
f||||
|d|}|	jdkrL|	j|	jd}t||dfj}| ||S )	Nr   )WrappedCythonOp)r  r   r  	aggregatere   )r  r  comp_idsrK   result_maskohlcr   )pandas.core.groupby.opsr  get_kind_from_howrI   r   rT   rX   r   rU   _cython_op_ndim_compatrG   r  _cython_arityr   tiler   r   )r_   r  r  r  r  r  r   r  r   r  rK   r  
res_valuesarityrQ   rQ   rR   _groupby_op  s,   





zBaseMaskedArray._groupby_op)rJ   rF   rK   rH   rL   r   )F)rJ   rF   rK   rH   rT   rU   rL   rV   )rT   rU   rL   r   )r]   r   rZ   r   )rm   rU   rL   rn   )rL   r&   )ru   r   rL   r   )ru   r   rL   r   )ru   r   rL   ry   )r}   r   r|   r~   rT   rU   rL   r   )NNNT)r|   r~   rT   rU   rL   r   )rZ   r   rT   rU   rL   r   )rL   rV   )rL   rU   )rL   r<   )rL   r   )rL   r   )rL   r   )r   )r   r   rL   r   )r   r   )rZ   r   rT   rU   rz   r   rL   rF   ).)rZ   r   rT   rU   rL   rF   )rZ   r   rT   rU   rL   r6   )rZ   r   rT   rU   rL   r   )TrM   )rZ   r   rL   rF   )r   r   r}   ro   )rK   r  rL   rH   )rL   r@   )rP   r&  rK   rF   )rL   rF   )r-  r.  r   r   rL   r   )r4  rU   r5  r6  r   r   rL   r   )rA  N)r   rB  rC  rD  rE  rF  rL   rG  )rI  rU   rL   rJ  )rY  rU   rL   r>   )rn  ro  rp  ro   rL   rD   )r]  ro   rt  rU   ru  rU   )r]  ro   )rt  rU   r  r   r   r  )rt  rU   r   r  )rt  rU   r   r  r  r   )r]  ro   rt  rU   rL   rD   )
r  ro   r  rU   r  r   r  r   r  r  )Ur  
__module____qualname____doc____annotations__r   r  r  classmethodrS   r`   rd   r   r6   rl   rp   propertyrZ   r   rx   r   r   rb   r   r   r   r   r   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __array_priority__r   r   r  r   r  r   _logical_methodr%  r   r)   r   r,  r3  r1   r0   rT   r@  rH  rW  rX  re  rm  rs  r~  r  r}  r  rc  rz  ry  rx  rw  rv  rM  r   r  r  r  __classcell__rQ   rQ   r   rR   rD   h   s  
 
!!^
.M](1
$$.-


QSrD   masked_arraysSequence[BaseMaskedArray]rL   list[BaseMaskedArray]c           
      C  s   t | } dd | D }tj|dd}dd | D }tj|dd}| d j}| }g }t|jd D ]}||dd|f |dd|f d}	||	 q2|S )	zTranspose masked arrays in a list, but faster.

    Input should be a list of 1-dim masked arrays of equal length and all have the
    same dtype. The caller is responsible for ensuring validity of input data.
    c                 S     g | ]	}|j d dqS r   r7  )rG   r   r   rO  rQ   rQ   rR   r         z7transpose_homogeneous_masked_arrays.<locals>.<listcomp>r   r   c                 S  r  r  )rI   r   r  rQ   rQ   rR   r     r  r   Nr   )listrX   r2  rZ   r   r   r]   r   )
r  rJ   transposed_valuesmaskstransposed_masksrZ   arr_typetransposed_arraysr   transposed_arrrQ   rQ   rR   #transpose_homogeneous_masked_arrays  s   
$r  )r  r  rL   r  )c
__future__r   typingr   r   r   r   r   r   numpyrX   pandas._libsr   r	   r   pandas._libs.tslibsr
   r   pandas._typingr   r   r   r   r   r   r   r   r   r   r   r   r   pandas.compatr   r   pandas.errorsr   pandas.util._decoratorsr   pandas.util._validatorsr   pandas.core.dtypes.baser   pandas.core.dtypes.commonr    r!   r"   r#   r$   r%   pandas.core.dtypes.dtypesr&   pandas.core.dtypes.missingr'   r(   r)   r*   pandas.corer+   r=  r,   r-   r.   pandas.core.algorithmsr/   r0   r1   pandas.core.array_algosr2   r3    pandas.core.array_algos.quantiler4   pandas.core.arrayliker5   pandas.core.arrays.baser6   pandas.core.constructionr7   r  r8   r9   pandas.core.indexersr:   pandas.core.opsr;   collections.abcr<   r=   r`  r>   r   r@   rA   rB   pandas.compat.numpyrC   r   rD   r  rQ   rQ   rQ   rR   <module>   sV    <            