o
    5c!P                  
   @  s  d dl mZ d dlZd dlmZmZmZ d dlZd dl	m
ZmZ d dlmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ erPd d
lmZ d dlmZ e			dPdQddZe			dPdRddZd ejdfdSddZdTddZ			dUdVd"d#Z ej!fdWd%d&Z"ej#d'd(dXd-d.Z$	dYdXd/d0Z%dZd1d2Z&d3d4 Z'i d5ej(d6ej)d7ej*d8ej+d9ej,d:ej-d;ej.d<ej/d=ej0d>ej1d?ej2d@ej3dAej4dBej5dCej6dDej7dEej8e&ej9ej:ej:e&ej;ej:de&ej3ej<ej<ej<e&ej3ej<ej<ej<dFZ=i d5ej>d6ej?d7ej@d8ejAd9ejBd:ejCd;ejDd<ejEd=ejFd>ejGd?ejHd@ejIdAejJdBejKdCejLdDejMdEejNe&ejOej:ej:e&ejPej:de&ejIej<ej<ej<dGe&ejIej<ej<ej<dGdFZQi d5ejRd6ejSd7ejTd8ejUd9ejVd:ejWd;ejXd<ejYd=ejZd>ej[d?ej\d@ej]dAej^dBej_dCej`dDejadEejbe&ejcej:ej:e&ejdej:de&ej]ej<ej<ej<dGe&ej]ej<ej<ej<dGdFZei d5ejfd6ejgd7ejhd8ejid9ejjd:ejkd;ejld<ejmd=ejnd>ejod?ejpd@ejqdAejrdBejsdCejtdDejudEejve&ejwej:ej:e&ejxej:de&ejqej<ej<ej<dGe&ejqej<ej<ej<dGdFZyd[dIdJZzd\dLdMZ{	d]d^dNdOZ|dS )_    )annotationsN)TYPE_CHECKINGcastoverload)algoslib)	ArrayLikenpt)maybe_promote)ensure_platform_intis_1d_only_ea_obj)na_value_for_dtype)ensure_wrapped_if_datetimelike)NDArrayBackedExtensionArray)ExtensionArray.arr
np.ndarrayaxisint
allow_fillboolreturnc                 C     d S N r   indexerr   
fill_valuer   r   r   R/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/core/array_algos/take.pytake_nd#      r   r   r   c                 C  r   r   r   r   r   r   r   r   .   r    Tc                 C  s   |t ju rt| jdd}nt| jtjr,| jjdv r,t| j|\}}| j|kr,| |} t| tj	sLt
| sDtd| } | j||||dS | j|||dS t| } t| ||||S )a1  
    Specialized Cython take which sets NaN values in one pass

    This dispatches to ``take`` defined on ExtensionArrays. It does not
    currently dispatch to ``SparseArray.take`` for sparse ``arr``.

    Note: this function assumes that the indexer is a valid(ated) indexer with
    no out of bound indices.

    Parameters
    ----------
    arr : np.ndarray or ExtensionArray
        Input array.
    indexer : ndarray
        1-D array of indices to take, subarrays corresponding to -1 value
        indices are filed with fill_value
    axis : int, default 0
        Axis to take from
    fill_value : any, default np.nan
        Fill value to replace -1 values with
    allow_fill : bool, default True
        If False, indexer is assumed to contain no -1 values so no filling
        will be done.  This short-circuits computation of a mask.  Result is
        undefined if allow_fill == False and -1 is present in indexer.

    Returns
    -------
    subarray : np.ndarray or ExtensionArray
        May be the same type as the input, or cast to an ndarray.
    F)compatmMr   )r   r   r   r   r   )r   
no_defaultr   dtype
isinstancenpkindr
   astypendarrayr   r   takeasarray_take_nd_ndarray)r   r   r   r   r   r%   r   r   r   r   9   s   
&



r   npt.NDArray[np.intp] | Nonec                 C  s  |d u rt j| j| t jd}| j| j }}nt|}t| |||\}}}d}| jdkr4| j	j
r4d}|r@| j} | j| d }t| j}t|||< t|}	| j	j
rc|| jd krct j|	|dd}
nt j|	|d}
t| j| j|
j||d}|| ||
| |r|
j}
|
S )	Nr%   F   T   F)r%   orderr   	mask_info)r'   arangeshapeintpr%   typer   '_take_preprocess_indexer_and_fill_valuendimflagsf_contiguousTlistlentupleempty_get_take_nd_function)r   r   r   r   r   r%   r5   
flip_order
out_shape_	out_shapeoutfuncr   r   r   r-   x   s4   

