o
    Ch                     @  sJ  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 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!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, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z: d dl;m<Z=m>Z>mZm?Z?m@Z@ d dlAmBZBmCZCmDZDmEZEmFZF d dlGmHZHmIZI d dlJmKZK d dlLmMZM d dlNmOZO d dlPmQZQ d dlRmSZTmUZUmVZV d dlWmXZX d dlYmZZZ d dl[m\Z\ erd dl]m^Z^m_Z_ d dl`maZa d dlbmcZc d dlmdZdmeZe d dlbmfZf d d lgmhZi G d!d" d"eMeQZjd)d'd(ZkdS )*    )annotations)TYPE_CHECKINGAnyCallableLiteraloverloadN)libmissing)is_supported_dtype)	ArrayLike	AstypeArgAxisIntDtypeObjFillnaOptionsInterpolateOptionsNpDtypePositionalIndexerScalarScalarIndexerSelfSequenceIndexerShapenpt)IS64is_platform_windowsAbstractMethodError)doc)find_stack_level)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	map_arraymodetake)masked_accumulationsmasked_reductions)quantile_with_mask)OpsMixin)to_numpy_dtype_inference)ExtensionArray)arrayensure_wrapped_if_datetimelikeextract_array)check_array_indexer)invalid_comparison)
hash_array)IteratorSequence)SeriesBooleanArray)NumpySorterNumpyValueArrayLikeFloatingArray)functionc                      sV  e Zd ZU dZded< ded< ded< eZeZed
ddZ		ddddZ
eddddddZeeejdddZddd d!Zedd#d$Zedd(d)Zedd+d)Zdd.d)Zddd/d0dd7d8Zeej	/ddd9d:Zedd;dd>d?Zd@dA ZddBdCZd fdDdEZddGdHZddJdKZeddLdMZeddNdOZddPdQZdddUdVZddWdXZ ddYdZZ!edd[d\Z"dd d^d_Z#dd`daZ$ddbdcZ%ddddeZ&ddfdgZ'd!dhdiZ(dde)j*fd"dmdnZ+eej,dodp Z,ed#d$dsdtZ-ed#d%dvdtZ-ed#d&dydtZ-d'd&dzdtZ-d{Z.	d(d)d~dZ/ded< d*ddZ0d+ddZ1edddZ2d,ddZ3dd Z4e4Z5d-ddZ6d.ddZ7d!ddZ8edd Z9edddZ:e	Rdd/ddZ;d0ddZ<dddRdd1ddZ=d2ddZ>dddZ?eej@	d3d4ddZ@dddZAeejB		d5d6ddZBeejC	/d'd7ddńZCeejDd!ddǄZDd'd8dd˄ZEd'd9dd̈́ZFeejGdddτZGd:ddԄZHd/dd՜d;ddڄZId<dd܄ZJddބ ZKd<ddZLd/dRdRdd=ddZMd/dRdRdd=ddZNd/dRdd>ddZOd/dRddd?ddZPd/dRddd?ddZQd/dRdd>ddZRd/dRdd>ddZSd+ddZTd/dRdd>ddZUd/dRdd>ddZVd@ddZWd/d dAddZXdBdd	ZY  ZZS (C  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)rK   __new__rN   rP   )clsrQ   rR   result rX   k/var/www/html/myvaluetrips/my_value_trip_new/venv/lib/python3.10/site-packages/pandas/core/arrays/masked.py_simple_new}   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
ValueErrorr[   rN   rP   )selfrQ   rR   r[   rX   rX   rY   __init__   s   
zBaseMaskedArray.__init__Nra   r[   c                C  s   | j |||d\}}| ||S )Nrh   )_coerce_to_array)rV   scalarsra   r[   rQ   rR   rX   rX   rY   _from_sequence   s   
zBaseMaskedArray._from_sequencerd   r   ra   r    c                 C  s\   t j||jd}|| j t j|td}| ||}t|| r$||jkr,t	d| d|S )Nra   z5Default 'empty' implementation is invalid for dtype='')
r_   emptytypefillrL   onesr\   r^   ra   NotImplementedError)rV   rd   ra   rQ   rR   rW   rX   rX   rY   _empty   s   

