o
    5cړ                     @  s  d dl mZ d dlmZmZm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mZ d dlmZmZmZmZmZ d d	l m!Z! d d
l"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+ esHd dl,Z-d dl.m/Z0 d dl1m2Z2 d dl3m4Z4 e0j5e0j6e0j7e0j8e0j9e0j:dZ;ere<ne0j=ere<ndd ere<ne0j>ere<ndd ere<ne0j?ere<ndd dZ@dDddZAdEd d!ZBi d"ere<ne0jCd#ere<nd$d d%ere<ne0jDd&ere<nd'd d(ere<ne0jEd)ere<nd*d d+ere<nd,d d-ere<nd.d d/ere<nd0d d1er$e<nd2d d3e<d4e<d5e<d6e<d7er:e<ne0jFd8erCe<nd9d ZGerQd d:lHmIZI ed;d<d=ZJdFdAdBZKG dCd< d<e%e'ZLdS )G    )annotations)TYPE_CHECKINGAnyTypeVarN)lib)DtypePositionalIndexerTakeIndexernpt)pa_version_under1p01pa_version_under2p0pa_version_under3p0pa_version_under4p0pa_version_under5p0pa_version_under6p0pa_version_under7p0)deprecate_nonkeyword_argumentsdoc)is_array_likeis_bool_dtype
is_integeris_integer_dtype	is_scalar)isna)resolve_na_sentinel)OpsMixin)ExtensionArray)check_array_indexerunpack_tuple_and_ellipsesvalidate_indices)fallback_performancewarning)
ArrowDtype)eqneltgtlegec                 C     t || S N)pc
and_kleenexy r/   T/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py<lambda>F       r1   c                 C  r(   r)   )r*   	or_kleener,   r/   r/   r0   r1   J   r2   c                 C  r(   r)   )r*   xorr,   r/   r/   r0   r1   L   r2   )andrandorrorr4   rxorarrow_arraypa.ChunkedArray	pa_objectpa.Array | pa.Scalarreturnc                 C  s.   t j| jrt j|jr| t  S | S r)   )patypesr   typecastfloat64)r:   r<   r/   r/   r0   cast_for_truedivO   s
   rD   left&pa.ChunkedArray | pa.Array | pa.Scalarrightc                 C  s>   t t | |}tj| jrtj|jr|| j}|S r)   )r*   floordivide_checkedr?   r@   r   rA   rB   )rE   rG   resultr/   r/   r0   floordiv_compatZ   s   rK   addraddc                 C  r(   r)   )r*   add_checkedr,   r/   r/   r0   r1   i   r2   subrsubc                 C  r(   r)   )r*   subtract_checkedr,   r/   r/   r0   r1   m   r2   mulrmulc                 C  r(   r)   )r*   multiply_checkedr,   r/   r/   r0   r1   q   r2   truedivc                 C  s   t t| ||S r)   r*   rI   rD   r,   r/   r/   r0   r1   t       rtruedivc                 C  s   t |t| |S r)   rV   r,   r/   r/   r0   r1   w   rW   floordivc                 C  s
   t | |S r)   rK   r,   r/   r/   r0   r1   z      
 	rfloordivc                 C  s
   t || S r)   rZ   r,   r/   r/   r0   r1   }   r[   modrmoddivmodrdivmodpowrpowc                 C  r(   r)   )r*   power_checkedr,   r/   r/   r0   r1      r2   )SeriesArrowExtensionArrayTArrowExtensionArray)bounddtype'ArrowDtype | pa.DataType | Dtype | Nonepa.DataType | Nonec                 C  sB   t | tr
| j}|S t | tjr| }|S | rt| }|S d}|S )z3
    Convert dtype to a pyarrow type instance.
    N)
isinstancer!   pyarrow_dtyper?   DataTypefrom_numpy_dtype)rh   pa_dtyper/   r/   r0   to_pyarrow_type   s   

