HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/indexes/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/indexes/__pycache__/api.cpython-36.pyc
3

���h��@srddlZddlmZmZddlmZmZddlmZddl	j
jZddl
mZmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZmZmZmZddlm Z ddl!m"Z"dd
l#m$Z$ej%d�Z&dddddddddddddddddd d!d"d#gZ'd4e(e(e(ed&�d'd �Z)eeeed(�d)d*�Z*d5eee(e(e(ed+�d,d-�Z+d6ed.�d/d!�Z,d0d1�Z-d2d"�Z.d3d#�Z/dS)7�N)�List�Set)�NaT�lib)�InvalidIndexError)�Index�
_new_Index�ensure_index�ensure_index_from_sequences)�CategoricalIndex)�
DatetimeIndex)�
IntervalIndex)�
MultiIndex)�Float64Index�
Int64Index�NumericIndex�UInt64Index)�PeriodIndex)�
RangeIndex)�TimedeltaIndexz�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'.
rrrrrrr
rrrrrrrrr	r
�get_objs_combined_axis�
union_indexes�get_consensus_names�all_indexes_sameFT)�	intersect�sort�copy�returncs"�fdd�|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
    csg|]}|j���qS�)Z	_get_axis)�.0�obj)�axisr�9/tmp/pip-build-5_djhm0z/pandas/pandas/core/indexes/api.py�
<listcomp>[sz*get_objs_combined_axis.<locals>.<listcomp>)rrr)�_get_combined_index)�objsrr!rrZ	obs_idxesr)r!r"rAs)r%rcCs@t�}g}x0|D](}t|�|kr|jt|��|j|�qW|S)z^
    Return a list with distinct elements of "objs" (different ids).
    Preserves order.
    )�set�id�add�append)r%�ids�resr rrr"�_get_distinct_objs_s
r,)�indexesrrrrcCs�t|�}t|�dkrtg�}nXt|�dkr4|d}nB|rb|d}x4|dd�D]}|j|�}qNWnt||d�}t|�}|r�y|j�}Wntk
r�YnX|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�N)r)	r,�lenr�intersectionrr	Zsort_values�	TypeErrorr)r-rrr�index�otherrrr"r$ms&

r$)rcs t|�dkrtd��t|�dkrB|d}t|t�r>tt|��}|St|�\}}td��fdd�}|dkr�|d}t|d�r�|j|dd	��Sx|dd	�D]}|j	|�}q�W|Snj|d
k�r|d}x&|dd	�D]}|j
|�s�||�Sq�Wt|�d}||jk�r|j
|d�}|S||�Sd	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
    rz#Must have at least 1 Index to unionr.)rcs(dd��ttj�fdd�|D��d��S)z�
        Convert indexes to lists and concatenate them, removing duplicates.

        The final dtype is inferred.

        Parameters
        ----------
        inds : list of Index or list objects

        Returns
        -------
        Index
        cSst|t�r|j�}|S)N)�
isinstancer�tolist)�irrr"�conv�s
z4union_indexes.<locals>._unique_indices.<locals>.convcsg|]}�|��qSrr)rr6)r7rr"r#�sz:union_indexes.<locals>._unique_indices.<locals>.<listcomp>)r)rrZfast_unique_multiple_list)Zinds)r)r7r"�_unique_indices�sz&union_indexes.<locals>._unique_indices�special�
union_manyN�array)�name)r/�AssertionErrorr4�listr�sorted�_sanitize_and_check�hasattrr:�union�equalsrr<Z
_shallow_copy)r-r�result�kindr8r3r2r<r)rr"r�s4



cCsptdd�|D��}t|krHt|�dkr@dd�|D�}|jt�n|dfSt|�dks\t|krd|dfS|dfSd	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'}
    cSsh|]}t|��qSr)�type)rr2rrr"�	<setcomp>�sz&_sanitize_and_check.<locals>.<setcomp>r.cSs&g|]}t|t�stt|��n|�qSr)r4rr>)r�xrrr"r#sz'_sanitize_and_check.<locals>.<listcomp>r>r9r;N)r>r/�remover)r-Zkindsrrr"r@�sr@cCs:dd�|D�}t|�dkr*tt|�d�Sdg|djS)a%
    Give a consensus 'names' to indexes.

    If there's exactly one non-empty 'names', return this,
    otherwise, return empty.

    Parameters
    ----------
    indexes : list of Index objects

    Returns
    -------
    list
        A list representing the consensus 'names' found.
    cSs"h|]}tj|j�rt|j��qSr)�comZany_not_none�names�tuple)rr6rrr"rG!sz&get_consensus_names.<locals>.<setcomp>r.rN)r/r>Znlevels)r-Zconsensus_namesrrr"rscCs0t|�}t|�}x|D]}|j|�sdSqWdS)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.
    FT)�iter�nextrC)r-Zitr�firstr2rrr"r's


)FrTF)FFF)T)0�textwrapZtypingrrZpandas._libsrrZ
pandas.errorsrZpandas.core.common�core�commonrJZpandas.core.indexes.baserrr	r
Zpandas.core.indexes.categoryrZpandas.core.indexes.datetimesrZpandas.core.indexes.intervalr
Zpandas.core.indexes.multirZpandas.core.indexes.numericrrrrZpandas.core.indexes.periodrZpandas.core.indexes.rangerZpandas.core.indexes.timedeltasr�dedentZ	_sort_msg�__all__�boolrr,r$rr@rrrrrr"�<module>s^/H&