
    Eg(                    `   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rd dl%m&Z&  ej'        d          Z(g dZ)	 	 	 	 d-d.dZ*d/d Z+	 	 	 d0d1d"Z,d2d$Z-d3d4d&Z.d' Z/d5d(Z0d6d,Z1dS )7    )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                F    fd| D             }t          ||||          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                :    g | ]}|                               S  )	_get_axis).0objr    s     L/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/indexes/api.py
<listcomp>z*get_objs_combined_axis.<locals>.<listcomp>f   s%    555t$$555    )r   r!   r"   )_get_combined_index)objsr   r    r!   r"   	obs_idxess     `   r*   r   r   H   s5    < 6555555IyIDtTTTTr,   r.   list[Index]c                    t                      }g }| D ]J}t          |          |vr7|                    t          |                     |                    |           K|S )z^
    Return a list with distinct elements of "objs" (different ids).
    Preserves order.
    )setidaddappend)r.   idsresr)   s       r*   _get_distinct_objsr8   j   s_    
 EEC
C  c77#GGBsGGJJsOOOJr,   indexesc                   t          |           } t          |           dk    rt          g           }nit          |           dk    r	| d         }nM|r+| d         }| dd         D ]}|                    |          }n t	          | d          }t          |          }|rt          |          }|r|                                }|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!   )r8   lenr   intersectionr   r   r   r"   )r9   r   r!   r"   indexothers         r*   r-   r-   x   s    4 !))G
7||qb			W		
	 $
QRR[ 	. 	.E&&u--EE	. gE222U## '&& 

Lr,   r?   c                V   | j         r| S 	 t          |           }t          |t                    r|S t	          t
          j        |          }t          | t                    rt          j        || j	                  } n-t          || j
        | j                  } n# t          $ r Y nw xY w| 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   
isinstancer   r   npndarrayr   from_tuplesrB   rC   rD   	TypeError)r?   array_sorteds     r*   r   r      s     $ L '' lE** 	 BJ55eZ(( 	L*<u{KKKEE,UZu{KKKEE     Ls   B 
B&%B&bool | Nonec                    t                     dk    rt          d          t                     dk    rM d         }t          |t                    r.st	          |          }nt	          t          |                    }|S t                     \   }dfd} fd}|dk    r͉ d         }d	  D             }d
 |D             }t          |          dt          |          fvrt          d          t          |          t                     k    rd d         }n)t          |          dk    rdd  D               d         } dd         D ]}|                    |rdnd          }|S |dk    rs |           }	 d         t          f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 unionr;   r#   r   c                   t          d | D                       rfd| D             } | d                                         }| d                             | dd                   }||                    |          dk             }t	          |          r'|                    |                                          }r|                                }|S d t          t          j        f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              3  @   K   | ]}t          |t                    V  d S N)rF   r   )r(   inds     r*   	<genexpr>z9union_indexes.<locals>._unique_indices.<locals>.<genexpr>   s,      66#z#u%%666666r,   c                >    g | ]}|                     d           S F)r"   )astype)r(   rQ   rD   s     r*   r+   z:union_indexes.<locals>._unique_indices.<locals>.<listcomp>   s)    BBBcCJJu5J11BBBr,   r   r;      Nc                X    t          | t                    r|                                 } | S rP   )rF   r   tolist)is    r*   convz4union_indexes.<locals>._unique_indices.<locals>.conv   s&    !U## HHJJHr,   c                &    g | ]} |          S r&   r&   )r(   rZ   r[   s     r*   r+   z:union_indexes.<locals>._unique_indices.<locals>.<listcomp>  s!    *A*A*Aq4477*A*A*Ar,   r<   )rD   )	alluniquer5   get_indexer_forr=   sort_valuesr   r   fast_unique_multiple_list)indsrD   resultr@   diffr[   r!   s    `   @r*   _unique_indicesz&union_indexes.<locals>._unique_indices   s$    6666666 		BBBBTBBBD!W^^%%FGNN48,,E//66"<=D4yy 6t{{}}55 .++--M	 	 	
 )*A*A*A*AD*A*A*AMMM
 
 
 	