rp   c                      s6  e Zd ZU dZded< ded< dd
dZeddddddZeddddddZdddZ	dddZ
dddZddd Zdd!d"Zdd#d$Zd%d& Zd'd( Zd)d* Zd+d, Zdd.d/Zedd0d1Zedd3d4Zdd5d6Zedd7d8Zdd:d;Zeddgd<	=	>	?dd fdEdFZd fdIdJZdddKdLZdddMdNZddOdPZd fdQdRZ d fdSdTZ!ddVdWZ"e#e$j%e&j'e&j'fdd]d^Z%d_d` Z(		dddfdgZ)d fdhdiZ*dddldmZ+eddpdqZ,d=drd fdtduZ-ddydzZ.dd|d}Z/dddZ0ddddZ1dd Z2dddZ3edddZ4  Z5S )rf   aW  
    Pandas ExtensionArray backed by a PyArrow ChunkedArray.

    .. warning::

       ArrowExtensionArray is considered experimental. The implementation and
       parts of the API may change without warning.

    Parameters
    ----------
    values : pyarrow.Array or pyarrow.ChunkedArray

    Attributes
    ----------
    None

    Methods
    -------
    None

    Returns
    -------
    ArrowExtensionArray

    Notes
    -----
    Most methods are implemented using `pyarrow compute functions. <https://arrow.apache.org/docs/python/api/compute.html>`__
    Some methods may either raise an exception or raise a ``PerformanceWarning`` if an
    associated compute function is not available based on the installed version of PyArrow.

    Please install the latest version of PyArrow to enable the best functionality and avoid
    potential bugs in prior versions of PyArrow.

    Examples
    --------
    Create an ArrowExtensionArray with :func:`pandas.array`:

    >>> pd.array([1, 1, None], dtype="int64[pyarrow]")
    <ArrowExtensionArray>
    [1, 1, <NA>]
    Length: 3, dtype: int64[pyarrow]
    r;   _datar!   _dtypevaluespa.Array | pa.ChunkedArrayr>   Nonec                 C  sf   t rd}t|t|tjrt|g| _nt|tjr || _n
tdt	| dt
| jj	| _d S )NzBpyarrow>=1.0.0 is required for PyArrow backed ArrowExtensionArray.zUnsupported type 'z' for ArrowExtensionArray)r   ImportErrorrk   r?   Arraychunked_arrayrq   ChunkedArray
ValueErrorrA   r!   rr   )selfrs   msgr/   r/   r0   __init__   s   zArrowExtensionArray.__init__NFrh   copyrh   Dtype | Nonec                C  sb   t |}t|| }|st|tjtjfr$|r|j}|r ||}| |S | ttj||ddS )zL
        Construct a new ExtensionArray from a sequence of scalars.
        TrA   from_pandas)	rp   rk   r?   rw   ry   rq   rB   rx   array)clsscalarsrh   r   ro   is_clsr/   r/   r0   _from_sequence   s   

z"ArrowExtensionArray._from_sequencec                C  s6  t |}|du r|}ntj|rddlm} ||dd}nutj|r2ddlm} ||ddj}natj|rEddl	m
} ||dd}nNtj|rXddlm} ||dd}n;tj|rldd	lm}	 |	| }n'tj|s~tj|s~tj|rdd
lm}
 |
|dd}ntd| d| j|||dS )zL
        Construct a new ExtensionArray from a sequence of strings.
        Nr   )to_datetimeraise)errors)to_timedelta)to_timecoerceBooleanArray)
to_numericzConverting strings to z is not implemented.r~   )rp   r?   r@   is_timestamppandas.core.tools.datetimesr   is_datedateis_durationpandas.core.tools.timedeltasr   is_timepandas.core.tools.timesr   
is_booleanpandas.core.arraysr   _from_sequence_of_stringsto_numpyr   is_floating
is_decimalpandas.core.tools.numericr   NotImplementedErrorr   )r   stringsrh   r   pa_typer   r   r   r   r   r   r/   r/   r0   r      s<   



