
    `Vg(                       d dl mZ d dlZd dl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 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!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*  ejV                  d      Z,g dZ-	 d	 	 	 	 	 	 	 ddZ.ddZ/	 	 	 d	 	 	 	 	 	 	 	 	 d dZ0d!dZ1d"d#dZ2d Z3d$dZ4d%dZ5y)&    )annotationsN)cast)NaTlib)InvalidIndexError)find_common_type)is_dtype_equal)	safe_sort)Index
_new_Indexensure_indexensure_index_from_sequencesget_unanimous_names)CategoricalIndex)DatetimeIndex)IntervalIndex)
MultiIndex)Float64Index
Int64IndexNumericIndexUInt64Index)PeriodIndex)
RangeIndex)TimedeltaIndexzSorting 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   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          X/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/indexes/api.pyr   r   N   s6    4 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_objsr2   l   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"   )r2   lenr   intersectionr   r   r   r#   )indexesr!   r"   r#   indexothers         r*   r%   r%   z   s    4 !)G
7|qb		W	
	
QR[ 	.E&&u-E	. gE2U#&

Lr3   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ndarrayfrom_tuplesr=   r   r>   r?   	TypeError)r:   array_sorteds     r*   r   r      s     $$L ' lJ/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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	t        fd
 D              s D cg c]  }|j                  d       c}  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 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 unionr5   c           
         d }t        t        j                  | D cg c]
  } ||       c}      |      S c c}w )a3  
        Convert indexes to lists and concatenate them, removing duplicates.

        The final dtype is inferred.

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

        Returns
        -------
        Index
        c                F    t        | t              r| j                         } | S N)rA   r   tolist)is    r*   convz4union_indexes.<locals>._unique_indices.<locals>.conv   s    !U#HHJHr3   r6   )r?   )r   r   fast_unique_multiple_list)indsr?   rM   rL   r"   s       r*   _unique_indicesz&union_indexes.<locals>._unique_indices   s<     	
 ))D*Aq47*AM
 	
*As   ;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)rA   r   r?   r   )rO   idxdtypesr?   r9   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 DatetimeIndexTc              3  ^   K   | ]$  }t        |j                  j                         & y wrJ   )r	   r?   ).0xfirsts     r*   	<genexpr>z union_indexes.<locals>.<genexpr>#  s      M~aggu{{;Ms   *-UTCF)r#   r6   arrayc              3  @   K   | ]  }j                  |        y wrJ   equals)rW   r;   r:   s     r*   rZ   z union_indexes.<locals>.<genexpr><  s     @55<<&@   )returnr   )r7   AssertionErrorrA   listr   sorted_sanitize_and_checkr   tzrE   all
tz_convertastypeobjectunionr   r>   rename)r9   r"   resultkindrP   rT   rX   dtisdti_tzsr;   r?   r>   rY   r:   s   ``          @@r*   r   r      s#     7|qBCC
7|qfd#6&>*F'0MGT
4( y"CajM&BCC"7add&6177w<3t9~-
 NOOt9G$DMWMM 9@@11<<.@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..[ D7 A Fs$   G;G;!H 3H HH
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'}
    r5   rc   rU   r\   )rc   typer7   rA   r   remove)r9   r:   kindsrX   s       r*   re   re   H  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rJ   r^   )rW   r:   rY   s     r*   rZ   z#all_indexes_same.<locals>.<genexpr>}  s     4uu||E"4r`   )iternextrg   )r9   itrrY   s     @r*   r   r   n  s(     w-CIE4444r3   c                H    t        d|       }t        j                  |d       S )Nr   )r>   )ranger   _simple_new)nrngs     r*   r   r     s     
1+C!!#D11r3   )Fr   TF)r!   boolr"   r   r#   r   ra   r   )r&   list[Index]ra   r   )FFF)
r9   r   r!   r   r"   r   r#   r   ra   r   )r:   r   ra   r   )T)r"   zbool | Nonera   r   )ra   r   )r}   intra   r   )6
__future__r   textwraptypingr   numpyrB   pandas._libsr   r   pandas.errorsr   pandas.core.dtypes.castr   pandas.core.dtypes.commonr	   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.numericr   r   r   r   pandas.core.indexes.periodr   pandas.core.indexes.ranger   pandas.core.indexes.timedeltasr   dedent	_sort_msg__all__r   r2   r%   r   r   re   r   r    r3   r*   <module>r      s    "    , 4 4 ,  : 7 6 0  3 0 9HOO		8 LQUU15UDHU
U<  	--- - 	-
 -`Dy/x# L5$2r3   