zBaseMaskedArray._emptyboxedCallable[[Any], str | None]c                 C  s   t S rT   )str)rf   rt   rX   rX   rY   
_formatter      zBaseMaskedArray._formatterr'   c                 C     t | rT   r   rf   rX   rX   rY   ra         zBaseMaskedArray.dtypeitemr   r   c                 C     d S rT   rX   rf   r|   rX   rX   rY   __getitem__   rx   zBaseMaskedArray.__getitem__r   c                 C  r}   rT   rX   r~   rX   rX   rY   r      rx   r   
Self | Anyc                 C  sD   t | |}| j| }t|r|r| jjS | j| S | | j| |S rT   )r>   rP   r!   ra   na_valuerN   rZ   )rf   r|   newmaskrX   rX   rY   r      s   


T)limit
limit_arear[   methodr   r   
int | Noner   #Literal['inside', 'outside'] | Nonec                C  sH  | j }| rtj|| jd}| jj}|j}|r!| }| }n|d ur)| }||||d |d ur| s|j}| }	|		 }
t
|	|	d d d 	  d }|dkrv|d |
  |d |
 O  < ||d d   ||d d  O  < n|dkr||
d |  ||
d | O  < |r| |j|jS | S |r|  }|S | }|S )Nndimr   rR      insideoutside)rP   anyr	   get_fill_funcr   rN   Tr[   allargmaxlenrZ   )rf   r   r   r   r[   rR   funcnpvaluesnew_maskneg_maskfirstlast
new_valuesrX   rX   rY   _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 )Nr   r   )r   rP   r	   check_value_sizer   r   r   r   rN   r   r[   rZ   )
rf   valuer   r   r[   rR   r   r   r   r   rX   rX   rY   fillna   s.   
zBaseMaskedArray.fillnar[   r   tuple[np.ndarray, np.ndarray]c                C  ry   rT   r   )rV   rQ   ra   r[   rX   rX   rY   ri     s   z BaseMaskedArray._coerce_to_arrayc                 C  sz   | 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|d| j  d)zy
        Check if we have a scalar that we can cast losslessly.

        Raises
        ------
        TypeError
        bfzInvalid value 'z' for dtype 'rm   )ra   kindr   r!   
is_integeris_floatrc   )rf   r   r   rX   rX   rY   _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 )NTFrl   )r>   r$   r)   ra   rP   r   rN   ri   )rf   keyr   rR   rX   rX   rY   __setitem__4  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*   ra   r   rN   r   r   r   r\   r_   isnanrP   r   super__contains__)rf   r   	__class__rX   rY   r   E  s   zBaseMaskedArray.__contains__rA   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 )Nr   )	r   _hasnarN   ra   r   ziprP   ranger   )rf   valr   isna_irX   rX   rY   __iter__M  s   

zBaseMaskedArray.__iter__intc                 C  s
   t | jS rT   )r   rN   rz   rX   rX   rY   __len__]     
