o
    $j(                     @  sX  d dl mZ d dlZd dlmZmZ d dl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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  d dl!m"Z" d dl#m$Z$ erpd dl%m&Z& e'dZ(g dZ)		 		d5d6ddZ*d7d!d"Z+			d8d9d$d%Z,d:d'd(Z-d;d<d*d+Z.d,d- Z/d=d.d/Z0d>d3d4Z1dS )?    )annotationsN)TYPE_CHECKINGcast)NaTlib)InvalidIndexErrorfind_common_type)	safe_sort)Index
_new_Indexensure_indexensure_index_from_sequencesget_unanimous_names)CategoricalIndex)DatetimeIndex)IntervalIndex)
MultiIndex)PeriodIndex)
RangeIndex)TimedeltaIndex)AxiszSorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.
)r   r   r   r   r   r   r   r   r   r   r   r   r   get_objs_combined_axisunion_indexesr   all_indexes_samedefault_indexsafe_sort_indexFT	intersectboolaxisr   sortcopyreturnr   c                   s"    fdd| D }t ||||dS )a  
    Extract combined index: return intersection or union (depending on the
    value of "intersect") of indexes on given axis, or None if all objects
    lack indexes (e.g. they are numpy arrays).

    Parameters
    ----------
    objs : list
        Series or DataFrame objects, may be mix of the two.
    intersect : bool, default False
        If True, calculate the intersection between indexes. Otherwise,
        calculate the union.
    axis : {0 or 'index', 1 or 'outer'}, default 0
        The axis to extract indexes from.
    sort : bool, default True
        Whether the result index should come out sorted or not.
    copy : bool, default False
        If True, return a copy of the combined index.

    Returns
    -------
    Index
    c                   s   g | ]}|  qS  )Z	_get_axis).0objr   r#   X/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/core/indexes/api.py
<listcomp>f   s    z*get_objs_combined_axis.<locals>.<listcomp>)r   r    r!   )_get_combined_index)objsr   r   r    r!   Z	obs_idxesr#   r&   r'   r   H   s   r   r*   list[Index]c                 C  s<   t  }g }| D ]}t||vr|t| || q|S )z^
    Return a list with distinct elements of "objs" (different ids).
    Preserves order.
    )setidaddappend)r*   Zidsresr%   r#   r#   r'   _get_distinct_objsj   s   
r1   indexesc                 C  s   t | } t| dkrtg }n*t| dkr| d }n|r/| d }| dd D ]}||}q&n
t| dd}t|}|r?t|}|rE| }|S )a  
    Return the union or intersection of indexes.

    Parameters
    ----------
    indexes : list of Index or list objects
        When intersect=True, do not accept list of lists.
    intersect : bool, default False
        If True, calculate the intersection between indexes. Otherwise,
        calculate the union.
    sort : bool, default False
        Whether the result index should come out sorted or not.
    copy : bool, default False
        If True, return a copy of the combined index.

    Returns
    -------
    Index
    r      NFr    )r1   lenr   intersectionr   r   r   r!   )r2   r   r    r!   indexotherr#   r#   r'   r)   x   s"   

r)   r7   c                 C  sz   | j r| S zt| }W n
 ty   Y | S w t|tr|S ttj|}t| tr2tj	|| j
d} | S t|| j| jd} | S )z
    Returns the sorted index

    We keep the dtypes and the name attributes.

    Parameters
    ----------
    index : an Index

    Returns
    -------
    Index
    )names)namedtype)Zis_monotonic_increasingr
   	TypeError
isinstancer   r   npZndarrayr   from_tuplesr9   r:   r;   )r7   Zarray_sortedr#   r#   r'   r      s    

