
    i/%                    R   d dl m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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& 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Z.d#dZ/y)$    )annotations)TYPE_CHECKINGcastN)NaTlib)InvalidIndexError)find_common_type)	safe_sort)Index
_new_Indexensure_indexensure_index_from_sequencesget_unanimous_namesmaybe_sequence_to_range)CategoricalIndex)DatetimeIndex)IntervalIndex)
MultiIndex)PeriodIndex)
RangeIndex)TimedeltaIndex)Axis)r   r   r   r   r   r   r   r   r   r   r   all_indexes_samedefault_indexr   r   get_objs_combined_axisr   r   safe_sort_indexunion_indexesc                d    | 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. NoDefault
        use for deprecation in GH#57335.

    Returns
    -------
    Index
    )	intersectsort)	_get_axis_get_combined_index)objsr   axisr    obj	obs_idxess         T/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/core/indexes/api.pyr   r   ?   s4    8 155t$5I5yIDII 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/   _   sM    
 EC
C c7#GGBsGJJsO J    c                T   t        |       } t        |       dk(  rt        d      }nct        |       dk(  r| d   }nO|r!| d   }| dd D ]  }|j                  |      } n,t	        | |t
        j                  u r|nd      }t        |      }|r|t
        j                  urt        |      }|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. NoDefault
        used for deprecation of GH#57335

    Returns
    -------
    Index
    r      NFr    )	r/   lenr   intersectionr   r   
no_defaultr   r   )indexesr   r    indexothers        r'   r"   r"   m   s    0 !)G
7|q$Q'	W	
	
QR[ 	.E&&u-E	. gDCNN4JDPUVU#CNN*&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)r8   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(  rL| d   }t        |t              r5|r|t        j
                  u rt        |      }|S t        t        |            }|S t        |       \  } }|dk(  r| d   }d}d}| D ]*  }t        |t              s|dz  }|j                  &|dz  }, |d|fvrt        d      |t        |       k(  r|t        j
                  u rd}| d   }n0|dkD  r+d}| D cg c]  }|j                  t        d	       } }| d   }| dd D ]  }|j                  ||rdnd
      } |S |dk(  rt        |       st!        | D cg c]  }|j"                   c}      }	| D 
cg c]  }
|
j                  |	d	       }}
|d   j%                         }|d   j'                  |dd       }||j)                  |      dk(     }t        |      r|j'                  |j%                               }|r|j+                         }n| d   }t-        |  d   }||j.                  k7  r|j1                  |      }|S |dk(  rn| D cg c]  }t        |t              s|j"                  ! }}|rt!        |      }	nd}	d | D        }t        t	        j2                  |t5        |      
      |	      S t7        d|d      c c}w 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. NoDefault
        used for deprecation of GH#57335.

    Returns
    -------
    Index
    r   z#Must have at least 1 Index to unionr2   specialNz0Cannot join tz-naive with tz-aware DatetimeIndexTF)copyr3   array   listc              3  `   K   | ]&  }t        |t              r|j                         n| ( y wN)r?   r   tolist).0idxs     r'   	<genexpr>z union_indexes.<locals>.<genexpr>  s$     XZU%;SZZ\DXs   ,.)r=   zkind=z& must be 'special', 'array' or 'list'.)r4   AssertionErrorr?   rK   r   r6   r   sorted_sanitize_and_checkr   tzrC   astypeobjectunionr   r	   r=   uniquer,   get_indexer_forsort_valuesr   r<   renamefast_unique_multiple_list_genbool
ValueError)r7   r    resultkindnum_dtisnum_dti_tzsrP   xr9   r=   indindsr8   diffr<   dtypes	all_listss                    r'   r   r      s   " 7|qBCC
7|qfd#43>>1v  vf~.'0MGTy 	%C#}-A66%1$K		%
 q(m+
 NOOs7|#s~~%QZF\ D >EEqxxUx3EGEQZFQR[ 	GE\\%dd\FF	G	($7%CCcii%CDE=DEcCJJu5J1EDEGNN$EGNN48,E..u5;<D4yT[[]3))+AJE"G,Q/5::LL&E	'.I*S%2H#))II$V,EEXPWX	--id4jI
 	

 ED7"HIJJK F &DE  Js   K$KKK-Kc                2   | D ch c]  }t        |       }}t        |v rPt        |      dkD  r>| D cg c](  }t        |t              st	        t        |            n|* } }|t        hz  }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   rK   rF   rH   )typerK   r4   r?   r   )r7   r8   kindsrd   s       r'   rT   rT     s    * '..UT%[.E.u}u:>KRFGjE&:d1gAG  dVOEF?"
5zA~e+	!! /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rM   )equals)rO   r8   firsts     r'   rQ   z#all_indexes_same.<locals>.<genexpr>Q  s     4uu||E"4s   )iternextall)r7   itrrp   s     @r'   r   r   B  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   T  s    
(C!!#D11r0   )Fr   T)r   r^   r$   r   r    bool | lib.NoDefaultreturnr   )r#   list[Index]r{   r|   )FF)r7   r|   r   r^   r    rz   r{   r   )r8   r   r{   r   )T)r    rz   r{   r   )r{   r^   )rx   intr{   r   )0
__future__r   typingr   r   numpyr@   pandas._libsr   r   pandas.errorsr   pandas.core.dtypes.castr	   pandas.core.algorithmsr
   pandas.core.indexes.baser   r   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   __all__r   r/   r"   r   r   rT   r   r    r0   r'   <module>r      s    "
  , 4 ,  : 7 6 0 2 0 9#4 !%	JJ J 	J
 J@  !&''' ' 	'TD`KF# L5$2r0   