o
    ôT·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)ÚAxiszôSorting 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 © )Ú	_get_axis)Ú.0Úobj©r   r#   úZ/home/dinkstrade/pdmp-scanner/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!   Ú	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+   ÚidsÚresr&   r#   r#   r(   Ú_get_distinct_objsj   s   
€r4   Ú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    )r4   Úlenr   Úintersectionr   r   r   r!   )r5   r   r    r!   ÚindexÚotherr#   r#   r(   r*   x   s"   

ÿr*   r:   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)Úis_monotonic_increasingr
   Ú	TypeErrorÚ
isinstancer   r   ÚnpÚndarrayr   Úfrom_tuplesr<   r=   r>   )r:   Ú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r‚d‰dd„ ˆD ƒ‰ˆd }ˆdd… D ]}|j|ˆr‘d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 unionr6   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)rA   r   ©r%   Úindr#   r#   r(   Ú	<genexpr>ô   ó   € z9union_indexes.<locals>._unique_indices.<locals>.<genexpr>c                   s   g | ]	}|j ˆ d d�‘qS ©F)r!   )ÚastyperH   ©r>   r#   r(   r)   õ   ó    z:union_indexes.<locals>._unique_indices.<locals>.<listcomp>r   r6   é   Néÿÿÿÿc                 S  s   t | tƒr	|  ¡ } | S rG   )rA   r   Útolist)Úir#   r#   r(   Úconvÿ   s   
z4union_indexes.<locals>._unique_indices.<locals>.convc                   s   g | ]}ˆ |ƒ‘qS r#   r#   )r%   rS   )rT   r#   r(   r)     ó    r7   rN   )	ÚallÚuniquer1   Úget_indexer_forr8   Úsort_valuesr   r   Úfast_unique_multiple_list)Úindsr>   Úresultr;   Údiffr7   )rT   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#   )rA   r   r>   )r%   Úidxr#   r#   r(   r)     s    zCunion_indexes.<locals>._find_common_index_dtype.<locals>.<listcomp>Nr   )r[   Údtypesr>   )r5   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#   )rA   r   ©r%   Úxr#   r#   r(   r)      rO   z!union_indexes.<locals>.<listcomp>c                 S  s   g | ]	}|j d ur|‘qS rG   )Útzrc   r#   r#   r(   r)   !  rO   z0Cannot join tz-naive with tz-aware DatetimeIndexTFc                 S  s   g | ]	}|j td d�‘qS rL   )rM   Úobjectrc   r#   r#   r(   r)   4  rO   Nr7   Úarrayc                 3  ó   � | ]}ˆ   |¡V  qd S rG   ©Úequals)r%   r;   )r:   r#   r(   rJ   >  rK   z union_indexes.<locals>.<genexpr>)r"   r   )r8   ÚAssertionErrorrA   Úlistr   ÚsortedÚ_sanitize_and_checkr@   ÚunionrV   r   r=   Úrename)r5   r    r\   Úkindr^   ra   ÚdtisÚdti_tzsr;   r>   r=   r#   )r:   r5   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%   r:   r#   r#   r(   Ú	<setcomp>_  rU   z&_sanitize_and_check.<locals>.<setcomp>r6   c                 S  s&   g | ]}t |tƒstt|ƒƒn|‘qS r#   )rA   r   rl   rc   r#   r#   r(   r)   c  s    ÿz'_sanitize_and_check.<locals>.<listcomp>rl   rb   rg   )rl   r8   Úremover   )r5   Úkindsr#   r#   r(   rn   J  s   ÿrn   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  rh   rG   ri   ru   ©Úfirstr#   r(   rJ     rK   z#all_indexes_same.<locals>.<genexpr>)ÚiterÚnextrV   )r5   Úitrr#   ry   r(   r   p  s   r   ÚnÚintr   c                 C  s   t | ƒ}tj|d d�S )N)r=   )Úranger   Ú_simple_new)r~   Úrngr#   r#   r(   r   ‚  s   r   )Fr   TF)
r   r   r   r   r    r   r!   r   r"   r   )r+   r-   r"   r-   )FFF)
r5   r-   r   r   r    r   r!   r   r"   r   )r:   r   r"   r   )T)r    rF   r"   r   )r"   r   )r~   r   r"   r   )2Ú
__future__r   ÚtextwrapÚtypingr   r   ÚnumpyrB   Úpandas._libsr   r   Úpandas.errorsr   Úpandas.core.dtypes.castr	   Úpandas.core.algorithmsr
   Úpandas.core.indexes.baser   r   r   r   r   Úpandas.core.indexes.categoryr   Úpandas.core.indexes.datetimesr   Úpandas.core.indexes.intervalr   Úpandas.core.indexes.multir   Úpandas.core.indexes.periodr   Úpandas.core.indexes.ranger   Úpandas.core.indexes.timedeltasr   Úpandas._typingr   ÚdedentÚ	_sort_msgÚ__all__r   r4   r*   r   r   rn   r   r   r#   r#   r#   r(   Ú<module>   sL    ÿû
"ü
0" 
&