zBaseMaskedArray.__len__c                 C     | j jS rT   )rN   rd   rz   rX   rX   rY   rd   `  r{   zBaseMaskedArray.shapec                 C  r   rT   )rN   r   rz   rX   rX   rY   r   d  r{   zBaseMaskedArray.ndimc                 C  s(   | j ||}| j||}| ||S rT   )rN   swapaxesrP   rZ   )rf   axis1axis2datarR   rX   rX   rY   r   h  s   zBaseMaskedArray.swapaxesr   axisr   c                 C  s0   t j| j||d}t j| j||d}| ||S Nr   )r_   deleterN   rP   rZ   )rf   locr   r   rR   rX   rX   rY   r   m     zBaseMaskedArray.deletec                 O  s0   | j j|i |}| jj|i |}| ||S rT   )rN   reshaperP   rZ   rf   argskwargsr   rR   rX   rX   rY   r   r  r   zBaseMaskedArray.reshapec                 O  s2   | j j|i |}| jj|i |}t| ||S rT   )rN   ravelrP   ro   r   rX   rX   rY   r   w  s   zBaseMaskedArray.ravelc                 C  s   |  | jj| jjS rT   )rZ   rN   r   rP   rz   rX   rX   rY   r   }  s   zBaseMaskedArray.Tdecimalsc                 O  sF   | j jdkr| S 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   r   )
ra   r   nvvalidate_roundr_   roundrN   _maybe_mask_resultrP   r[   )rf   r   r   r   rQ   rX   rX   rY   r     s
   zBaseMaskedArray.roundc                 C  s   |  | j | j S rT   rZ   rN   rP   r[   rz   rX   rX   rY   
__invert__     zBaseMaskedArray.__invert__c                 C  s   |  | j | j S rT   r   rz   rX   rX   rY   __neg__  r   zBaseMaskedArray.__neg__c                 C  s   |   S rT   r   rz   rX   rX   rY   __pos__  s   zBaseMaskedArray.__pos__c                 C  s   |  t| j| j S rT   )rZ   absrN   rP   r[   rz   rX   rX   rY   __abs__  s   zBaseMaskedArray.__abs__c                 C  s   t j| tdS )Nrl   )r_   asarrayobjectrz   rX   rX   rY   _values_for_json  s   z BaseMaskedArray._values_for_jsonnpt.DTypeLike | Noner   r   c                 C  s   | j }t| |||\}}|du rt}|rQ|tkr)t|s)|tju r)td| dt  tj	dt
d | j|}W d   n1 sEw   Y  ||| j< |S t  tj	dt
d | jj||d}W d   |S 1 spw   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   r9   r   r%   
libmissingNAre   warningscatch_warningsfilterwarningsRuntimeWarningrN   astyperP   )rf   ra   r[   r   hasnar   rX   rX   rY   to_numpy  s2   B





zBaseMaskedArray.to_numpyc                 C  s>   | j dkrdd | D S | jrd n| jj}| j|tjd S )Nr   c                 S  s   g | ]}|  qS rX   )tolist.0xrX   rX   rY   
<listcomp>  s    z*BaseMaskedArray.tolist.<locals>.<listcomp>ra   r   )r   r   rN   ra   r   r   r   r   )rf   ra   rX   rX   rY   r     s   
zBaseMaskedArray.tolist.npt.DTypeLikec                 C  r}   rT   rX   rf   ra   r[   rX   rX   rY   r     rx   zBaseMaskedArray.astyper:   c                 C  r}   rT   rX   r   rX   rX   rY   r     rx   r   r   c                 C  r}   rT   rX   r   rX   rX   rY   r   !  rx   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   Frh   r   MNaTiuzcannot convert NA to integerr   z cannot convert float NaN to bool)ra   r   r[   )r&   ra   r[   r^   r'   r   r   r   r   rN   r   numpy_dtyperP   construct_array_typer    rk   r   r_   nan
datetime64r   
no_defaultr   re   r   )rf   ra   r[   r   rR   rV   eaclsr   rX   rX   rY   r   %  s6   





i  NpDtype | Nonebool | Nonec                 C  sL   |du r| j stj| j||dS tjdtt d |du rd}| j||dS )z|
        the array interface, return my values
        We return an object array here to preserve our scalar values
        Frh   aS  Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed and passing 'copy=False' raises an error when returning a zero-copy NumPy array is not possible. pandas will follow this behavior starting with pandas 3.0.
This conversion to NumPy requires a copy, but 'copy=False' was passed. Consider using 'np.asarray(..)' instead.)
stacklevelN)	r   r_   r;   rN   r   warnFutureWarningr   r   r   rX   rX   rY   	__array__U  s   zBaseMaskedArray.__array__ztuple[type, ...]_HANDLED_TYPESufuncnp.ufuncrv   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outrX   reducerl   r   rM   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   )rE   rI   IntegerArrayr   r   r   )pandas.core.arraysrE   rI   r  ra   r   r[   r_   float16r   float32r   )r   rE   rI   r  mrR   rX   rY   reconstruct  s   



z4BaseMaskedArray.__array_ufunc__.<locals>.reconstructr   c                 3  s    | ]} |V  qd S rT   rX   r   )r  rX   rY   	<genexpr>  s    z2BaseMaskedArray.__array_ufunc__.<locals>.<genexpr>)r   rM   )getr^   r   rK   NotImplementedr-   !maybe_dispatch_ufunc_to_dunder_opdispatch_ufunc_with_outdispatch_reduction_ufuncr_   zerosr   r\   rP   appendrN   getattrnouttupler   	_na_value)	rf   r   r   inputsr   r   r   rW   inputs2rX   )rR   r  rY   __array_ufunc__r  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)rR   ro   )pyarrowr;   rN   rP   )rf   ro   parX   rX   rY   __arrow_array__  s   zBaseMaskedArray.__arrow_array__c                 C  
   | j  S rT   )rP   r   rz   rX   rX   rY   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)rP   r[   r   r   r#   r   r*   )rf   rR   otherrX   rX   rY   _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 )Nra   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int8r\   r"  r   r   )r#  r&  r   )r   r   Fr   r!  ) __name__hasattrr#   r   pd_arrayr=   r^   rK   rN   rP   r:   r_   r   r   rr   r/   maybe_prepare_scalar_for_opget_array_opr<   rb   r\   r  r   r   	ones_likera   r   r   float64errstatewherer   )	rf   r  opop_nameomaskpd_oprR   rW   ra   rX   rX   rY   _arith_method  sn   










zBaseMaskedArray._arith_methodrE   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   rD   r   r  zLengths must match to comparer\   rl   r   elementwise__Fr   )r  rE   r^   rK   rN   rP   r#   r_   r   r   rr   r   re   r   r   r  rd   rq   r   r   r   r   DeprecationWarningr  r)  r
  r?   r  )rf   r  r2  rE   rR   rW   r   rX   rX   rY   _cmp_method?  s0   




zBaseMaskedArray._cmp_methodrW   *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rdt
|jrddd	lm} |jd
||< t ||sb|j||jdS |S |jjdv rwddlm} |||ddS tj||< |S )z
        Parameters
        ----------
        result : array-like or tuple[array-like]
        mask : array-like bool
        r   r   rH   Fr   r   rD   r  )TimedeltaArrayr   rl   r   r  )r^   r  r   ra   r   r  rI   rE   r   is_np_dtyper
   r<  ro   rZ   r  r_   r   )	rf   rW   rR   divr&  rI   rE   r<  r  rX   rX   rY   r   g  s,   
	



z"BaseMaskedArray._maybe_mask_resultc                 C  r  rT   )rP   r[   rz   rX   rX   rY   r*     r   zBaseMaskedArray.isnac                 C  r   rT   r   rz   rX   rX   rY   r    r{   zBaseMaskedArray._na_valuec                 C  s   | j j| jj S rT   )rN   nbytesrP   rz   rX   rX   rY   r@    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 rX   rN   r   rX   rX   rY   r         z5BaseMaskedArray._concat_same_type.<locals>.<listcomp>r   c                 S  rC  rX   )rP   r   rX   rX   rY   r     rE  )r_   concatenate)rV   rA  r   r   rR   rX   rX   rY   _concat_same_type  s   
z!BaseMaskedArray._concat_same_typeencodinghash_key
categorizenpt.NDArray[np.uint64]c                C  s*   t | j|||d}t| jj||  < |S )N)rH  rI  rJ  )r@   rN   hashra   r   r*   )rf   rH  rI  rJ  hashed_arrayrX   rX   rY   _hash_pandas_object  s
   
z#BaseMaskedArray._hash_pandas_object)
allow_fill
fill_valuer   rO  rP  Scalar | Nonec          	      C  sp   t |r| jn|}t| j||||d}t| j|d||d}|r2t|r2t|dk}|||< ||A }| ||S )N)rP  rO  r   Tr   )	r*   rL   r4   rN   rP   r+   r_   r   rZ   )	rf   indexerrO  rP  r   data_fill_valuerW   rR   	fill_maskrX   rX   rY   r4     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   rD   c                 3  s    | ]	}| j ju V  qd S rT   r   )r   r   rz   rX   rY   r    s    
z'BaseMaskedArray.isin.<locals>.<genexpr>rl   Fr   )r  rE   r_   r   r1   rN   r   ra   r   r   rP   r  rd   r\   )rf   rQ   rE   
values_arrrW   values_have_NArR   rX   rz   rY   r1     s   

zBaseMaskedArray.isinc                 C  s    | j  }| j }| ||S rT   )rN   r[   rP   rZ   )rf   r   rR   rX   rX   rY   r[     s   

zBaseMaskedArray.copyr   keepLiteral['first', 'last', False]c                 C  s   | j }| j}tj|||dS )N)rW  rR   )rN   rP   algos
duplicated)rf   rW  rQ   rR   rX   rX   rY   rZ    s   zBaseMaskedArray.duplicatedc                 C  s    t | j| j\}}| ||S )z
        Compute the BaseMaskedArray of unique values.

        Returns
        -------
        uniques : BaseMaskedArray
        )rY  unique_with_maskrN   rP   rZ   )rf   uniquesrR   rX   rX   rY   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.)r`  rb  )r   re   r^   r:   r   r   rN   searchsorted)rf   r   r`  rb  rX   rX   rY   re    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)rf  rR   r   rl   r   r   )rN   rP   r0   ra   r   r   r   r_   r  r\   r   intpmaxinsertrZ   )rf   rf  arrrR   codesr\  has_nasizeuniques_maskna_indexna_code
uniques_earX   rX   rY   	factorize  s(   
zBaseMaskedArray.factorizec                 C  s   | j S rT   rD  rz   rX   rX   rY   _values_for_argsort:  s   z#BaseMaskedArray._values_for_argsortdropnarC   c                 C  s   ddl m}m} ddlm} tj| j|| jd\}}}t	j
t|ft	jd}| }	|dkr2d|d< |||	}
|| j ||}||
|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   )IndexrC   r=  ru  rR   rl   Tr   countF)indexnamer[   )pandasrv  rC   pandas.arraysr  rY  value_counts_arraylikerN   rP   r_   r  r   rb   r[   ra   r   )rf   ru  rv  rC   r  keysvalue_counts
na_counter
mask_indexrR   rk  ry  rX   rX   rY   r  >  s    

zBaseMaskedArray.value_countsc                 C  sZ   |rt | j|| jd}tj|jtjd}nt | j|| jd\}}t| ||}||  S )Nrw  rl   )	r3   rN   rP   r_   r  rd   rb   ro   argsort)rf   ru  rW   res_maskrX   rX   rY   _modef  s   zBaseMaskedArray._modec                 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)ro   ra   r_   array_equalrP   rN   r(   )rf   r  r^  rightrX   rX   rY   equalso  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.
        )rR   rP  r  r     rl   r  )r7   rN   rP   r_   r   r   r   rr   r*   r   rq   rd   r\   r"   ra   r  r   r   )rf   r  r  resout_maskrX   rX   rY   	_quantile  s$   


zBaseMaskedArray._quantile)skipnakeepdimsrz  r  r  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   ri  minstdsumvarmeanprodr  r   r   )r   r  rR   r   )r   )rz  r   	mask_sizer   rl   rX   )r  rN   rP   r.   popr*   _wrap_na_resultr   r_   r  r\   r   r   r   )
rf   rz  r  r  r   rW   r   rR   r2  r   rX   rX   rY   _reduce  s    
zBaseMaskedArray._reducec                C  s>   t |tjr|r| jj|d}n| jj|d}| ||S |S r   )r^   r_   r`   rP   r   r   r   )rf   rz  rW   r  r   rR   rX   rX   rY   _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 )Nrl   Float32r  r/  )r  medianr  r  skewkurt)r  ri     int32int64uint32uint64)r   r   ur   r   r  )r_   rq   r\   ra   itemsizer   rz  r   r   r   r;   r   )rf   rz  r   r  rR   
float_dtypnp_dtypeis_windows_or_32bitint_dtyp	uint_dtypr   rX   rX   rY   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   rl   r  r   )r^   r_   r`   r   r  rd   r\   r  )rf   rz  rW   r  	min_countr   rX   rX   rY    _wrap_min_count_reduction_result  s   z0BaseMaskedArray._wrap_min_count_reduction_resultr  r  r   r  AxisInt | Nonec                K  8   t d| tj| j| j|||d}| jd||||dS )NrX   r  r  )r   validate_sumr6   r  rN   rP   r  rf   r  r  r   r   rW   rX   rX   rY   r       
zBaseMaskedArray.sumc                K  r  )NrX   r  r  )r   validate_prodr6   r  rN   rP   r  r  rX   rX   rY   r    r  zBaseMaskedArray.prodr  c                K  4   t d| tj| j| j||d}| jd|||dS )NrX   r  r  )r   validate_meanr6   r  rN   rP   r  rf   r  r   r   rW   rX   rX   rY   r       zBaseMaskedArray.meanr   r  r   ddofr  c                K  :   t jd|dd tj| j| j|||d}| jd|||dS )NrX   r  fnamer  r  )r   validate_stat_ddof_funcr6   r  rN   rP   r  rf   r  r   r  r   rW   rX   rX   rY   r       zBaseMaskedArray.varc                K  r  )NrX   r  r  r  r  )r   r  r6   r  rN   rP   r  r  rX   rX   rY   r  +  r  zBaseMaskedArray.stdc                K  r  )NrX   r  r  )r   validate_minr6   r  rN   rP   r  r  rX   rX   rY   r  8  r  zBaseMaskedArray.minc                K  r  )NrX   r  ri  )r   validate_maxr6   ri  rN   rP   r  r  rX   rX   rY   ri  B  r  zBaseMaskedArray.maxc                 C  s   t |  ||dS )N)	na_action)r2   r   )rf   mapperr  rX   rX   rY   mapL  s   zBaseMaskedArray.mapc                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>
        rX   r   )r   validate_anyrN   r[   r_   putmaskrP   _falsey_valuer   r   ra   r   rf   r  r   r   rQ   rW   rX   rX   rY   r   O  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
        rX   r   r   )r   validate_allrN   r[   r_   r  rP   _truthy_valuer   r   r   ra   r   r  rX   rX   rY   r     s   ?
zBaseMaskedArray.allr   rI   c             
   K  s   | j jdkr|r| j }	| j }
n#| j}	| j}
n| j jdv r.d}| jd}	| j }
ntd| j  tj|	f|d|||||
d| |sK| S | j jdkrYt	| 
|	|
S ddlm} |
|	|
S )	z2
        See NDFrame.interpolate.__doc__.
        r   r   Tf8z)interpolate is not implemented for dtype=r   )r   r   ry  r   limit_directionr   rR   rH   )ra   r   rN   r[   rP   r   rr   r	   interpolate_2d_inplacero   rZ   r  rI   )rf   r   r   ry  r   r  r   r[   r   r   rR   rI   rX   rX   rY   interpolate  s@   

	zBaseMaskedArray.interpolate)r  c                K  s<   | j }| j}tt|}|||fd|i|\}}| ||S )Nr  )rN   rP   r  r5   rZ   )rf   rz  r  r   r   rR   r2  rX   rX   rY   _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}|dkr7|	ddv r7d	|d d < |	j
| jf||||
|d
|}|	jdkr]|	j	|	jd}t||dfj}|	jdv rd|S | ||S )Nr   )WrappedCythonOp)r  r   r  	aggregaterl   rank	na_option)topbottomF)r  r  comp_idsrR   result_maskohlcr   )idxminidxmax)pandas.core.groupby.opsr  get_kind_from_howrP   r   r[   r_   r  r\   r	  _cython_op_ndim_compatrN   r  _cython_aritytiler   r   )rf   r  r  r  r  r  r   r  r   r2  rR   r  
res_valuesarityrX   rX   rY   _groupby_op4  s4   

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


zBaseMaskedArray._groupby_op)rQ   rM   rR   rO   rS   r   )F)rQ   rM   rR   rO   r[   r\   rS   r]   )r[   r\   rS   r   )rd   r   ra   r    )rt   r\   rS   ru   )rS   r'   )r|   r   rS   r   )r|   r   rS   r   )r|   r   rS   r   )
r   r   r   r   r   r   r[   r\   rS   r   )NNNT)r   r   r[   r\   rS   r   )ra   r   r[   r\   rS   r   )rS   r]   )rS   r\   )rS   rA   )rS   r   )rS   r   )rS   r   )r   )r   r   rS   r   )r   r   )rS   rM   )ra   r   r[   r\   r   r   rS   rM   ).)ra   r   r[   r\   rS   rM   )ra   r    r[   r\   rS   r:   )ra   r   r[   r\   rS   r   )T)NN)ra   r   r[   r   rS   rM   )r   r   r   rv   rT   )rR   r  rS   rO   )rS   rE   )rW   r;  rR   rM   )rA  rB  r   r   rS   r   )rH  rv   rI  rv   rJ  r\   rS   rK  )rO  r\   rP  rQ  r   r   rS   r   )rQ   r   rS   rE   )r   )rW  rX  rS   rO   )r^  N)r   r_  r`  ra  rb  rc  rS   rd  )rf  r\   rS   rg  )ru  r\   rS   rC   )ru  r\   rS   r   )r  r  r  rv   rS   rK   )rz  rv   r  r\   r  r\   )rz  rv   )r  r\   r  r   r   r  )r  r\   r   r  )r  r\   r   r  r  r   )r   r   r   r   r[   r\   rS   rI   )rz  rv   r  r\   rS   rK   )
r  rv   r  r\   r  r   r  r   r  r  )[r)  
__module____qualname____doc____annotations__r   r  r  classmethodrZ   rg   rk   r   r:   rs   rw   propertyra   r   r   r   r   ri   r   r   r   r   r   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __array_priority__r   r  r  r   r  r6  _logical_methodr:  r   r*   r  r@  rG  rN  r4   r1   r[   rZ  r]  re  rs  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ri  r  r   r   r  r  r  __classcell__rX   rX   r   rY   rK   l   s  
 ,!#]