z-ArrowExtensionArray._from_sequence_of_stringsitemr   c                 C  s  t | |}t|tjrLt|s/| jjdkr | jjdkr t	 }n| jj
}t| tjg |dS t|jr9| |S t|jrHt| | j|S tdt|trUt|}|tu r]td}t|rit|sitd| j| }t|tjrzt| |S | }|du r| jjS |S )a8  Select a subset of self.

        Parameters
        ----------
        item : int, slice, or ndarray
            * int: The position in 'self' to get.
            * slice: A slice object, where 'start', 'stop', and 'step' are
              integers or None
            * ndarray: A 1-d boolean NumPy ndarray the same length as 'self'

        Returns
        -------
        item : scalar or ExtensionArray

        Notes
        -----
        For scalar ``item``, return a scalar value suitable for the array's
        type. This should be an instance of ``self.dtype.type``.
        For slice ``key``, return an instance of ``ExtensionArray``, even
        if the slice is length 0 or 1.
        For a boolean mask, return an instance of ``ExtensionArray``, filtered
        to the values where ``item`` is True.
        stringpyarrowrA   zFOnly integers, slices and integer or boolean arrays are valid indices.Nzuonly integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices)r   rk   npndarraylenrr   namestorager?   r   rl   rA   rx   r   rh   taker   rq   filter
IndexErrortupler   Ellipsisslicer   r   ry   as_pyna_value)r{   r   ro   valuescalarr/   r/   r0   __getitem__  s:   






zArrowExtensionArray.__getitem__c                 C     | j S )z)Convert myself to a pyarrow ChunkedArray.)rq   )r{   rA   r/   r/   r0   __arrow_array__e  s   z#ArrowExtensionArray.__arrow_array__r{   re   c                 C  s    t rtdt| t| jS )Nz*__invert__ not implement for pyarrow < 2.0)r   r   rA   r*   invertrq   r{   r/   r/   r0   
__invert__i  s   zArrowExtensionArray.__invert__c                 C     t | t| jS r)   )rA   r*   negate_checkedrq   r   r/   r/   r0   __neg__n     zArrowExtensionArray.__neg__c                 C     t | | jS r)   rA   rq   r   r/   r/   r0   __pos__q     zArrowExtensionArray.__pos__c                 C  r   r)   )rA   r*   abs_checkedrq   r   r/   r/   r0   __abs__t  r   zArrowExtensionArray.__abs__c              	   C  s  ddl m} t|j }t|tr|| j|j}n_t|tjt	fr'|| j|}nPt
|rkz|| jt|}W n@ tjjtjjfyj   t| t|B }| }tjt| dd}|t| | |||< ||| Y S w t|j dt| tr| j}n| }||S )Nr   r   boolrh    not implemented for )pandas.arraysr   ARROW_CMP_FUNCS__name__rk   rf   rq   r   r   listr   r?   r   r   ArrowNotImplementedErrorArrowInvalidr   zerosr   r   r   rA   r   	to_pandasrs   r   r   )r{   otheropr   pc_funcrJ   maskvalidr/   r/   r0   _cmp_methodw  s.   


zArrowExtensionArray._cmp_methodc                 C  s   ||j  }|tu rt|j  dt|tr|| j|j}n.t|tjtfr2|| jt	j
|dd}nt|r@|| jt	|}nt|j  dt| t| |S )Nz not implemented.Tr   r   )r   NotImplementedr   rk   rf   rq   r   r   r   r?   r   r   r   rA   )r{   r   r   arrow_funcsr   rJ   r/   r/   r0   _evaluate_op_method  s   

z'ArrowExtensionArray._evaluate_op_methodc                 C     |  ||tS r)   )r   ARROW_LOGICAL_FUNCSr{   r   r   r/   r/   r0   _logical_method  r   z#ArrowExtensionArray._logical_methodc                 C  r   r)   )r   ARROW_ARITHMETIC_FUNCSr   r/   r/   r0   _arith_method  r   z!ArrowExtensionArray._arith_methodr   c                 C  s   t |tsdS | j|jkS )NF)rk   rf   rq   )r{   r   r/   r/   r0   equals  s   
zArrowExtensionArray.equalsc                 C  r   )z2
        An instance of 'ExtensionDtype'.
        )rr   r   r/   r/   r0   rh     s   zArrowExtensionArray.dtypeintc                 C  s   | j jS )zL
        The number of bytes needed to store this object in memory.
        )rq   nbytesr   r/   r/   r0   r     s   zArrowExtensionArray.nbytesc                 C  s
   t | jS )z]
        Length of this array.

        Returns
        -------
        length : int
        )r   rq   r   r/   r/   r0   __len__  s   