r   bool | Nonec                   s  t dkr
tdt dkr)d }t|tr's!t|}|S tt|}|S t\}dfdd}fdd	}|d
krd }dd D }dd |D }t |dt |fvr`tdt |t krodd }nt |dkrddd D d }dd D ]}|j|rdndd}q|S |dkr|}	d  t	 fdddd D s||	 t
 d }
|
 jkrȈ |
  S |}	||	S )a)  
    Return the union of indexes.

    The behavior of sort and names is not consistent.

    Parameters
    ----------
    indexes : list of Index or list objects
    sort : bool, default True
        Whether the result index should come out sorted or not.

    Returns
    -------
    Index
    r   z#Must have at least 1 Index to unionr3   r"   r   c                   s   t dd | D r?fdd| D } | d  }| d | dd }|||d	k }t|r7|| }r=| }|S d
d  ttj fdd| D ddS )z
        Concatenate indices and remove duplicates.

        Parameters
        ----------
        inds : list of Index or list objects
        dtype : dtype to set for the resulting Index

        Returns
        -------
        Index
        c                 s  s    | ]}t |tV  qd S N)r=   r   r$   indr#   r#   r'   	<genexpr>       z9union_indexes.<locals>._unique_indices.<locals>.<genexpr>c                   s   g | ]	}|j  d dqS F)r!   )astyperB   r;   r#   r'   r(          z:union_indexes.<locals>._unique_indices.<locals>.<listcomp>r   r3      Nc                 S  s   t | tr	|  } | S rA   )r=   r   tolist)ir#   r#   r'   conv   s   
z4union_indexes.<locals>._unique_indices.<locals>.convc                   s   g | ]} |qS r#   r#   )r$   rM   )rN   r#   r'   r(         r4   rH   )	alluniquer/   Zget_indexer_forr5   Zsort_valuesr   r   Zfast_unique_multiple_list)indsr;   resultr8   diffr4   )rN   r;   r'   _unique_indices   s   z&union_indexes.<locals>._unique_indicesc                   s&   dd  D }|rt |}|S d}|S )a  
        Finds a common type for the indexes to pass through to resulting index.

        Parameters
        ----------
        inds: list of Index or list objects

        Returns
        -------
        The common type or None if no indexes were given
        c                 S  s   g | ]
}t |tr|jqS r#   )r=   r   r;   )r$   idxr#   r#   r'   r(     s    zCunion_indexes.<locals>._find_common_index_dtype.<locals>.<listcomp>Nr   )rR   Zdtypesr;   )r2   r#   r'   _find_common_index_dtype	  s   z/union_indexes.<locals>._find_common_index_dtypespecialc                 S  s   g | ]	}t |tr|qS r#   )r=   r   r$   xr#   r#   r'   r(      rI   z!union_indexes.<locals>.<listcomp>c                 S  s   g | ]	}|j d ur|qS rA   )tzrY   r#   r#   r'   r(   !  rI   z0Cannot join tz-naive with tz-aware DatetimeIndexTFc                 S  s   g | ]	}|j td dqS rF   )rG   objectrY   r#   r#   r'   r(   4  rI   Nr4   arrayc                 3      | ]}  |V  qd S rA   equals)r$   r8   )r7   r#   r'   rD   >  rE   z union_indexes.<locals>.<genexpr>)r"   r   )r5   AssertionErrorr=   listr   sorted_sanitize_and_checkr<   unionrP   r   r:   rename)r2   r    rS   kindrU   rW   ZdtisZdti_tzsr8   r;   r:   r#   )r7   r2   r    r'   r      sP   
"




r   c                 C  sl   t dd | D }t |v r$t|dkr dd | D } |t  n| dfS t|dks.t|vr2| dfS | dfS )	aN  
    Verify the type of indexes and convert lists to Index.

    Cases:

    - [list, list, ...]: Return ([list, list, ...], 'list')
    - [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...])
        Lists are sorted and converted to Index.
    - [Index, Index, ...]: Return ([Index, Index, ...], TYPE)
        TYPE = 'special' if at least one special type, 'array' otherwise.

    Parameters
    ----------
    indexes : list of Index or list objects

    Returns
    -------
    sanitized_indexes : list of Index or list objects
    type : {'list', 'array', 'special'}
    c                 S  s   h | ]}t |qS r#   )typer$   r7   r#   r#   r'   	<setcomp>_  rO   z&_sanitize_and_check.<locals>.<setcomp>r3   c                 S  s&   g | ]}t |tstt|n|qS r#   )r=   r   rb   rY   r#   r#   r'   r(   c  s    z'_sanitize_and_check.<locals>.<listcomp>rb   rX   r]   )rb   r5   remover   )r2   kindsr#   r#   r'   rd   J  s   rd   c                   s&   t | }t| t fdd|D S )z
    Determine if all indexes contain the same elements.

    Parameters
    ----------
    indexes : iterable of Index objects

    Returns
    -------
    bool
        True if all indexes contain the same elements, False otherwise.
    c                 3  r^   rA   r_   ri   firstr#   r'   rD     rE   z#all_indexes_same.<locals>.<genexpr>)iternextrP   )r2   itrr#   rm   r'   r   p  s   r   nintr   c                 C  s   t | }tj|d dS )N)r:   )ranger   Z_simple_new)rr   rngr#   r#   r'   r     s   r   )Fr   TF)
r   r   r   r   r    r   r!   r   r"   r   )r*   r+   r"   r+   )FFF)
r2   r+   r   r   r    r   r!   r   r"   r   )r7   r   r"   r   )T)r    r@   r"   r   )r"   r   )rr   rs   r"   r   )2
__future__r   textwraptypingr   r   numpyr>   Zpandas._libsr   r   Zpandas.errorsr   Zpandas.core.dtypes.castr	   Zpandas.core.algorithmsr
   Zpandas.core.indexes.baser   r   r   r   r   Zpandas.core.indexes.categoryr   Zpandas.core.indexes.datetimesr   Zpandas.core.indexes.intervalr   Zpandas.core.indexes.multir   Zpandas.core.indexes.periodr   Zpandas.core.indexes.ranger   Zpandas.core.indexes.timedeltasr   Zpandas._typingr   dedentZ	_sort_msg__all__r   r1   r)   r   r   rd   r   r   r#   r#   r#   r'   <module>   sL    
"
0" 
&