o
    $jJ                     @  s  d dl mZ d dlmZmZ d dlZd dlZd dl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mZ d d	lmZmZmZ d d
lmZ d dlmZm Z  d dl!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z-m.Z. erd dl/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl)m9Z9m:Z: dPddZ;dQd!d"Z<dRd'd(Z=dSd-d.Z>dTd3d4Z?dUd6d7Z@dVd=d>ZAG d?d@ d@ZBdWdDdEZCdXdHdIZDdYdLdMZEdZdNdOZFdS )[    )annotations)TYPE_CHECKINGcastN)NaTalgos	internalslib)NA)cache_readonly)find_stack_level)ensure_dtype_can_hold_nafind_common_type)is_1d_only_ea_dtype	is_scalarneeds_i8_conversion)concat_compat)ExtensionDtypeSparseDtype)is_valid_na_for_dtypeisnaisna_all)ensure_wrapped_if_datetimelike)ArrayManager)ensure_block_shapenew_block_2d)BlockManagermake_na_array)Sequence)	ArrayLikeAxisIntDtypeObj	Manager2DShape)Index)BlockBlockPlacementmgrslist[ArrayManager]axeslist[Index]concat_axisr   returnr!   c                 C  s4   |dkr| d  | |S |dksJ | d | |S )z
    Concatenate array managers into one.

    Parameters
    ----------
    mgrs_indexers : list of (ArrayManager, {axis: indexer,...}) tuples
    axes : list of Index
    concat_axis : int

    Returns
    -------
    ArrayManager
       r   )Zconcat_verticalconcat_horizontal)r&   r(   r*    r.   ]/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/core/internals/concat.py_concatenate_array_managersF   s   r0   copyboolc                   s  |o|dk}t | d d trt|| |}t|||S |dkr-t|| |}|d ||S t| dkrt| d d jdkrt| d d jd j  t	j
t	jfv rtt fdd| D rtt| dkrttdd |D }t| | }t|f|S t|| |}t|dkr|d }|jdd}	||	_|	S t|}
g }|
D ]c\}}|d }|j}t|rdd	 |D }|jst	j|dd
}nt|jrt|ddd}t|dd}nt|dd
}t|}|jj|jk}nt||d}d}|r|j||d}nt||d}|| qtt||S )z
    Concatenate block managers into one.

    Parameters
    ----------
    mgrs_indexers : list of (BlockManager, {axis: indexer,...}) tuples
    axes : list of Index
    concat_axis : int
    copy : bool

    Returns
    -------
    BlockManager
    r   c                 3  s    | ]
\}}t | V  qd S N)_is_homogeneous_mgr.0mgr_first_dtyper.   r/   	<genexpr>       z'concatenate_managers.<locals>.<genexpr>r,   c                 s      | ]}t |V  qd S r3   )lenr6   xr.   r.   r/   r;          F)deepc                 S     g | ]}|j jqS r.   )blockvaluesr6   Zjur.   r.   r/   
<listcomp>       z(concatenate_managers.<locals>.<listcomp>axisTrJ   Zea_compat_axis   )ndim)r1   )	placement) 
isinstancer   _maybe_reindex_columns_na_proxyr0   r-   r>   nblocksblocksdtypenpfloat64Zfloat32alltuple_concat_homogeneous_fastpathr   r1   r(   _get_combined_planrD   _is_uniform_join_unitsis_extensionconcatenater   r   r   r   rE   _concatenate_join_unitsZmake_block_same_classr   append)mgrs_indexersr(   r*   r1   
needs_copyr&   shapenbr7   outZconcat_planrR   rN   
join_unitsunitblkvalsrE   Zfastpathbr.   r9   r/   concatenate_managers^   s\   

ri   r_   0list[tuple[BlockManager, dict[int, np.ndarray]]]r`   list[BlockManager]c                 C  sb   g }|D ]*\}}|  D ]\}}|j| | || |ddddd}q|r)|s)| }|| q|S )z
    Reindex along columns so that all of the BlockManagers being concatenated
    have matching columns.

    Columns added in this reindexing have dtype=np.void, indicating they
    should be ignored when choosing a column's final dtype.
    FT)rJ   r1   Z
only_sliceZ
allow_dupsZuse_na_proxy)itemsZreindex_indexerr1   r^   )r(   r_   r`   Znew_mgrsr7   indexersiindexerr.   r.   r/   rP      s    	rP   r7   r   r:   r    c                 C  s<   | j dkrdS | jd }|jjr|jjjdksdS |j|kS )zC
    Check if this Manager can be treated as a single ndarray.
    r,   Fr   )rQ   rR   mgr_locsis_slice_likeas_slicesteprS   )r7   r:   rf   r.   r.   r/   r4      s   