zArrowExtensionArray.__len__c                 C  s   | j jdkS )Nr   )rq   
null_countr   r/   r/   r0   _hasna  s   zArrowExtensionArray._hasnanpt.NDArray[np.bool_]c                 C  s"   t r
| j  jS | j  S )z
        Boolean NumPy array indicating if each value is missing.

        This should return a 1-D array the same length as 'self'.
        )r   rq   is_nullr   rs   r   r   r/   r/   r0   r     s   zArrowExtensionArray.isna)versionallowed_argsT	quicksortlast	ascendingkindstrna_position
np.ndarrayc           
        s~   |rdnd}ddd |d }|d u str"td t j|||dS tj| j||d}tr3|	 j
}	n| }	|	jtjd	d
S )Nr   
descendingat_endat_start)r   first7)r   r   r   )ordernull_placementFr   )getr   r    superargsortr*   array_sort_indicesrq   r   r   rs   r   astyper   intp)
r{   r   r   r   argskwargsr   r   rJ   	np_result	__class__r/   r0   r     s   	zArrowExtensionArray.argsortskipnamethodc                   sr   | j  d| j jfv s| jr|stt d| |dS tr&td| dtt|| j |d}t	| j |
 S )Nr   argr  z, only implemented for pyarrow version >= 6.0
skip_nulls)rq   lengthr   r   getattrr   r   r   r*   indexr   )r{   r  r  r   r  r/   r0   _argmin_max  s   
zArrowExtensionArray._argmin_maxc                 C     |  |dS )Nminr  r{   r  r/   r/   r0   argmin     zArrowExtensionArray.argminc                 C  r  )Nmaxr  r  r/   r/   r0   argmax  r  zArrowExtensionArray.argmaxc                 C  r   )z
        Return a shallow copy of the array.

        Underlying ChunkedArray is immutable, so a deep copy is unnecessary.

        Returns
        -------
        type(self)
        r   r   r/   r/   r0   r     s   
zArrowExtensionArray.copyc                   s,   t rtdd t  S t| t| jS )z|
        Return ArrowExtensionArray without NA values.

        Returns
        -------
        ArrowExtensionArray
        6r   )r   r    r   dropnarA   r*   	drop_nullrq   r   r  r/   r0   r       