r,   c                H    d D             }|rt          |          }n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                F    g | ]}t          |t                    |j        S r&   )rF   r   rD   )r(   idxs     r*   r+   zCunion_indexes.<locals>._find_common_index_dtype.<locals>.<listcomp>  s)    III*S%2H2HI#)IIIr,   Nr	   )rb   dtypesrD   r9   s      r*   _find_common_index_dtypez/union_indexes.<locals>._find_common_index_dtype	  s:     JIwIII 	$V,,EEEr,   specialc                <    g | ]}t          |t                    |S r&   )rF   r   r(   xs     r*   r+   z!union_indexes.<locals>.<listcomp>   s'    CCCajM&B&BCCCCr,   c                     g | ]}|j         	|S rP   )tzrm   s     r*   r+   z!union_indexes.<locals>.<listcomp>!  s    777ad&61&6&6&6r,   z0Cannot join tz-naive with tz-aware DatetimeIndexTFc                F    g | ]}|                     t          d           S rT   )rU   objectrm   s     r*   r+   z!union_indexes.<locals>.<listcomp>4  s(    EEEqxxUx33EEEr,   Nr<   arrayc              3  B   K   | ]}                     |          V  d S rP   equals)r(   r@   r?   s     r*   rR   z union_indexes.<locals>.<genexpr>>  s/      @@55<<&&@@@@@@r,   )r#   r   )r=   AssertionErrorrF   listr   sorted_sanitize_and_checkrJ   unionr]   r   rC   rename)r9   r!   rc   kindre   rj   dtisdti_tzsr@   rD   rC   r?   s   ``         @r*   r   r      s     7||qBCCC
7||qfd## 	/ /vvf~~..'00MGT 
  
  
  
  
  
D    ( yCC7CCC77d777w<<3t99~--
 NOOOt99G$$DQZFFYY]] D FEWEEEGQZFQRR[ 	G 	GE\\%d.Edd\FFFF	((11
@@@@GABBK@@@@@ 	4#OGU33E"G,Q/5:LL&&E((11w...r,   c                
   t          d | D                       }t           |v r>t          |          dk    r'd | D             } |                    t                      n| dfS t          |          dk    s	t          |vr| 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                ,    h | ]}t          |          S r&   )type)r(   r?   s     r*   	<setcomp>z&_sanitize_and_check.<locals>.<setcomp>_  s    333%$u++333r,   r;   c                t    g | ]5}t          |t                    st          t          |                    n|6S r&   )rF   r   rx   rm   s     r*   r+   z'_sanitize_and_check.<locals>.<listcomp>c  sD       FGjE&:&:Ad1gg  r,   rx   rk   rs   )rx   r=   remover   )r9   kindss     r*   rz   rz   J  s    * 33733344Eu}}u::>> KR  G LLF?"
5zzA~~e++	!!r,   c                v    t          |           }t          |          t          f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  B   K   | ]}                     |          V  d S rP   ru   )r(   r?   firsts     r*   rR   z#all_indexes_same.<locals>.<genexpr>  s/      44uu||E""444444r,   )iternextr]   )r9   itrr   s     @r*   r   r   p  s>     w--CIIE4444444444r,   nintr   c                L    t          |           }t          j        |d           S )N)rC   )ranger   _simple_new)r   rngs     r*   r   r     s#    
((C!#D1111r,   )Fr   TF)
r   r   r    r   r!   r   r"   r   r#   r   )r.   r0   r#   r0   )FFF)
r9   r0   r   r   r!   r   r"   r   r#   r   )r?   r   r#   r   )T)r!   rL   r#   r   )r#   r   )r   r   r#   r   )2
__future__r   textwraptypingr   r   numpyrG   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   r8   r-   r   r   rz   r   r   r&   r,   r*   <module>r      s   " " " " " "        
            , + + + + + 4 4 4 4 4 4 , , , , , ,              : 9 9 9 9 9 7 7 7 7 7 7 6 6 6 6 6 6 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 0 0 0 9 9 9 9 9 9 $######HO	 		  2 U U U U UD     	- - - - -`   D}/ }/ }/ }/ }/@#  #  # L5 5 5 5$2 2 2 2 2 2r,   