r4   ra   r"   np.dtyper$   c                 C  s  t dd | D r&dd | D }t|j}tt|d }t||}|S tj||d}|tj	kr6t
j}nt
j}d}| D ]8\}	}
|	jd }|| }d|
v rc||	jd j|
d |dd||f  n|	jd j|dd||f< ||7 }q=tt|d }t||}|S )	zl
    With single-Block managers with homogeneous dtypes (that can already hold nan),
    we avoid [...]
    c                 s  s    | ]\}}| V  qd S r3   r.   )r6   r8   rm   r.   r.   r/   r;         z/_concat_homogeneous_fastpath.<locals>.<genexpr>c                 S  s   g | ]\}}|j d  jjqS )r   )rR   rE   Tr5   r.   r.   r/   rG     s    z0_concat_homogeneous_fastpath.<locals>.<listcomp>r   rS   r,   N)rV   rT   r\   rv   libinternalsr%   slicer   emptyrU   libalgosZtake_2d_axis0_float64_float64Ztake_2d_axis0_float32_float32ra   rR   rE   )r_   ra   r:   ZarrsZarrbprb   Z	take_funcstartr7   rm   Zmgr_lenendr.   r.   r/   rX      s2   






rX   +list[tuple[BlockPlacement, list[JoinUnit]]]c                 C  s   g }| d j d }dd | D }t|}t|D ]-\}\}}g }t| D ]\}	}
||	 }t|
|||d}t|}|| q%|||f q|S )Nr   c                 S  s   g | ]}|j qS r.   )blknos)r6   r7   r.   r.   r/   rG   /  s    z&_get_combined_plan.<locals>.<listcomp>)max_len)ra   rx   Zget_concat_blkno_indexers	enumerate_get_block_for_concat_planJoinUnitr^   )r&   Zplanr   Zblknos_listpairsindr   r|   Zunits_for_bpkr7   blknorb   re   r.   r.   r/   rY   (  s   
rY   r|   r%   r   intr   c                C  sx   | j | }t|t|jkr|jjr|jjjdkr|}|S | j|j }t	||}t
|tr5||}|S ||}|S )Nr,   )rR   r>   rp   rq   rr   rs   Zblklocsro   r   Zmaybe_indices_to_slicerO   ry   Zslice_block_columnsZtake_block_columns)r7   r|   r   r   rf   rb   Zax0_blk_indexerZslcr.   r.   r/   r   B  s   



r   c                   @  sP   e Zd ZdddZddd	ZdddZedddZedddZdddZ	dS )r   rD   r$   r+   Nonec                 C  s
   || _ d S r3   )rD   )selfrD   r.   r.   r/   __init___  s   
zJoinUnit.__init__strc                 C  s   t | j dt| j dS )N())type__name__reprrD   )r   r.   r.   r/   __repr__b  s   zJoinUnit.__repr__rS   r    r2   c                   s   | j sdS | j}|jjdkrdS |jtkr'|j}t fdd|jddD S |j}|t	u r5|j kr5dS |t
u r?t r?dS t| S )z
        Check that we are all-NA of a type/dtype that is compatible with this dtype.
        Augments `self.is_na` with an additional check of the type of NA values.
        FVTc                 3  s    | ]}t | V  qd S r3   )r   r?   rw   r.   r/   r;   s  ru   z,JoinUnit._is_valid_na_for.<locals>.<genexpr>K)order)is_narD   rS   kindobjectrE   rV   Zravel
fill_valuer   r	   r   r   )r   rS   rf   rE   na_valuer.   rw   r/   _is_valid_na_fore  s   

zJoinUnit._is_valid_na_forc                 C  s   | j }|jjdkrdS |jsdS |j}|jdkrdS t|jtr"dS |jdkr9|d }t	|r3t
|s5dS t|S |d d }t	|rGt
|sIdS tdd |D S )Nr   TFr   r,   c                 s  r=   r3   )r   )r6   rowr.   r.   r/   r;     rA   z!JoinUnit.is_na.<locals>.<genexpr>)rD   rS   r   Z_can_hold_narE   sizerO   r   rM   r   r   r   rV   )r   rf   rE   valr.   r.   r/   r     s&   

zJoinUnit.is_nac                 C  s   | j }|jjdkrdS dS )z{
        Will self.is_na be True after values.size == 0 deprecation and isna_all
        deprecation are enforced?
        r   TFrD   rS   r   )r   rf   r.   r.   r/   )is_na_after_size_and_isna_all_deprecation  s   z2JoinUnit.is_na_after_size_and_isna_all_deprecationempty_dtyper   c                 C  s   |d u r| j jjdkr| j jS |}| |r<| j j}|tdkr4ttj| j j}|jr4|d d u r4d }t	|| j j
|S | j jS )Nr   r   )r   r   )rD   rS   r   rE   r   rT   r   Zndarrayr   r   ra   )r   r   upcasted_nar   Z	blk_dtyperE   r.   r.   r/   get_reindexed_values  s   
zJoinUnit.get_reindexed_valuesN)rD   r$   r+   r   )r+   r   )rS   r    r+   r2   )r+   r2   )r   r    r+   r   )
r   
__module____qualname__r   r   r   r
   r   r   r   r.   r.   r.   r/   r   ^  s    


 