zArrowExtensionArray.dropnac                   sv   t rtdd t |S t|stjt| tdS i }tr"d|d< t	j
| jfdtj|ddi|}tj|tjdS )N2r  r   T	skip_null	value_setr   )r   r    r   isinr   r   r   r   r   r*   is_inrq   r?   r   bool_)r{   rs   r  rJ   r  r/   r0   r  %  s    
zArrowExtensionArray.isintuple[np.ndarray, Any]c                 C  s(   t r	| j j}n| j }|| jjfS )a+  
        Return an array and missing value suitable for factorization.

        Returns
        -------
        values : ndarray
        na_value : pd.NA

        Notes
        -----
        The values returned by this method are also used in
        :func:`pandas.util.hash_pandas_object`.
        )r   rq   r   rs   r   rh   r   )r{   rs   r/   r/   r0   _values_for_factorize<  s   
z)ArrowExtensionArray._values_for_factorizena_sentinelint | lib.NoDefaultuse_na_sentinelbool | lib.NoDefault!tuple[np.ndarray, ExtensionArray]c                 C  sF  t ||}tr| j }n|d urdnd}| jj|d}tjdd |jD |jjd	 }|j
jdkr@|d ur9|nd|t|< |jtjd	d
}|jrt| |dj}|d u rtr|jdk}| }	||	 r|	dkrndn	|d |	  d }
||
| j
j}|||
k  d7  < |
||dk< nt| tjg |jjd}|j|fS )Nr   encode)null_encodingc                 S  s   g | ]}|j qS r/   )indices).0cr/   r/   r0   
<listcomp>]  rW   z1ArrowExtensionArray.factorize.<locals>.<listcomp>r   fFr   r      )r   r   rq   dictionary_encoder?   rx   chunksrA   
index_typer   rh   r   r   isnanr   int64
num_chunkschunk
dictionaryrs   r  r  insertr   r   
value_type)r{   r$  r&  resolved_na_sentinelencodedr*  r+  uniquesna_maskna_indexna_coder/   r/   r0   	factorizeP  s6   

 
zArrowExtensionArray.factorizec                 O  s   t t|  d)NzA does not support reshape as backed by a 1D pyarrow.ChunkedArray.)r   rA   )r{   r   r  r/   r/   r0   reshapev  s   zArrowExtensionArray.reshaper+  r	   
allow_fill
fill_valuer   c                 C  s   t |s
t|}n|}t| jdkr|dk rtd|jdkr/| t| jkr/td|rn|dk }| rdt	|t| j t
j||d}| j|}t|rXt| |S t| |}|||< |S t| | j|S |dk  rt|}||dk   t| j7  < t| | j|S )a  
        Take elements from an array.

        Parameters
        ----------
        indices : sequence of int or one-dimensional np.ndarray of int
            Indices to be taken.
        allow_fill : bool, default False
            How to handle negative values in `indices`.

            * False: negative values in `indices` indicate positional indices
              from the right (the default). This is similar to
              :func:`numpy.take`.

            * True: negative values in `indices` indicate
              missing values. These values are set to `fill_value`. Any other
              other negative values raise a ``ValueError``.

        fill_value : any, optional
            Fill value to use for NA-indices when `allow_fill` is True.
            This may be ``None``, in which case the default NA value for
            the type, ``self.dtype.na_value``, is used.

            For many ExtensionArrays, there will be two representations of
            `fill_value`: a user-facing "boxed" scalar, and a low-level
            physical NA value. `fill_value` should be the user-facing version,
            and the implementation should handle translating that to the
            physical version for processing the take if necessary.

        Returns
        -------
        ExtensionArray

        Raises
        ------
        IndexError
            When the indices are out of bounds for the array.
        ValueError
            When `indices` contains negative values other than ``-1``
            and `allow_fill` is True.

        See Also
        --------
        numpy.take
        api.extensions.take

        Notes
        -----
        ExtensionArray.take is called by ``Series.__getitem__``, ``.loc``,
        ``iloc``, when `indices` is a sequence of values. Additionally,
        it's called by :meth:`Series.reindex`, or any other method
        that causes realignment, with a `fill_value`.
        r   zcannot do a non-empty takez!out of bounds value in 'indices'.)r   )r   r   
asanyarrayr   rq   anyr   sizer  r   r?   r   r   r   rA   r   )r{   r+  rD  rE  indices_array	fill_maskrJ   r/   r/   r0   r   |  s.   <
zArrowExtensionArray.takec                   s,   t rtdd t  S t| t| jS )z
        Compute the ArrowExtensionArray of unique values.

        Returns
        -------
        ArrowExtensionArray
        r  r  )r   r    r   uniquerA   r*   rq   r   r  r/   r0   rK    r  zArrowExtensionArray.uniquer  rd   c           	      C  s   ddl m}m} | j }|d}|d}|r-| jjdkr-| }||}||}t	
|}|t| |}|||ddS )a@  
        Return 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   )Indexrd   r1  )r  Int64)pandasrL  rd   rq   value_countsfieldr   is_validr   r   r   rA   r   )	r{   r  rL  rd   vcrs   countsr   r  r/   r/   r0   rO    s   





z ArrowExtensionArray.value_countsr   type[ArrowExtensionArrayT]c                 C  s    dd |D }t |}| |S )z
        Concatenate multiple ArrowExtensionArrays.

        Parameters
        ----------
        to_concat : sequence of ArrowExtensionArrays

        Returns
        -------
        ArrowExtensionArray
        c                 S  s    g | ]}|j  D ]}|q	qS r/   )rq   