r-   npt.NDArray[np.intp]masknpt.NDArray[np.bool_] | Nonec           	      C  sz   t | tjs| j|||dS |s| |S t| ||d|\}}}tj|j|d}t| j| j	|j	d|d}|| ||| |S )ao  
    Specialized version for 1D arrays. Differences compared to `take_nd`:

    - Assumes input array has already been converted to numpy array / EA
    - Assumes indexer is already guaranteed to be intp dtype ndarray
    - Only works for 1D arrays

    To ensure the lowest possible overhead.

    Note: similarly to `take_nd`, this function assumes that the indexer is
    a valid(ated) indexer with no out of bound indices.

    Parameters
    ----------
    arr : np.ndarray or ExtensionArray
        Input array.
    indexer : ndarray
        1-D array of indices to take (validated indices, intp dtype).
    fill_value : any, default np.nan
        Fill value to replace -1 values with
    allow_fill : bool, default True
        If False, indexer is assumed to contain no -1 values so no filling
        will be done.  This short-circuits computation of a mask. Result is
        undefined if allow_fill == False and -1 is present in indexer.
    mask : np.ndarray, optional, default None
        If `allow_fill` is True, and the mask (where indexer == -1) is already
        known, it can be passed to avoid recomputation.
    r#   Tr/   r   r4   )
r&   r'   r*   r+   r:   rB   r7   rC   r;   r%   )	r   r   r   r   rJ   r%   r5   rG   rH   r   r   r   take_1d   s   #


rL   1tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]c                 C  s\  |dusJ |d dusJ |d dusJ |\}}t |}t |}||f}d}t| j|\}}|| jkrZ|dk}|dk}| }	| }
||f|	|
ff}|	sZ|
sZ| j| j }}t|t|f}tj||d}t	| jj
|jj
fd}|du r| j|jkrt	|jj
|jj
fd}|durt||j}|dur|| |||d |S t| ||||d |S )zD
    Specialized Cython take which sets NaN values in one pass.
    Nr   r1   r/   )rG   r   )r   r5   )r   r
   r%   anyr9   r@   r'   rB   _take_2d_multi_dictgetname_convert_wrapper_take_2d_multi_object)r   r   r   row_idxcol_idxr5   r%   row_maskcol_mask	row_needs	col_needsrF   rG   rH   r   r   r   take_2d_multi   s>   


r[      )maxsizer;   	arr_dtypenp.dtype	out_dtypec                 C  s   |j |j f}| dkrt|d}n| dkr&|dkr t|d}nt|d}|dur,|S |j |j f}| dkr=t|d}n| dkrR|dkrLt|d}nt|d}|dur]t||}|S dS )z
    Part of _get_take_nd_function below that doesn't need `mask_info` and thus
    can be cached (mask_info potentially contains a numpy ndarray which is not
    hashable and thus cannot be used as argument for cached function).
    r1   Nr0   r   )rR   _take_1d_dictrQ   _take_2d_axis0_dict_take_2d_axis1_dictrS   )r;   r^   r`   r   tuprH   r   r   r   _get_take_nd_function_cached   s(   	
re   c                   s:   d}| dkrt | || }|du rtjf fdd	}|S )za
    Get the appropriate "take" implementation for the given dimension, axis
    and dtypes.
    Nr0   c                   s    t |}t| || |d d S )N)r   r   r5   )r   _take_nd_objectr   r   rG   r   r4   r   r   rH   T  s   
z#_get_take_nd_function.<locals>.func)re   r'   nan)r;   r^   r`   r   r5   rH   r   r4   r   rC   F  s   rC   c                   s   t jfd fdd}|S )Nr   r   r   rG   c                   sH    d ur	|   } d ur| }d ur|}| |||d d S N)r   )viewrg   r^   f	fill_wrapr`   r   r   wrapper^  s   

z_view_wrapper.<locals>.wrapperr   r   r   r   rG   r   r'   rh   )rl   r^   r`   rm   rn   r   rk   r   _view_wrapper]  s   rq   c                   s   t jfd fdd}|S )Nr   r   r   rG   c                   s.    t krt| } |  } | |||d d S ri   )objectr   r)   rg   
conv_dtyperl   r   r   rn   m  s   
z!_convert_wrapper.<locals>.wrapperro   rp   )rl   rt   rn   r   rs   r   rS   l  s   	rS   )int8ru   )ru   int32)ru   int64)ru   float64)int16ry   )ry   rv   )ry   rw   )ry   rx   )rv   rv   )rv   rw   )rv   rx   )rw   rw   )rw   rx   )float32rz   )rz   rx   )rx   rx   )rr   rr   ))r   r   )r   rr   )datetime64[ns]r{   )timedelta64[ns]r|   )rm   rG   c           	      C  s   |d ur	|\}}n|dk}|  }| j|jkr| |j} | j| dkr,| j|||d |rBtd g| j }|||< ||t|< d S d S )NrN   r   )r   rG   )rO   r%   r)   r7   r+   slicer;   rA   )	r   r   rG   r   r   r5   rJ   needs_masking
outindexerr   r   r   rf     s   
rf   Nonec                 C  s   |\}}|d ur|\\}}\}	}
n|dk}|dk}|  }	|  }
|d ur9|	r/|||d d f< |
r9||d d |f< tt|D ]}|| }tt|D ]}|| }| ||f |||f< qKq?d S )NrN   )rO   ranger@   )r   r   rG   r   r5   rU   rV   rW   rX   rY   rZ   iu_jvr   r   r   rT     s&   	rT   c                 C  s   d }|s| j | j  }}d}n-t| j |\}}|| j kr=|d ur$d}n
|dk}t| }||f}|s=| j | j  }}|||fS )N)NFTrN   )r%   r9   r
   r   rO   )r   r   r   r   rJ   r5   r%   r~   r   r   r   r:   *  s   

