
    Owg(                       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jN                  d      Z(g dZ)	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZ*ddZ+	 	 	 d	 	 	 	 	 	 	 	 	 ddZ,d dZ-d!d"dZ.d Z/d#dZ0d$dZ1y)%    )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_indexc                f    | D cg c]  }|j                  |       }}t        ||||      S c c}w )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
    )	intersectsortcopy)	_get_axis_get_combined_index)objsr   axisr   r    obj	obs_idxess          N/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/indexes/api.pyr   r   H   s6    < 155t$5I5yIDtTT 6s   .c                    t               }g }| D ];  }t        |      |vs|j                  t        |             |j                  |       = |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_objsr/   j   sM    
 EC
C c7#GGBsGJJsO J    c                ,   t        |       } t        |       dk(  rt        g       }nOt        |       dk(  r| d   }n;|r!| d   }| dd D ]  }|j                  |      } nt	        | d      }t        |      }|rt        |      }|r|j                         }|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   )r/   lenr   intersectionr   r   r   r    )indexesr   r   r    indexothers         r'   r"   r"   x   s    4 !)G
7|qb		W	
	
QR[ 	.E&&u-E	. gE2U#&

Lr0   c                \   | j                   r| S 	 t        |       }t        |t              r|S t	        t
        j                  |      }t        | t              r#t        j                  || j                        } | S t        || j                  | j                        } | S # t        $ r Y | S w xY w)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_tuplesr:   r;   r<   	TypeError)r7   array_sorteds     r'   r   r      s     $$L ' lE*BJJ5eZ(**<u{{KE L ,UZZu{{KEL   Ls   B 	B+*B+c                    t               dk(  rt        d      t               dk(  r: d   }t        |t              r#st	        |      }|S t	        t        |            }|S t               \   }dfd} fd}|dk(  r d   } D cg c]  }t        |t              s| }}|D cg c]  }|j                  | }}t        |      dt        |      fvrt        d      t        |      t               k(  rd	 d   }n:t        |      dkD  r,d
 D cg c]  }|j                  t        d
       c}  d   } dd D ]  }	|j                  |	rdnd
      } |S |dk(  rZ |       }
 d   t        fd dd D              s	 | |
      t          d   }|j                  k7  rj!                  |      S  |       }
 | |
      S c c}w c c}w c c}w )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 unionr2   c           
        t        d | D              r| D cg c]  }|j                  |d       } }| d   j                         }| d   j                  | dd       }||j	                  |      dk(     }t        |      r|j                  |j                               }r|j                         }|S d	 }t        t        j                  | D cg c]
  } ||       c}
      |      S c c}w c c}w )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                y wN)r>   r   ).0inds     r'   	<genexpr>z9union_indexes.<locals>._unique_indices.<locals>.<genexpr>   s     6#z#u%6s   Fr    r   r2      Nc                F    t        | t              r| j                         } | S rG   )r>   r   tolist)is    r'   convz4union_indexes.<locals>._unique_indices.<locals>.conv   s    !U#HHJHr0   r3   )r<   )
allastypeuniquer,   get_indexer_forr4   sort_valuesr   r   fast_unique_multiple_list)	indsr<   rI   resultr8   diffrQ   rP   r   s	           r'   _unique_indicesz&union_indexes.<locals>._unique_indices   s     666=ABcCJJu5J1BDB!W^^%FGNN48,E//6"<=D4yt{{}5++-M	
 ))D*Aq47*AM
 	
 C  +Bs   C,C1c                    D cg c]  }t        |t              s|j                  ! }}|rt        |      }|S d}|S c c}w )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
        N)r>   r   r<   r	   )rX   idxdtypesr<   r6   s       r'   _find_common_index_dtypez/union_indexes.<locals>._find_common_index_dtype	  sK     (/I*S%2H#))II$V,E  E Js   ??specialNz0Cannot join tz-naive with tz-aware DatetimeIndexTFrK   r3   arrayc              3  @   K   | ]  }j                  |        y wrG   equals)rH   r8   r7   s     r'   rJ   z union_indexes.<locals>.<genexpr>>  s     @55<<&@   )returnr   )r4   AssertionErrorr>   listr   sorted_sanitize_and_checkr   tzrB   rS   objectunionrR   r   r;   rename)r6   r   rY   kindr[   r_   xdtisdti_tzsr8   r<   r;   r7   s   ``          @r'   r   r      s     7|qBCC
7|qfd#v  vf~.'0MGT 
D( y"CajM&BCC"7add&6177w<3t9~-
 NOOt9G$DQZFY] D >EEqxxUx3EGQZFQR[ 	GE\\%dd\FF	G	(1
@GABK@@#GU3E"G,Q/5::LL&E(1w..O D7& Fs   G"G,G>GGc                \   t        | D ch c]  }t        |       c}      }t         |v r[t        |      dkD  rI| D cg c](  }t        |t              st	        t        |            n|* } }|j                  t                n| dfS t        |      dkD  st        |vr| dfS | dfS c c}w c c}w )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'}
    r2   rh   r`   ra   )rh   typer4   r>   r   remove)r6   r7   kindsrp   s       r'   rj   rj   J  s    * 73%$u+34Eu}u:>KRFGjE&:d1gAG  LLF?"
5zA~e+	!! 4s
   B$-B)c                X    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  @   K   | ]  }j                  |        y wrG   rc   )rH   r7   firsts     r'   rJ   z#all_indexes_same.<locals>.<genexpr>  s     4uu||E"4re   )iternextrR   )r6   itrry   s     @r'   r   r   p  s(     w-CIE4444r0   c                F    t        |       }t        j                  |d       S )N)r;   )ranger   _simple_new)nrngs     r'   r   r     s    
(C!!#D11r0   )Fr   TF)
r   boolr$   r   r   r   r    r   rf   r   )r#   list[Index]rf   r   )FFF)
r6   r   r   r   r   r   r    r   rf   r   )r7   r   rf   r   )T)r   zbool | Nonerf   r   )rf   r   )r   intrf   r   )2
__future__r   textwraptypingr   r   numpyr?   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   r/   r"   r   r   rj   r   r    r0   r'   <module>r      s   " 
  , 4 ,  : 7 6 0 2 0 9#HOO		2 UU U 	U
 U UD  	--- - 	-
 -`D}/@# L5$2r0   