iterchunks)r,  ear   r/   r/   r0   r.  !  s     z9ArrowExtensionArray._concat_same_type.<locals>.<listcomp>)r?   rx   )r   	to_concatr3  arrr/   r/   r0   _concat_same_type  s   
z%ArrowExtensionArray._concat_same_typer  r   c          	        s   |dkr fdd}n!ddddd ||}tt|d	}|d	u r,t j|fd
|i|S z| jfd|i|}W n+ tttfyd } zdt	 j
 d j d| dtj d| d}t||d	}~ww t| rp jjS | S )a  
        Return a scalar result of performing the reduction operation.

        Parameters
        ----------
        name : str
            Name of the function, supported values are:
            { any, all, min, max, sum, mean, median, prod,
            std, var, sem, kurt, skew }.
        skipna : bool, default True
            If True, skip NaN values.
        **kwargs
            Additional keyword arguments passed to the reduction function.
            Currently, `ddof` is the only supported kwarg.

        Returns
        -------
        scalar

        Raises
        ------
        TypeError : subclass does not define reductions
        semc                   sD   t j| fd|i|}t t t j j|d|d }t ||S )Nr
  r	  ddof)r*   stddevsqrt_checkedrQ   countrq   rI   )datar  r  	numeratordenominatorr   r/   r0   pyarrow_meth?  s   z1ArrowExtensionArray._reduce.<locals>.pyarrow_methapproximate_medianproductr\  variance)medianprodstdvarNr  r
  'z' with dtype z does not support reduction 'z' with pyarrow version z. 'z(' may be supported by upgrading pyarrow.)r   r  r*   r   _reducerq   AttributeErrorr   	TypeErrorrA   r   rh   r?   __version__r   r   r   )	r{   r   r  r  rb  pyarrow_namerJ   errr|   r  r   r0   rk  %  s:   	
zArrowExtensionArray._reducekeyint | slice | np.ndarrayr   c                 C  s   t | |}| |}| |}t|}|| }t|r%t|t| }nt|t|kr1tdt	|| }| j
||d| _dS )a  Set one or more values inplace.

        Parameters
        ----------
        key : int, ndarray, or slice
            When called from, e.g. ``Series.__setitem__``, ``key`` will be
            one of

            * scalar int
            * ndarray of integers.
            * boolean ndarray
            * slice object

        value : ExtensionDtype.type, Sequence[ExtensionDtype.type], or object
            value or values to be set of ``key``.

        Returns
        -------
        None
        %Length of indexer and values mismatch)r+  r   N)r   _indexing_key_to_indices_maybe_convert_setitem_valuer   r   r   broadcast_tor   rz   asarray_set_via_chunk_iterationrq   )r{   rq  r   r+  r   r/   r/   r0   __setitem__d  s   



zArrowExtensionArray.__setitem__npt.NDArray[np.intp]c                 C  s   t | }t|trt|| }|S t|r t||g }|S t|r;t|}t ||kr3td|	 d }|S t|}t|| }|S )z
        Convert indexing key for self into positional indices.

        Parameters
        ----------
        key : int | slice | np.ndarray

        Returns
        -------
        npt.NDArray[np.intp]
        rs  r   )