r   rd   list[JoinUnit]r   c                   s   t | \ }tdd | D }t | fdd| D }tdd |D r;dd |D }t|ddd	}t|d
}nt|dd} |krS |jkrStjdtt	 d |S )zB
    Concatenate values from several join units along axis=1.
    c                 s      | ]
}|j jjd kV  qdS r   Nr   r6   re   r.   r.   r/   r;     r<   z*_concatenate_join_units.<locals>.<genexpr>c                   s   g | ]	}|j  d qS )r   r   )r   rF   r   r.   r/   rG     s    z+_concatenate_join_units.<locals>.<listcomp>c                 s  s    | ]}t |jV  qd S r3   r   rS   r6   tr.   r.   r/   r;     ru   c                 S  s*   g | ]}t |jr|n|d ddf qS )r   Nr   r   r.   r.   r/   rG     s    r   TrK   rL   r,   rI   a  The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.)
stacklevel)
_get_empty_dtypeany_dtype_to_na_valuer   r   rS   warningswarnFutureWarningr   )rd   r1   Zempty_dtype_futurehas_none_blocksZ	to_concatZconcat_valuesr.   r   r/   r]     s*   

	r]   rS   r   c                 C  sr   t | tr| jS | jdv r| dS | jdv r| dS | jdkr#dS | jdv r/|s,dS tjS | jdkr7tjS t)	z2
    Find the NA value to go with this dtype.
    ZmMr   fcNaNrh   NiuO)rO   r   r   r   r   rT   nanNotImplementedError)rS   r   r.   r.   r/   r     s   







r   Sequence[JoinUnit]tuple[DtypeObj, DtypeObj]c                 C  s   t dd | D r| d jj}||fS tdd | D }dd | D }t|s/dd | D }t|}|r9t|}|}t|t| krgdd | D }t|sUd	d | D }t|t|krgt|}|rgt|}||fS )
z
    Return dtype and N/A values to use when concatenating specified units.

    Returned N/A value may be None which means there was no casting involved.

    Returns
    -------
    dtype
    c                 S  rC   r.   )rD   rS   rF   r.   r.   r/   rG     rH   z$_get_empty_dtype.<locals>.<listcomp>r   c                 s  r   r   r   r   r.   r.   r/   r;     r<   z#_get_empty_dtype.<locals>.<genexpr>c                 S     g | ]	}|j s|jjqS r.   )r   rD   rS   r   r.   r.   r/   rG     s    c                 S  "   g | ]}|j jjd kr|j jqS r   r   r   r.   r.   r/   rG          c                 S  r   r.   )r   rD   rS   r   r.   r.   r/   rG   *  s    c                 S  r   r   r   r   r.   r.   r/   rG   0  r   )r   Zdtypes_all_equalrD   rS   r   r>   r   r   )rd   r   r   ZdtypesrS   Zdtype_futureZdtypes_futurer.   r.   r/   r     s4   
r   c                   sX   | d j   jjdkrdS t fdd| D o+t fdd| D o+tdd | D S )z
    Check if the join units consist of blocks of uniform type that can
    be concatenated using Block.concat_same_type instead of the generic
    _concatenate_join_units (which uses `concat_compat`).

    r   r   Fc                 3  s"    | ]}t |jt  u V  qd S r3   )r   rD   rF   firstr.   r/   r;   H  s     z)_is_uniform_join_units.<locals>.<genexpr>c                 3  s,    | ]}|j j jkp|j jjd v V  qdS )ZiubNr   rF   r   r.   r/   r;   K  s    
c                 s  s     | ]}|j  p|jjV  qd S r3   )r   rD   r[   rF   r.   r.   r/   r;   U  s    )rD   rS   r   rV   )rd   r.   r   r/   rZ   <  s   
rZ   )r&   r'   r(   r)   r*   r   r+   r!   )r(   r)   r*   r   r1   r2   r+   r!   )r(   r)   r_   rj   r`   r2   r+   rk   )r7   r   r:   r    r+   r2   )ra   r"   r:   rt   r+   r$   )r&   rk   r+   r   )
r7   r   r|   r%   r   r   r   r   r+   r$   )rd   r   r1   r2   r+   r   )rS   r    r   r2   )rd   r   r+   r   )rd   r   r+   r2   )G
__future__r   typingr   r   r   numpyrT   Zpandas._libsr   r   r{   r   rx   r   Zpandas._libs.missingr	   Zpandas.util._decoratorsr
   Zpandas.util._exceptionsr   Zpandas.core.dtypes.castr   r   Zpandas.core.dtypes.commonr   r   r   Zpandas.core.dtypes.concatr   Zpandas.core.dtypes.dtypesr   r   Zpandas.core.dtypes.missingr   r   r   Zpandas.core.constructionr   Z#pandas.core.internals.array_managerr   Zpandas.core.internals.blocksr   r   Zpandas.core.internals.managersr   r   collections.abcr   Zpandas._typingr   r   r    r!   r"   Zpandasr#   r$   r%   r0   ri   rP   r4   rX   rY   r   r   r]   r   r   rZ   r.   r.   r.   r/   <module>   sD    


l
"

/

k
.
.