.M](/
	$$(	-


QR5rK   masked_arraysSequence[BaseMaskedArray]rS   list[BaseMaskedArray]c           
      C  s   t | } | d j}dd | D }tj|dtjt| t| d fd|jdd}dd | D }tj|dtj|tdd}|	 }g }t
|jd	 D ]}||d
d
|f |d
d
|f d}	||	 qH|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.
    r   c                 S     g | ]	}|j d dqS r   r   )rN   r   r   rk  rX   rX   rY   r   o      z7transpose_homogeneous_masked_arrays.<locals>.<listcomp>F)orderra   )r   r   c                 S  r  r  )rP   r   r  rX   rX   rY   r   z  r  rl   r   Nr  )listra   r_   rF  rn   r   r   
empty_liker\   r   r   rd   r  )
r  ra   rQ   transposed_valuesmaskstransposed_masksarr_typetransposed_arraysr   transposed_arrrX   rX   rY   #transpose_homogeneous_masked_arraysd  s,   

$r  )r  r  rS   r  )l
__future__r   typingr   r   r   r   r   r   numpyr_   pandas._libsr   r	   r   pandas._libs.tslibsr
   pandas._typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   pandas.compatr   r   pandas.errorsr   pandas.util._decoratorsr   pandas.util._exceptionsr   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,   rY  r-   r.   r/   pandas.core.algorithmsr0   r1   r2   r3   r4   pandas.core.array_algosr5   r6    pandas.core.array_algos.quantiler7   pandas.core.arrayliker8   pandas.core.arrays._utilsr9   pandas.core.arrays.baser:   pandas.core.constructionr;   r+  r<   r=   pandas.core.indexersr>   pandas.core.opsr?   pandas.core.util.hashingr@   collections.abcrA   rB   r{  rC   r  rE   rF   rG   rI   pandas.compat.numpyrJ   r   rK   r  rX   rX   rX   rY   <module>   s`    @             