r   rk   r   r   aranger   r   rw  rz   nonzero)r{   rq  nr+  r/   r/   r0   rt    s    
		

z,ArrowExtensionArray._indexing_key_to_indicesqsnpt.NDArray[np.float64]interpolationc                 C  s*   t rtdtj| j||d}t| |S )z
        Compute the quantiles of self for each quantile in `qs`.

        Parameters
        ----------
        qs : np.ndarray[float64]
        interpolation: str

        Returns
        -------
        same type as self
        z2quantile only supported for pyarrow version >= 4.0)qr  )r   r   r*   quantilerq   rA   )r{   r~  r  rJ   r/   r/   r0   	_quantile  s   zArrowExtensionArray._quantilec                 C  s`   t rtdt| jt| j }|d}|d}t||d }|	|}t
| |S )a|  
        Returns the mode(s) of the ExtensionArray.

        Always returns `ExtensionArray` even if only one value.

        Parameters
        ----------
        dropna : bool, default True
            Don't consider counts of NA values.
            Not implemented by pyarrow.

        Returns
        -------
        same type as self
            Sorted, if possible.
        z.mode only supported for pyarrow version >= 6.0r   r1  )r   r   r*   moderq   count_distinctr   rP  equalr   rA   )r{   r  modesrs   rS  r   most_commonr/   r/   r0   _mode  s   


zArrowExtensionArray._modec                 C  s   |S )z-Maybe convert value to be pyarrow compatible.r/   )r{   r   r/   r/   r0   ru    s   z0ArrowExtensionArray._maybe_convert_setitem_valuenpt.NDArray[Any]c           
      C  s   g }d}| j  D ]P}||t| }}t|dks ||d kr&|| q	ttj||dd}|d| | }||d }t|}|d| ||d }	}|| |||	 q	t	|S )a  
        Loop through the array chunks and set the new values while
        leaving the chunking layout unchanged.

        Parameters
        ----------
        indices : npt.NDArray[np.intp]
            Position indices for the underlying ChunkedArray.

        value : ExtensionDtype.type, Sequence[ExtensionDtype.type], or object
            value or values to be set of ``key``.

        Notes
        -----
        Assumes that indices is sorted. Caller is responsible for sorting.
        r   rE   )sideN)
rq   rU  r   appendr   r   searchsorted_replace_with_indicesr?   rx   )
r{   r+  r   new_datastopr8  startr}  c_indc_valuer/   r/   r0   rx    s   
z,ArrowExtensionArray._set_via_chunk_iterationr8  pa.Arrayc           
      C  s   t |}|dkr
|S |ddg \}}|| |d krF|d| tj||jdd||d d g}dd |D }t |dkrA|d S t|S tjt |tjd	}d||< trh|j	d
d}	||	|< tj|	|jdS t
| rut|d|S t|||S )a  
        Replace items selected with a set of positional indices.

        Analogous to pyarrow.compute.replace_with_mask, except that replacement
        positions are identified via indices rather than a mask.

        Parameters
        ----------
        chunk : pa.Array
        indices : npt.NDArray[np.intp]
        value : npt.NDArray[Any]
            Replacement value(s).

        Returns
        -------
        pa.Array
        r   r0  r1  NTr   c                 S  s   g | ]}t |r|qS r/   )r   )r,  rX  r/   r/   r0   r.  .  s    z=ArrowExtensionArray._replace_with_indices.<locals>.<listcomp>r   F)zero_copy_onlyr   )r   r?   r   rA   concat_arraysr   r   r!  r   r   r   allr*   if_elsereplace_with_mask)
r   r8  r+  r   r}  r  r  arraysr   rX  r/   r/   r0   r    s,   

z)ArrowExtensionArray._replace_with_indices)rs   rt   r>   ru   )rh   r   )r   r   r)   )r{   re   r>   re   )r>   r   )r>   r!   )r>   r   )r>   r   )Tr   r   )r   r   r   r   r   r   r>   r   )r  r   r  r   r>   r   )T)r  r   r>   r   )r>   r"  )r$  r%  r&  r'  r>   r(  )FN)r+  r	   rD  r   rE  r   r>   rf   )r  r   r>   rd   )r   rT  r>   re   )r   r   r  r   )rq  rr  r   r   r>   ru   )rq  rr  r>   rz  )r{   re   r~  r  r  r   r>   re   )r{   re   r  r   r>   re   )r+  rz  r   r  r>   r;   )r8  r  r+  rz  r   r  r>   r  )6r   
__module____qualname____doc____annotations__r}   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   propertyrh   r   r   r   r   r   r   r  r  r  r   r  r  r#  r   r   rB  r   
no_defaultrC  r   rK  rO  rY  rk  ry  rt  r  r  ru  rx  r  __classcell__r/   r/   r  r0   rf      s|   
 +

-
H









%	b&
?
%
'
")r:   r;   r<   r=   r>   r;   )rE   rF   rG   rF   r>   r;   )rh   ri   r>   rj   )M
__future__r   typingr   r   r   numpyr   pandas._libsr   pandas._typingr   r   r	   r
   pandas.compatr   r   r   r   r   r   r   pandas.util._decoratorsr   r   pandas.core.dtypes.commonr   r   r   r   r   pandas.core.dtypes.missingr   pandas.core.algorithmsr   pandas.core.arrayliker   pandas.core.arrays.baser   pandas.core.indexersr   r   r   r   r?   pyarrow.computecomputer*   %pandas.core.arrays.arrow._arrow_utilsr    pandas.core.arrays.arrow.dtyper!   r  	not_equallessgreater
less_equalgreater_equalr   r   r+   r3   r4   r   rD   rK   rN   rQ   rT   rc   r   rN  rd   re   rp   rf   r/   r/   r/   r0   <module>   s    $	


	
#