r:   )...)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )
r   r   r   r.   r   r   r   r   r   r   )NTN)
r   r   r   rI   r   r   rJ   rK   r   r   )r   r   r   rM   r   r   )r;   r   r^   r_   r`   r_   r   r   )r   N)NNN)r   r   r   rI   rG   r   r   r   )r   r   r   rM   rG   r   r   r   r   )r   r   r   rI   r   r   rJ   rK   )}
__future__r   	functoolstypingr   r   r   numpyr'   pandas._libsr   libalgosr   pandas._typingr   r	   pandas.core.dtypes.castr
   pandas.core.dtypes.commonr   r   pandas.core.dtypes.missingr   pandas.core.constructionr   pandas.core.arrays._mixinsr   pandas.core.arrays.baser   r   r$   r-   rL   rh   r[   	lru_cachere   rC   rq   rS   take_1d_int8_int8take_1d_int8_int32take_1d_int8_int64take_1d_int8_float64take_1d_int16_int16take_1d_int16_int32take_1d_int16_int64take_1d_int16_float64take_1d_int32_int32take_1d_int32_int64take_1d_int32_float64take_1d_int64_int64take_1d_int64_float64take_1d_float32_float32take_1d_float32_float64take_1d_float64_float64take_1d_object_objecttake_1d_bool_booluint8take_1d_bool_objectrw   ra   take_2d_axis0_int8_int8take_2d_axis0_int8_int32take_2d_axis0_int8_int64take_2d_axis0_int8_float64take_2d_axis0_int16_int16take_2d_axis0_int16_int32take_2d_axis0_int16_int64take_2d_axis0_int16_float64take_2d_axis0_int32_int32take_2d_axis0_int32_int64take_2d_axis0_int32_float64take_2d_axis0_int64_int64take_2d_axis0_int64_float64take_2d_axis0_float32_float32take_2d_axis0_float32_float64take_2d_axis0_float64_float64take_2d_axis0_object_objecttake_2d_axis0_bool_booltake_2d_axis0_bool_objectrb   take_2d_axis1_int8_int8take_2d_axis1_int8_int32take_2d_axis1_int8_int64take_2d_axis1_int8_float64take_2d_axis1_int16_int16take_2d_axis1_int16_int32take_2d_axis1_int16_int64take_2d_axis1_int16_float64take_2d_axis1_int32_int32take_2d_axis1_int32_int64take_2d_axis1_int32_float64take_2d_axis1_int64_int64take_2d_axis1_int64_float64take_2d_axis1_float32_float32take_2d_axis1_float32_float64take_2d_axis1_float64_float64take_2d_axis1_object_objecttake_2d_axis1_bool_booltake_2d_axis1_bool_objectrc   take_2d_multi_int8_int8take_2d_multi_int8_int32take_2d_multi_int8_int64take_2d_multi_int8_float64take_2d_multi_int16_int16take_2d_multi_int16_int32take_2d_multi_int16_int64take_2d_multi_int16_float64take_2d_multi_int32_int32take_2d_multi_int32_int64take_2d_multi_int32_float64take_2d_multi_int64_int64take_2d_multi_int64_float64take_2d_multi_float32_float32take_2d_multi_float32_float64take_2d_multi_float64_float64take_2d_multi_object_objecttake_2d_multi_bool_booltake_2d_multi_bool_objectrP   rf   rT   r:   r   r   r   r   <module>   s   

?5=
<&
	
	

 	

 	


!
"