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__/base.cpython-36.pyc
3

���h��@s�ddlmZddlmZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
mZddlZddlZddlmZmZmZddljjZddlmZmZddlm Z m!Z!dd	l"m#Z#dd
l$m%Z%ddl&m'Z'm(Z(ddl)m*Z*dd
l+m,Z-ddl.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4ddl5m6Z7ddl8m9Z9m:Z:ddl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSddlTmUZUddlVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ddl`maZambZbddlcmdZdddlemfZfddlgjhjiZddljmkZkmlZlddlmmnZnmoZoddlpmqZqmrZrddlsjhjtZuddlvmwZwddlxmyZyddlzjhj{Z{ddl|m}Z}ddl~mZddl�m�Z�dd l�m�Z�dd!l�m�Z�m�Z�m�Z�m�Z�m�Z�e�r�dd"l�m�Z�d#gZ�e�dM�Z�e�d#d&d#d&d#d'd(�Z�e��Z�e�Z�d)d*�Z�d+d,�Z�ej�e��Z�e�Z�d-d.�Z�Gd/d#�d#eqer�Z�e�j��e�j��e�j��dNd0d1�Z�dOe�d�d3d4�Z�d5d6�Z�ee�ee�d7�d8d9�Z�e�d:�d;d<�Z�d=d>�Z�e(d?�d@dA�Z�ej�ej�e�ej�dB�dCdD�Z�dEdF�Z�ej�e�ej�ej�dG�dHdI�Z�e�e(dJ�dKdL�Z�dS)P�)�copy)�datetimeN)�dedent)�
TYPE_CHECKING�Any�Callable�	FrozenSet�Hashable�List�Optional�Union)�algos�index�lib)�is_datetime_array�
no_default)�OutOfBoundsDatetime�	Timestamp)�IncompatibleFrequency)�
tz_compare)�DtypeObj�Label)�set_function_name)�function)�InvalidIndexError)�Appender�Substitution�cache_readonly�doc)�concat)�maybe_cast_to_integer_array�validate_numeric_casting)�ensure_int64�
ensure_object�ensure_platform_int�is_bool�
is_bool_dtype�is_categorical_dtype�is_datetime64_any_dtype�is_dtype_equal�is_extension_array_dtype�is_float�is_float_dtype�is_hashable�
is_integer�is_integer_dtype�is_interval_dtype�is_iterator�is_list_like�is_object_dtype�is_period_dtype�	is_scalar�is_signed_integer_dtype�is_timedelta64_dtype�is_unsigned_integer_dtype�pandas_dtype)�
concat_compat)	�ABCCategorical�ABCDataFrame�ABCDatetimeIndex�
ABCMultiIndex�ABCPandasArray�ABCPeriodIndex�
ABCRangeIndex�	ABCSeries�ABCTimedeltaIndex)�array_equivalent�isna)�ops)�CachedAccessor)�Categorical�ExtensionArray)�tz_to_dtype�validate_tz_from_dtype)�
IndexOpsMixin�PandasObject)�deprecate_ndim_indexing)�
FrozenList)�get_op_result_name)�make_invalid_op)�ensure_key_mapped)�
StringMethods)�
PrettyDict�default_pprint�format_object_attrs�format_object_summary�pprint_thing)�Series�Index�mixed�
mixed-integer�z
np.ndarray)�klass�inplaceZtarget_klassZraises_section�unique�
duplicatedcs&�fdd�}d�j�d�}t|||�S)Ncsdt|tjtttf�r6|jdkr6t|�t|�kr6td��t	|j
�rht|t�rht|�|j
|j
d�}�||�St	|j
�r�t|t�r�tjdd���|j
|�}WdQRXn�t	|j
�r�t|t�r�tjdd��tj�|j
|�}WdQRXnft|j
��rtjdd���|j
tj|��}WdQRXn.tjdd��tj|j
tj|���}WdQRXt|��rV|Stj||��S)NrzLengths must match to compare)�dtype�ignore)�all)�
isinstance�np�ndarrayrZrBrI�ndim�len�
ValueErrorr3rbr;�type�_valuesZerrstater>rFZcomp_method_OBJECT_ARRAYr0�asarrayZ
comparison_opr&Zinvalid_comparison)�self�other�left�result)�op��:/tmp/pip-build-5_djhm0z/pandas/pandas/core/indexes/base.py�
cmp_methodxs(
 
z'_make_comparison_op.<locals>.cmp_method�__)�__name__r)rr�clsru�namers)rrrt�_make_comparison_opwsrzcs&�fdd�}d�j�d�}t|||�S)NcsXt|tttf�rtSddlm}�||�|�}t|t�rPt|d�t|d�fSt|�S)Nr)rY�)	rerBr<rC�NotImplemented�pandasrY�tuplerZ)rnrorYrq)rrrsrt�index_arithmetic_method�s
z4_make_arithmetic_op.<locals>.index_arithmetic_methodrv)rwr)rrrxrryrs)rrrt�_make_arithmetic_op�sr�cCsXt|t�r"ddlm}||f|�St|t�rJd|krJd|krJ|jd�|d<|j|f|�S)zv
    This is called upon unpickling, rather than the default which doesn't
    have arguments and breaks __new__.
    r)�_new_PeriodIndex�labels�codes)�
issubclassr@Zpandas.core.indexes.periodr�r>�pop�__new__)rx�dr�rsrsrt�
_new_Index�s

r�cs�eZdZUdZejejBeddg�BZee	dZ
dd�Zdd�Zd	d
�Z
dd�Zd
ZeeejfdZdZedZedgZdgZdZdZdZej Z!dZ"dhZ#e$de%�Z	�d�dd�dd�Z&e'dd��Z(e)�d�ed�dd��Z*e+dd��Z,dd�Z-de.fed�dd �Z/ed�d!d"�Z0d#d$�Z1d%d&�Z2e+d'd(��Z3e4d�d)d*�Z5�d�ejd�d+d,�Z6�d�d-d.�Z7e+d/d0��Z8�d�d2d3�Z9�d�d4d5�Z:�d�d6d7�Z;d8e<d9<e=e<d9e>��d�d;d<��Z?ddej@fd=d>�ZAd?e<d@<e=e<d@e>��d�dAdB��ZB�d�dCdD�ZCdEdF�ZD�d�dGdH�ZEeFd�dIdJ�ZGeFd�dKdL�ZHe'dMdN��ZI�d�eFd�dOdP�ZJdQdR�ZKdSdT�ZL�d�eeMeNeFeOeFdV�dWdX�ZP�d�eOeFeFeOeFdY�dZd[�ZQ�d�d\d]�ZR�d�d_d`�ZS�d�eFd�dadb�ZTdcdd�ZU�d�dedf�ZV�d�edg�dhdi�ZWe'djdk��ZXeXjYdldk��ZX�d�edm�dndo�ZZdpdq�Z[�d�drds�Z\e'e\e[dt�Z]�d�edu�dvdw�Z^�d�dxdy�Z_e'e4d�dzd{��Z`d|d}�Zad~d�Zbe4d�d�d��Zc�d�d�d��Zdd�d��ZeeeZf�d�d�d��Zg�d�d�d��Zhe'ed�d�d���Zie'ed�d�d���Zje'ed�d�d���Zke'ed�d�d���Zle'ed�d�d���Zme+ed�d�d���Zne'ed�d�d���Zoed�d�d��Zped�d�d��Zqed�d�d��Zred�d�d��Zsed�d�d��Zted�d�d��Zued�d�d��Zved�d�d��Zwed�d�d��Zxe+eFd�d�d���Zye+ed�d�d���Zzd�d��Z{ej@Z|e+d�d���Z}e+d�d���Z~e+ed�d�d���Zd�d��Z�e�Z�d�d��Z�e�Z��d�d�d��Z��d�d�d��Z��d؇fd�d��	Z��dهfd�dÄ	Z��dڇfd�dń	Z��d�edƜd�dȄZ�d�dʄZ�d�d̄Z�d�d΄Z�d�dЄZ�d�d҄Z�d�dԄZ�d�dքZ�d�d؄Z�d�dڄZ�e�Z�d�d܄Z�d�dބZ�ed�d�d�Z�d�d�Z��d�d�d�Z�d�d�Z�d�d�Z��d�d�d�Z��d�d�d�Z��d�d�d�Z�d�d�Z�d�d�Z��d�d�d�Z�d�e<d�<e=e<d�e>��d�ejd�d�d���Z�d�d��Z��d�deFejd��d�d��Z��d�deFejd��d�d��Z�dej�d��d�d�Z�edejefejej�d��d�d�Z��d�d�Z�e��d��d	�d
�Z�e�eF�d��d�d
�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z�eF�d��d�d�Z��d�d�Z��d�d�d�Z��d�d�Z��d�d �d!�Z��d�d"�d#�Z��d�d$�d%�Z��d�d&�d'�Z��d�d(�d)�Z��d*�d+�Z�e'ejd��d,�d-��Z�e+e�ej��ed��d.�d/���Z�e'eeejfd��d0�d1��Z�ejd��d2�d3�Z�e�ej���d�ee4�d4��f�d5�d6�
�Z��d�d7�d8�Z�e)�d9�d:��Z�e)�d;�d<��Z��d=�d>�Zd?�d@�ZÐdA�dB�ZĐdC�dD�Z�e'ed��dE�dF��Z�ed��dG�dH�Z�ed��dI�dJ�Z�e�e�dK��dL�dM�ZʐdN�dO�ZːdP�dQ�Z̐dR�dS�Z�ed��dT�dU�ZΐdV�dW�ZϐdX�dY�ZАdZ�d[�Z�e�e�d\��d]�d^�Z�ed��d_�d`�ZӐda�db�ZԐdc�dd�ZՐd�eMeN�d��de�df�Z֐dg�dh�Zאd�di�dj�Z�ejd��dk�dl�Zِdm�dn��do�dp�Zڐdq�dr�Z�ed��ds�dt�Zܐdm�dn��du�dv�Zݐdw�dx�Zސdye<�dz<e=e<�dze>��d{�d|��Zߐd}�d~�Z�d�d��d��d��Z�e�e�d���d��d��Z�e�e�ejfd��d��d��Z�d�f�d��d��	Z�d�dd��d��d��Z�d�d��d��Z�d�eFee�d���d��d��Z�d�d��d��Z�d��d��Z�eFeF�d���d��d��Z�eF�d���d��d��Z�d�d��d��Z�eFe4�d���d��d��Z�d�d��d��Z�d��d��Z�e4�d���d��d��Z�d�eF�d���d��d��Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e)�d��d���Z�e'�d��d���Z��Z�S(�rZa�
    Immutable ndarray implementing an ordered, sliceable set. The basic object
    storing axis labels for all pandas objects.

    Parameters
    ----------
    data : array-like (1-dimensional)
    dtype : NumPy dtype (default: object)
        If dtype is None, we find the dtype that best fits the data.
        If an actual dtype is provided, we coerce to that dtype if it's safe.
        Otherwise, an error will be raised.
    copy : bool
        Make a copy of input ndarray.
    name : object
        Name to be stored in the index.
    tupleize_cols : bool (default: True)
        When True, attempt to create a MultiIndex if possible.

    See Also
    --------
    RangeIndex : Index implementing a monotonic integer range.
    CategoricalIndex : Index of :class:`Categorical` s.
    MultiIndex : A multi-level, or hierarchical Index.
    IntervalIndex : An Index of :class:`Interval` s.
    DatetimeIndex : Index of datetime64 data.
    TimedeltaIndex : Index of timedelta64 data.
    PeriodIndex : Index of Period data.
    Int64Index : A special case of :class:`Index` with purely integer labels.
    UInt64Index : A special case of :class:`Index` with purely unsigned integer labels.
    Float64Index : A special case of :class:`Index` with purely float labels.

    Notes
    -----
    An Index instance can **only** contain hashable objects

    Examples
    --------
    >>> pd.Index([1, 2, 3])
    Int64Index([1, 2, 3], dtype='int64')

    >>> pd.Index(list('abc'))
    Index(['a', 'b', 'c'], dtype='object')
    �contains�	set_valuer{cCstj||�S)N)�libjoinZleft_join_indexer_unique)rnrp�rightrsrsrt�_left_indexer_unique�szIndex._left_indexer_uniquecCstj||�S)N)r�Zleft_join_indexer)rnrpr�rsrsrt�
_left_indexerszIndex._left_indexercCstj||�S)N)r�Zinner_join_indexer)rnrpr�rsrsrt�_inner_indexerszIndex._inner_indexercCstj||�S)N)r�Zouter_join_indexer)rnrpr�rsrsrt�_outer_indexerszIndex._outer_indexerrNFryT�str)�returncKs2ddlm}t|||�}|dk	r(t|�}d|krL|jd�}t||�t|�}t|t�r^|j	�}t
|dd�}	t||�r�|||||d�St|t�r�|j|||d�St
|	�s�t
|�r�ddlm}
t||
|||f|�St|	�s�t|��rddlm}t|||||f|�St|	��st|��r4dd	lm}t|||||f|�St|	��sHt|��rhdd
lm}
t||
|||f|�St|	��s|t|��r�ddlm}t|||||f|�St|	��s�t|��r|dk�p�t|��s�|j�}|j||dd
�}ntj |t!d�}|j"t!�}t#|ft!||d�|��St|tj$t#t%f��r\ddl&m'}m(}m)}|dk	�rRt*|||�}|j+}t,|j+��rn|||||d�St-|j+��r�|||||d�St.|j+��r�|||||d�St/|j+j0t1��s�t2|��r�|j"d�}nt3j4|t!d�}|�r�|j5�}|dk�r t6|�\}}|dk	�r ||f|d|d�|��S|�r<t7dt8t9|������|j:dk�rPt;d��|j<||�S|dk�spt=|��r||j>|��n�t?|d��r�t#tj |�f|||d�|��S|�rt@|��rtA|��r�tB|�}|�rtCdd�|D���rddlDmE}|jF||�p|jGd�d�St3j4|t!d�}t#|f|||d�|��SdS)Nr)�
RangeIndex�tzrb)�startrrbry)rbry)�CategoricalIndex)�
IntervalIndex)�
DatetimeIndex)�TimedeltaIndex)�PeriodIndexF)rbr)rb)rbrry)�Float64Index�
Int64Index�UInt64Index)rrbry�objectzUnexpected keyword arguments r{z Index data must be 1-dimensional�	__array__css|]}t|t�VqdS)N)rer~)�.0�ersrsrt�	<genexpr>�sz Index.__new__.<locals>.<genexpr>)�
MultiIndex�names)r�)H�pandas.core.indexes.ranger��maybe_extract_namer9r�rKrJrer?Zto_numpy�getattr�rangeZ
from_ranger'�pandas.core.indexes.categoryr��_maybe_asobjectr0Zpandas.core.indexes.intervalr�r(r}r�r7r�r4r�r*r3Zconstruct_array_type�_from_sequencerfrmr��astyperZrgrBZpandas.core.indexes.numericr�r�r��_maybe_cast_with_dtyperbr6r8r,r�rk�boolr&�com�asarray_tuplesafer�_maybe_cast_data_without_dtype�	TypeError�repr�setrhrj�_simple_newr5�_scalar_data_error�hasattrr2r1�listrd�pandas.core.indexes.multir��from_tuples�get)rx�datarbrry�
tupleize_cols�kwargsr�r�Z
data_dtyper�r�r�r�r�Zea_clsr�r�r��subarrZnew_dataZ	new_dtyper�rsrsrtr�%s�









z
Index.__new__cCsdS)z�
        Integer representation of the values.

        Returns
        -------
        ndarray
            An ndarray with int64 dtype.
        Nrs)rnrsrsrt�asi8�s
z
Index.asi8)rycCsBt|tj�stt|���tj|�}||_||_||_	i|_
|j�S)z�
        We require that we have a dtype compat for the values. If we are passed
        a non-dtype compat, then coerce using the constructor.

        Must be careful not to recurse.
        )rerfrg�AssertionErrorrkr�r��_dataZ_index_data�_name�_cache�_reset_identity)rx�valuesryrqrsrsrtr��s
zIndex._simple_newcCst|�S)N)rk)rnrsrsrt�_constructor�szIndex._constructorcs�fdd��jD�S)z9
        Return an attributes dict for my class.
        csi|]}t�|d�|�qS)N)r�)r��k)rnrsrt�
<dictcomp>�sz.Index._get_attributes_dict.<locals>.<dictcomp>)�_attributes)rnrs)rnrt�_get_attributes_dict�szIndex._get_attributes_dictcCsN|tkr|jn|}|dkr$|jj�ni}|dkr6|j}|j||d�}||_|S)az
        Create a new Index with the same class as the caller, don't copy the
        data, use the same object attributes with passed in attributes taking
        precedence.

        *this is an internal non-public method*

        Parameters
        ----------
        values : the values to create the new Index, optional
        name : Label, defaults to self.name
        N)ry)rryr�rrlr�)rnr�ry�cacherqrsrsrt�
_shallow_copy�s
zIndex._shallow_copycCs|jt|dt�ko|jdk	S)a
        More flexible, faster check like ``is`` but that works through views.

        Note: this is *not* the same as ``Index.identical()``, which checks
        that metadata is also the same.

        Parameters
        ----------
        other : object
            Other object to compare against.

        Returns
        -------
        bool
            True if both have same underlying data, False otherwise.

        See Also
        --------
        Index.identical : Works like ``Index.is_`` but also checks metadata.
        �_idN)r�r��Ellipsis)rnrorsrsrt�is_sz	Index.is_cCst�|_|S)zJ
        Initializes or resets ``_id`` attribute with new object.
        )�	_Identityr�)rnrsrsrtr� szIndex._reset_identitycCs|jj�dS)N)�_engineZ
clear_mapping)rnrsrsrt�_cleanup'szIndex._cleanupcs |j��|j�fdd�t|��S)Ncs�S)Nrsrs)�
target_valuesrsrt�<lambda>1szIndex._engine.<locals>.<lambda>)�_get_engine_target�_engine_typeri)rnrs)r�rtr�*sz
Index._enginecCs
t|j�S)z1
        Return the length of the Index.
        )rir�)rnrsrsrt�__len__7sz
Index.__len__cCstj|j|d�S)z8
        The array interface, return my values.
        )rb)rfrmr�)rnrbrsrsrtr�=szIndex.__array__cCsBtj|�}t|�s*tj|�s*tj|�dkr.|S|j�}t|f|�S)z,
        Gets called after a ufunc.
        r{)rZitem_from_zerodimr&r5rfrhr�rZ)rnrq�context�attrsrsrsrt�__array_wrap__Cs

 zIndex.__array_wrap__cCs|jjS)zA
        Return the dtype object of the underlying data.
        )r�rb)rnrsrsrtrbNszIndex.dtype�CcCs|j�}|j|d�S)z�
        Return an ndarray of the flattened values of the underlying data.

        Returns
        -------
        numpy.ndarray
            Flattened array.

        See Also
        --------
        numpy.ndarray.ravel
        )�order)r��ravel)rnr�r�rsrsrtr�Us
zIndex.ravelcCs@|dk	r"t|d�r"|jj|�}n|j�}t|t�r<|j|_|S)N�_typ)r�r��viewr�rerZr�)rnrxrqrsrsrtr�es
z
Index.viewcCs�|dk	rt|�}t|j|�r,|r(|j�S|St|�rTddlm}||j|j||d�St	|�rtt
tj|�|j||d�Sy|jj
||d�}WnBttfk
r�}z"tdt|�j�d|���|�WYdd}~XnXt
||j|d�S)	a\
        Create an Index with values cast to dtypes.

        The class of a new Index is determined by dtype. When conversion is
        impossible, a ValueError exception is raised.

        Parameters
        ----------
        dtype : numpy dtype or pandas type
            Note that any signed integer `dtype` is treated as ``'int64'``,
            and any unsigned integer `dtype` is treated as ``'uint64'``,
            regardless of the size.
        copy : bool, default True
            By default, astype always returns a newly allocated object.
            If copy is set to False and internal requirements on dtype are
            satisfied, the original data is used to create a new Index
            or the original Index is returned.

        Returns
        -------
        Index
            Index with values cast to specified dtype.
        Nr)r�)ryrbr)rzCannot cast z
 to dtype )ryrb)r9r)rbrr'r�r�rlryr*rZrfrmr�r�rjrkrw)rnrbrr�Zcasted�errrsrsrtr�qs"zIndex.astypea�
        Return a new %(klass)s of the values selected by the indices.

        For internal compatibility with numpy arrays.

        Parameters
        ----------
        indices : list
            Indices to be taken.
        axis : int, optional
            The axis over which to select values, always 0.
        allow_fill : bool, default True
        fill_value : bool, default None
            If allow_fill=True and fill_value is not None, indices specified by
            -1 is regarded as NA. If Index doesn't hold NA, raise ValueError.

        Returns
        -------
        numpy.ndarray
            Elements of given indices.

        See Also
        --------
        numpy.ndarray.take
        �takercKsv|rtjt�|�t|�}|jr:|j|j||||jd�}n2|r`|dk	r`t|�j	}t
d|�d���|jj|�}|j|�S)N)�
allow_fill�
fill_value�na_valuezUnable to fill values because z cannot contain NA)
�nvZ
validate_taker~r$�_can_hold_na�_assert_take_fillablerl�	_na_valuerkrwrjr�r�)rn�indices�axisr�r�r��takenZcls_namersrsrtr��s 
z
Index.takecCsJt|�}|r<|dk	r<|dkj�r(td��tj||||d�}n
|j|�}|S)z?
        Internal method to handle NA filling of take.
        Nr{zJWhen allow_fill=True and fill_value is not None, all indices must be >= -1)r�r����)r$�anyrjr
r�)rnr�r�r�r�r�r�rsrsrtr��s
zIndex._assert_take_fillablea�
        Repeat elements of a %(klass)s.

        Returns a new %(klass)s where each element of the current %(klass)s
        is repeated consecutively a given number of times.

        Parameters
        ----------
        repeats : int or array of ints
            The number of repetitions for each element. This should be a
            non-negative integer. Repeating 0 times will return an empty
            %(klass)s.
        axis : None
            Must be ``None``. Has no effect but is accepted for compatibility
            with numpy.

        Returns
        -------
        repeated_index : %(klass)s
            Newly created %(klass)s with repeated elements.

        See Also
        --------
        Series.repeat : Equivalent function for Series.
        numpy.repeat : Similar method for :class:`numpy.ndarray`.

        Examples
        --------
        >>> idx = pd.Index(['a', 'b', 'c'])
        >>> idx
        Index(['a', 'b', 'c'], dtype='object')
        >>> idx.repeat(2)
        Index(['a', 'a', 'b', 'b', 'c', 'c'], dtype='object')
        >>> idx.repeat([1, 2, 3])
        Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object')
        �repeatcCs.t|�}tjt�t|d��|j|jj|��S)N)r�)r$r�Zvalidate_repeatr~�dictr�rlr�)rnZrepeatsr�rsrsrtr�szIndex.repeatcCsJ|r|j|jj��}n|j�}|j|||d�}|j|�}|rF|j|�}|S)a�
        Make a copy of this object.

        Name and dtype sets those attributes on the new object.

        Parameters
        ----------
        name : Label, optional
            Set name for new object.
        deep : bool, default False
        dtype : numpy dtype or pandas type, optional
            Set dtype for new object.
        names : list-like, optional
            Kept for compatibility with MultiIndex. Should not be used.

        Returns
        -------
        Index
            Index refer to new object which is a copy of this object.

        Notes
        -----
        In most cases, there should be no functional difference from using
        ``deep``, but if ``deep`` is passed it will attempt to deepcopy.
        )ryr��deep)r�r�r�_validate_names�	set_namesr�)rnryr�rbr��	new_indexrsrsrtrs

z
Index.copycKs|jf|�S)N)r)rnr�rsrsrt�__copy__?szIndex.__copy__cCs|jdd�S)zq
        Parameters
        ----------
        memo, default None
            Standard signature. Unused
        T)r�)r)rn�memorsrsrt�__deepcopy__BszIndex.__deepcopy__cCsdt|�j}|j�}|j�}|j�}dd�|D�}d|��j|�}|dkrLd}|�d|�|�d�}|S)zA
        Return a string representation for this object.
        cSsg|]\}}|�d|���qS)�=rs)r�r��vrsrsrt�
<listcomp>Vsz"Index.__repr__.<locals>.<listcomp>�,Nr]�(�))rkrw�_format_data�
_format_attrs�
_format_space�join)rn�
klass_namer�r��spaceZ	attrs_strZprepr�resrsrsrt�__repr__Ns
zIndex.__repr__cCsdS)N� rs)rnrsrsrtraszIndex._format_spacecCstS)z0
        Return the formatter function.
        )rU)rnrsrsrt�_formatter_funckszIndex._formatter_funccCs>d}|jdkrd}n|jdkr,t|j�r,d}t||j||d�S)z@
        Return the formatted data as a unicode string.
        T�stringF�categorical)�
is_justifyry)�
inferred_typer3�
categoriesrWr)rnryr
rsrsrtr�rs


zIndex._format_datacCst|�S)zH
        Return a list of tuples of the (attr,formatted_value).
        )rV)rnrsrsrtr��szIndex._format_attrscCs|jS)N)r�)rnrsrsrt�	_mpl_repr�szIndex._mpl_repr�NaN)ry�	formatter�na_repr�cCsRg}|r*|j|jdk	r$t|jdd�nd�|dk	rD|t|j|��S|j||d�S)	z>
        Render a string representation of the Index.
        N�	�
�
)�escape_charsr])r)rrr)�appendryrXr��map�_format_with_header)rnryrr�headerrsrsrt�format�s	zIndex.format)rrr�cCs�ddlm}|j}t|j�r*tj|dd�}t|j�rndd�|D�}t|�}|j�r�t	j
|�}|||<|j�}nt||ddd��}||S)	Nr)�format_arrayr{)�safecSsg|]}t|dd��qS)rrr)r)rrr)rX)r��xrsrsrtr��sz-Index._format_with_header.<locals>.<listcomp>rp)Zjustify)
Zpandas.io.formats.formatrrlr3rbrZmaybe_convert_objectsrEr�rf�array�tolist�
trim_front)rnrrrr�rq�maskrsrsrtr�s



zIndex._format_with_headercKs |}|dk	r||}|jf|�S)a	
        Format specified values of `self` and return them.

        Parameters
        ----------
        slicer : int, array-like
            An indexer into `self` that specifies which values
            are used in the formatting process.
        kwargs : dict
            Options for specifying how the values should be formatted.
            These options include the following:

            1) na_rep : str
                The value that serves as a placeholder for NULL values
            2) quoting : bool or None
                Whether or not there are quoted values in `self`
            3) date_format : str
                The format used to represent date-like values.

        Returns
        -------
        numpy.ndarray
            Formatted values.
        N)�_format_native_types)rnZslicerr�r�rsrsrt�to_native_types�szIndex.to_native_typesr]cKsFt|�}|j�r*|r*tj|�jt�}ntj|tdd�}|||<|S)z>
        Actually format specific types of the index.
        T)rbr)rE�	is_objectrfrmr�r�rr�)rnr�quotingr�r r�rsrsrtr!�szIndex._format_native_typescCs�t|�dkrj|d}t|d�r2t|t�r2|j�}|d
}t|d�rXt|t�rX|j�}d|�d|��}nd}|dkr�t|�j}|�dt|��d	|��S)a
        Return a summarized representation.

        Parameters
        ----------
        name : str
            name to use in the summary representation

        Returns
        -------
        String with a summarized representation of the index
        rrr{z, z to r]Nz: z entriesr�)rir�rer�rrkrw)rnry�head�tailZ
index_summaryrsrsrt�_summary�s

zIndex._summarycCs|S)aM
        Identity method.

        .. versionadded:: 0.24.0

        This is implemented for compatibility with subclass implementations
        when chaining.

        Returns
        -------
        pd.Index
            Caller.

        See Also
        --------
        MultiIndex.to_flat_index : Subclass implementation.
        rs)rnrsrsrt�
to_flat_indexszIndex.to_flat_indexcCs>ddlm}|dkr|j�}|dkr*|j}||jj�||d�S)a�
        Create a Series with both index and values equal to the index keys.

        Useful with map for returning an indexer based on an index.

        Parameters
        ----------
        index : Index, optional
            Index of resulting Series. If None, defaults to original index.
        name : str, optional
            Name of resulting Series. If None, defaults to name of original
            index.

        Returns
        -------
        Series
            The dtype will be based on the type of the Index values.

        See Also
        --------
        Index.to_frame : Convert an Index to a DataFrame.
        Series.to_frame : Convert Series to DataFrame.

        Examples
        --------
        >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')

        By default, the original Index and original name is reused.

        >>> idx.to_series()
        animal
        Ant      Ant
        Bear    Bear
        Cow      Cow
        Name: animal, dtype: object

        To enforce a new Index, specify new labels to ``index``:

        >>> idx.to_series(index=[0, 1, 2])
        0     Ant
        1    Bear
        2     Cow
        Name: animal, dtype: object

        To override the name of the resulting column, specify `name`:

        >>> idx.to_series(name='zoo')
        animal
        Ant      Ant
        Bear    Bear
        Cow      Cow
        Name: zoo, dtype: object
        r)rYN)rry)r}rYr�ryr�r)rnrryrYrsrsrt�	to_seriess6zIndex.to_series)rcCs>ddlm}|dkr|jpd}|||jj�i�}|r:||_|S)a�
        Create a DataFrame with a column containing the Index.

        .. versionadded:: 0.24.0

        Parameters
        ----------
        index : bool, default True
            Set the index of the returned DataFrame as the original Index.

        name : object, default None
            The passed name should substitute for the index name (if it has
            one).

        Returns
        -------
        DataFrame
            DataFrame containing the original Index data.

        See Also
        --------
        Index.to_series : Convert an Index to a Series.
        Series.to_frame : Convert Series to DataFrame.

        Examples
        --------
        >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
        >>> idx.to_frame()
               animal
        animal
        Ant       Ant
        Bear     Bear
        Cow       Cow

        By default, the original Index is reused. To enforce a new Index:

        >>> idx.to_frame(index=False)
            animal
        0   Ant
        1  Bear
        2   Cow

        To override the name of the resulting column, specify `name`:

        >>> idx.to_frame(index=False, name='zoo')
            zoo
        0   Ant
        1  Bear
        2   Cow
        r)�	DataFrameN)r}r*ryrlrr)rnrryr*rqrsrsrt�to_frameWs3
zIndex.to_framecCs|jS)z2
        Return Index or MultiIndex name.
        )r�)rnrsrsrtry�sz
Index.namecCs(|jrtd��t|dt|��||_dS)NzOCannot set name on a level of a MultiIndex. Use 'MultiIndex.set_names' instead.)�_no_setting_name�RuntimeErrorr�rkr�)rn�valuersrsrtry�s
)r�cCs|ddlm}|dk	r&|dk	r&td��nR|dkrJ|dkrJ|rD||j�S|jS|dk	rft|�sbtd��|St|�st|gS|SdS)z�
        Handles the quirks of having a singular 'name' parameter for general
        Index and plural 'names' parameter for MultiIndex.
        r)�deepcopyNz*Can only provide one of `names` and `name`zMust pass list-like as `names`.)rr/r�r�r2)rnryr�r�r/rsrsrtr��s
zIndex._validate_namescCst|jf�S)N)rOry)rnrsrsrt�
_get_names�szIndex._get_namescCsft|�std��t|�dkr.tdt|�����x(|D] }t|�s4tt|�j�d���q4W|d|_dS)a�
        Set new names on index. Each name has to be a hashable type.

        Parameters
        ----------
        values : str or sequence
            name(s) to set
        level : int, level name, or sequence of int/level names (default None)
            If the index is a MultiIndex (hierarchical), level(s) to set (None
            for all levels).  Otherwise level must be None

        Raises
        ------
        TypeError if each name is not hashable.
        zNames must be a list-liker{z#Length of new names must be 1, got z.name must be a hashable typerN)r2rjrir-r�rkrwr�)rnr��levelryrsrsrt�
_set_names�s
zIndex._set_names)�fset�fget)r_cCs�|dk	rt|t�rtd��|dk	r>t|�r>t|�r>td��t|�rb|dkrb|jdkrbtd��t|�sp|g}|dk	r�t|�r�|g}|r�|}n|j�}|j||d�|s�|SdS)a
        Set Index or MultiIndex name.

        Able to set new names partially and by level.

        Parameters
        ----------
        names : label or list of label
            Name(s) to set.
        level : int, label or list of int or label, optional
            If the index is a MultiIndex, level(s) to set (None for all
            levels). Otherwise level must be None.
        inplace : bool, default False
            Modifies the object directly, instead of creating a new Index or
            MultiIndex.

        Returns
        -------
        Index
            The same type as the caller or None if inplace is True.

        See Also
        --------
        Index.rename : Able to set new names without level.

        Examples
        --------
        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx
        Int64Index([1, 2, 3, 4], dtype='int64')
        >>> idx.set_names('quarter')
        Int64Index([1, 2, 3, 4], dtype='int64', name='quarter')

        >>> idx = pd.MultiIndex.from_product([['python', 'cobra'],
        ...                                   [2018, 2019]])
        >>> idx
        MultiIndex([('python', 2018),
                    ('python', 2019),
                    ( 'cobra', 2018),
                    ( 'cobra', 2019)],
                   )
        >>> idx.set_names(['kind', 'year'], inplace=True)
        >>> idx
        MultiIndex([('python', 2018),
                    ('python', 2019),
                    ( 'cobra', 2018),
                    ( 'cobra', 2019)],
                   names=['kind', 'year'])
        >>> idx.set_names('species', level=0)
        MultiIndex([('python', 2018),
                    ('python', 2019),
                    ( 'cobra', 2018),
                    ( 'cobra', 2019)],
                   names=['species', 'year'])
        Nz%Level must be None for non-MultiIndexz7Names must be a string when a single level is provided.r{zMust pass list-like as `names`.)r1)rer>rjr2r��nlevelsr�r2)rnr�r1r_�idxrsrsrtr��s 8zIndex.set_namescCs|j|g|d�S)ah
        Alter Index or MultiIndex name.

        Able to set new names without level. Defaults to returning new index.
        Length of names must match number of levels in MultiIndex.

        Parameters
        ----------
        name : label or list of labels
            Name(s) to set.
        inplace : bool, default False
            Modifies the object directly, instead of creating a new Index or
            MultiIndex.

        Returns
        -------
        Index
            The same type as the caller or None if inplace is True.

        See Also
        --------
        Index.set_names : Able to set new names partially and by level.

        Examples
        --------
        >>> idx = pd.Index(['A', 'C', 'A', 'B'], name='score')
        >>> idx.rename('grade')
        Index(['A', 'C', 'A', 'B'], dtype='object', name='grade')

        >>> idx = pd.MultiIndex.from_product([['python', 'cobra'],
        ...                                   [2018, 2019]],
        ...                                   names=['kind', 'year'])
        >>> idx
        MultiIndex([('python', 2018),
                    ('python', 2019),
                    ( 'cobra', 2018),
                    ( 'cobra', 2019)],
                   names=['kind', 'year'])
        >>> idx.rename(['species', 'year'])
        MultiIndex([('python', 2018),
                    ('python', 2019),
                    ( 'cobra', 2018),
                    ( 'cobra', 2019)],
                   names=['species', 'year'])
        >>> idx.rename('species')
        Traceback (most recent call last):
        TypeError: Must pass list-like as `names`.
        )r_)r�)rnryr_rsrsrt�rename,s1zIndex.renamecCsdS)z#
        Number of levels.
        r{rs)rnrsrsrtr5bsz
Index.nlevelscCs|S)z)
        Compat with MultiIndex.
        rs)rnrsrsrt�_sort_levels_monotoniciszIndex._sort_levels_monotoniccCsnt|t�rH|dkr,|d
kr,td|�d���qj|dkrjtd|d����n"||jkrjtd|�d|j�d���d	S)z�
        Validate index level.

        For single-level Index getting level number is a no-op, but some
        verification must be done like in MultiIndex.

        rr{z)Too many levels: Index has only 1 level, z is not a valid level numberz-Too many levels: Index has only 1 level, not zRequested level (z) does not match index name (r�Nr�)re�int�
IndexErrorry�KeyError)rnr1rsrsrt�_validate_index_levelos

zIndex._validate_index_levelcCs|j|�dS)Nr)r<)rnr1rsrsrt�_get_level_number�s
zIndex._get_level_numbercCs|jd|d�S)aa
        For internal compatibility with with the Index API.

        Sort the Index. This is for compat with MultiIndex

        Parameters
        ----------
        ascending : bool, default True
            False to sort in descending order

        level, sort_remaining are compat parameters

        Returns
        -------
        Index
        T)�return_indexer�	ascending)�sort_values)rnr1r?Zsort_remainingrsrsrt�	sortlevel�szIndex.sortlevelcCs|j|�|S)a�
        Return an Index of values for requested level.

        This is primarily useful to get an individual level of values from a
        MultiIndex, but is provided on Index as well for compatibility.

        Parameters
        ----------
        level : int or str
            It is either the integer position or the name of the level.

        Returns
        -------
        Index
            Calling object, as there is only one level in the Index.

        See Also
        --------
        MultiIndex.get_level_values : Get values for a level of a MultiIndex.

        Notes
        -----
        For Index, level should be 0, since there are no multiple levels.

        Examples
        --------
        >>> idx = pd.Index(list('abc'))
        >>> idx
        Index(['a', 'b', 'c'], dtype='object')

        Get level values by supplying `level` as integer:

        >>> idx.get_level_values(0)
        Index(['a', 'b', 'c'], dtype='object')
        )r<)rnr1rsrsrt�_get_level_values�s$
zIndex._get_level_valuesc
s*t|ttf�s|g}t�fdd�|D��ddd�}t|�dkrD�St|��jkrntdt|��d�j�d���t�j�}t�j�}t�j	�}x*|D]"}|j
|�|j
|�|j
|�q�Wt|�dk�r
|dd
k}|dj|d�}|j��r�|j
|tj�}|d|_|Sdd	lm}	|	|||d
d�SdS)a
        Return index with requested level(s) removed.

        If resulting index has only 1 level left, the result will be
        of Index type, not MultiIndex.

        .. versionadded:: 0.23.1 (support for non-MultiIndex)

        Parameters
        ----------
        level : int, str, or list-like, default 0
            If a string is given, must be the name of a level
            If list-like, elements must be names or indexes of levels.

        Returns
        -------
        Index or MultiIndex
        c3s|]}�j|�VqdS)N)r=)r�Zlev)rnrsrtr��sz"Index.droplevel.<locals>.<genexpr>Nr{rzCannot remove z levels from an index with z) levels: at least one level must be left.)r�F)�levelsr�r��verify_integrityr�r�)rer~r��sortedrir5rjrCr�r�r�r�r��putmaskrf�nanr�r�r�)
rnr1Zlevnums�
new_levels�	new_codesZ	new_names�ir rqr�rs)rnrt�	droplevel�s8 







zIndex.droplevelcCs6|dks|dkst�|dkr"|}n
|j|�}|ddfS)a
        Get index grouper corresponding to an index level

        Parameters
        ----------
        mapper: Group mapping function or None
            Function mapping index values to groups
        level : int or None
            Index level

        Returns
        -------
        grouper : Index
            Index of values to group on.
        labels : ndarray of int or None
            Array of locations in level_index.
        uniques : Index or None
            Index of unique values for level.
        Nr)r�r)rn�mapperr1Zgrouperrsrsrt�_get_grouper_for_levels

zIndex._get_grouper_for_levelcCs|jS)z4
        Alias for is_monotonic_increasing.
        )�is_monotonic_increasing)rnrsrsrt�is_monotonic#szIndex.is_monotoniccCs|jjS)aR
        Return if the index is monotonic increasing (only equal or
        increasing) values.

        Examples
        --------
        >>> Index([1, 2, 3]).is_monotonic_increasing
        True
        >>> Index([1, 2, 2]).is_monotonic_increasing
        True
        >>> Index([1, 3, 2]).is_monotonic_increasing
        False
        )r�rN)rnrsrsrtrN*szIndex.is_monotonic_increasingcCs|jjS)aR
        Return if the index is monotonic decreasing (only equal or
        decreasing) values.

        Examples
        --------
        >>> Index([3, 2, 1]).is_monotonic_decreasing
        True
        >>> Index([3, 2, 2]).is_monotonic_decreasing
        True
        >>> Index([3, 1, 2]).is_monotonic_decreasing
        False
        )r��is_monotonic_decreasing)rnrsrsrtrP;szIndex.is_monotonic_decreasingcCs|jo
|jS)aq
        Return if the index is strictly monotonic increasing
        (only increasing) values.

        Examples
        --------
        >>> Index([1, 2, 3])._is_strictly_monotonic_increasing
        True
        >>> Index([1, 2, 2])._is_strictly_monotonic_increasing
        False
        >>> Index([1, 3, 2])._is_strictly_monotonic_increasing
        False
        )�	is_uniquerN)rnrsrsrt�!_is_strictly_monotonic_increasingLsz'Index._is_strictly_monotonic_increasingcCs|jo
|jS)aq
        Return if the index is strictly monotonic decreasing
        (only decreasing) values.

        Examples
        --------
        >>> Index([3, 2, 1])._is_strictly_monotonic_decreasing
        True
        >>> Index([3, 2, 2])._is_strictly_monotonic_decreasing
        False
        >>> Index([3, 1, 2])._is_strictly_monotonic_decreasing
        False
        )rQrP)rnrsrsrt�!_is_strictly_monotonic_decreasing]sz'Index._is_strictly_monotonic_decreasingcCs|jjS)z8
        Return if the index has unique values.
        )r�rQ)rnrsrsrtrQnszIndex.is_uniquecCs|jS)a�
        Check if the Index has duplicate values.

        Returns
        -------
        bool
            Whether or not the Index has duplicate values.

        Examples
        --------
        >>> idx = pd.Index([1, 5, 7, 7])
        >>> idx.has_duplicates
        True

        >>> idx = pd.Index([1, 5, 7])
        >>> idx.has_duplicates
        False

        >>> idx = pd.Index(["Watermelon", "Orange", "Apple",
        ...                 "Watermelon"]).astype("category")
        >>> idx.has_duplicates
        True

        >>> idx = pd.Index(["Orange", "Apple",
        ...                 "Watermelon"]).astype("category")
        >>> idx.has_duplicates
        False
        )rQ)rnrsrsrt�has_duplicatesuszIndex.has_duplicatescCs
|jdkS)a�
        Check if the Index only consists of booleans.

        Returns
        -------
        bool
            Whether or not the Index only consists of booleans.

        See Also
        --------
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index([True, False, True])
        >>> idx.is_boolean()
        True

        >>> idx = pd.Index(["True", "False", "True"])
        >>> idx.is_boolean()
        False

        >>> idx = pd.Index([True, False, "True"])
        >>> idx.is_boolean()
        False
        �boolean)rU)r)rnrsrsrt�
is_boolean�s!zIndex.is_booleancCs
|jdkS)a�
        Check if the Index only consists of integers.

        Returns
        -------
        bool
            Whether or not the Index only consists of integers.

        See Also
        --------
        is_boolean : Check if the Index only consists of booleans.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx.is_integer()
        True

        >>> idx = pd.Index([1.0, 2.0, 3.0, 4.0])
        >>> idx.is_integer()
        False

        >>> idx = pd.Index(["Apple", "Mango", "Watermelon"])
        >>> idx.is_integer()
        False
        �integer)rW)r)rnrsrsrtr.�s!zIndex.is_integercCs
|jdkS)a�
        Check if the Index is a floating type.

        The Index may consist of only floats, NaNs, or a mix of floats,
        integers, or NaNs.

        Returns
        -------
        bool
            Whether or not the Index only consists of only consists of floats, NaNs, or
            a mix of floats, integers, or NaNs.

        See Also
        --------
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index([1.0, 2.0, 3.0, 4.0])
        >>> idx.is_floating()
        True

        >>> idx = pd.Index([1.0, 2.0, np.nan, 4.0])
        >>> idx.is_floating()
        True

        >>> idx = pd.Index([1, 2, 3, 4, np.nan])
        >>> idx.is_floating()
        True

        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx.is_floating()
        False
        �floating�mixed-integer-float�
integer-na)rXrYrZ)r)rnrsrsrt�is_floating�s)zIndex.is_floatingcCs
|jdkS)a�
        Check if the Index only consists of numeric data.

        Returns
        -------
        bool
            Whether or not the Index only consists of numeric data.

        See Also
        --------
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index([1.0, 2.0, 3.0, 4.0])
        >>> idx.is_numeric()
        True

        >>> idx = pd.Index([1, 2, 3, 4.0])
        >>> idx.is_numeric()
        True

        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx.is_numeric()
        True

        >>> idx = pd.Index([1, 2, 3, 4.0, np.nan])
        >>> idx.is_numeric()
        True

        >>> idx = pd.Index([1, 2, 3, 4.0, np.nan, "Apple"])
        >>> idx.is_numeric()
        False
        rWrX)rWrX)r)rnrsrsrt�
is_numerics)zIndex.is_numericcCs
t|j�S)a�
        Check if the Index is of the object dtype.

        Returns
        -------
        bool
            Whether or not the Index is of the object dtype.

        See Also
        --------
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index(["Apple", "Mango", "Watermelon"])
        >>> idx.is_object()
        True

        >>> idx = pd.Index(["Apple", "Mango", 2.0])
        >>> idx.is_object()
        True

        >>> idx = pd.Index(["Watermelon", "Orange", "Apple",
        ...                 "Watermelon"]).astype("category")
        >>> idx.is_object()
        False

        >>> idx = pd.Index([1.0, 2.0, 3.0, 4.0])
        >>> idx.is_object()
        False
        )r3rb)rnrsrsrtr#1s&zIndex.is_objectcCs
|jdkS)a�
        Check if the Index holds categorical data.

        Returns
        -------
        bool
            True if the Index is categorical.

        See Also
        --------
        CategoricalIndex : Index for categorical data.
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_interval : Check if the Index holds Interval objects.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index(["Watermelon", "Orange", "Apple",
        ...                 "Watermelon"]).astype("category")
        >>> idx.is_categorical()
        True

        >>> idx = pd.Index([1, 3, 5, 7])
        >>> idx.is_categorical()
        False

        >>> s = pd.Series(["Peter", "Victor", "Elisabeth", "Mar"])
        >>> s
        0        Peter
        1       Victor
        2    Elisabeth
        3          Mar
        dtype: object
        >>> s.index.is_categorical()
        False
        r	)r	)r)rnrsrsrt�is_categoricalYs)zIndex.is_categoricalcCs
|jdkS)a�
        Check if the Index holds Interval objects.

        Returns
        -------
        bool
            Whether or not the Index holds Interval objects.

        See Also
        --------
        IntervalIndex : Index for Interval objects.
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_mixed : Check if the Index holds data with mixed data types.

        Examples
        --------
        >>> idx = pd.Index([pd.Interval(left=0, right=5),
        ...                 pd.Interval(left=5, right=10)])
        >>> idx.is_interval()
        True

        >>> idx = pd.Index([1, 3, 5, 7])
        >>> idx.is_interval()
        False
        �interval)r^)r)rnrsrsrt�is_interval�szIndex.is_intervalcCstjdtdd�|jdkS)a�
        Check if the Index holds data with mixed data types.

        Returns
        -------
        bool
            Whether or not the Index holds data with mixed data types.

        See Also
        --------
        is_boolean : Check if the Index only consists of booleans.
        is_integer : Check if the Index only consists of integers.
        is_floating : Check if the Index is a floating type.
        is_numeric : Check if the Index only consists of numeric data.
        is_object : Check if the Index is of the object dtype.
        is_categorical : Check if the Index holds categorical data.
        is_interval : Check if the Index holds Interval objects.

        Examples
        --------
        >>> idx = pd.Index(['a', np.nan, 'b'])
        >>> idx.is_mixed()
        True

        >>> idx = pd.Index([1.0, 2.0, 3.0, 5.0])
        >>> idx.is_mixed()
        False
        zqIndex.is_mixed is deprecated and will be removed in a future version. Check index.inferred_type directly instead.�)�
stacklevelr[)r[)�warnings�warn�
FutureWarningr)rnrsrsrt�is_mixed�s
zIndex.is_mixedcCs
|jdkS)z6
        Whether the type is an integer type.
        rW�
mixed-integer)rWrf)r)rnrsrsrt�
holds_integer�szIndex.holds_integercCstj|jdd�S)zG
        Return a string of the type inferred from the values.
        F)�skipna)r�infer_dtyperl)rnrsrsrtr�szIndex.inferred_typecCstt|j��S)zH
        Whether or not the index values only consist of dates.
        )rr#rl)rnrsrsrt�is_all_dates�szIndex.is_all_datescCs,t|jd�}|j|j��tt|�|fdfS)N)r�)r�r��updater�r�rk)rnr�rsrsrt�
__reduce__�szIndex.__reduce__cCs4|jrt|�Stjt|�tjd�}|jd�|SdS)z.
        Return if each value is NaN.
        )rbFN)r�rErf�emptyriZbool_�fill)rnr�rsrsrt�_isnan�s

zIndex._isnancCs(|jr|jj�dStjgtjd�SdS)Nr)rb)r�ro�nonzerorfr�int64)rnrsrsrt�	_nan_idxs�szIndex._nan_idxscCs|jrt|jj��SdSdS)zK
        Return if I have any nans; enables various perf speedups.
        FN)r�r�ror�)rnrsrsrt�hasnanssz
Index.hasnanscCs|jS)a
        Detect missing values.

        Return a boolean same-sized object indicating if the values are NA.
        NA values, such as ``None``, :attr:`numpy.NaN` or :attr:`pd.NaT`, get
        mapped to ``True`` values.
        Everything else get mapped to ``False`` values. Characters such as
        empty strings `''` or :attr:`numpy.inf` are not considered NA values
        (unless you set ``pandas.options.mode.use_inf_as_na = True``).

        Returns
        -------
        numpy.ndarray
            A boolean array of whether my values are NA.

        See Also
        --------
        Index.notna : Boolean inverse of isna.
        Index.dropna : Omit entries with missing values.
        isna : Top-level isna.
        Series.isna : Detect missing values in Series object.

        Examples
        --------
        Show which entries in a pandas.Index are NA. The result is an
        array.

        >>> idx = pd.Index([5.2, 6.0, np.NaN])
        >>> idx
        Float64Index([5.2, 6.0, nan], dtype='float64')
        >>> idx.isna()
        array([False, False,  True])

        Empty strings are not considered NA values. None is considered an NA
        value.

        >>> idx = pd.Index(['black', '', 'red', None])
        >>> idx
        Index(['black', '', 'red', None], dtype='object')
        >>> idx.isna()
        array([False, False, False,  True])

        For datetimes, `NaT` (Not a Time) is considered as an NA value.

        >>> idx = pd.DatetimeIndex([pd.Timestamp('1940-04-25'),
        ...                         pd.Timestamp(''), None, pd.NaT])
        >>> idx
        DatetimeIndex(['1940-04-25', 'NaT', 'NaT', 'NaT'],
                      dtype='datetime64[ns]', freq=None)
        >>> idx.isna()
        array([False,  True,  True,  True])
        )ro)rnrsrsrtrE
s5z
Index.isnacCs
|j�S)a
        Detect existing (non-missing) values.

        Return a boolean same-sized object indicating if the values are not NA.
        Non-missing values get mapped to ``True``. Characters such as empty
        strings ``''`` or :attr:`numpy.inf` are not considered NA values
        (unless you set ``pandas.options.mode.use_inf_as_na = True``).
        NA values, such as None or :attr:`numpy.NaN`, get mapped to ``False``
        values.

        Returns
        -------
        numpy.ndarray
            Boolean array to indicate which entries are not NA.

        See Also
        --------
        Index.notnull : Alias of notna.
        Index.isna: Inverse of notna.
        notna : Top-level notna.

        Examples
        --------
        Show which entries in an Index are not NA. The result is an
        array.

        >>> idx = pd.Index([5.2, 6.0, np.NaN])
        >>> idx
        Float64Index([5.2, 6.0, nan], dtype='float64')
        >>> idx.notna()
        array([ True,  True, False])

        Empty strings are not considered NA values. None is considered a NA
        value.

        >>> idx = pd.Index(['black', '', 'red', None])
        >>> idx
        Index(['black', '', 'red', None], dtype='object')
        >>> idx.notna()
        array([ True,  True,  True, False])
        )rE)rnrsrsrt�notnaCs*zIndex.notnacCs<|j|�|jr4|j|j|�}|dkr4t||jd�S|j�S)a�
        Fill NA/NaN values with the specified value.

        Parameters
        ----------
        value : scalar
            Scalar value to use to fill holes (e.g. 0).
            This value cannot be a list-likes.
        downcast : dict, default is None
            A dict of item->dtype of what to downcast if possible,
            or the string 'infer' which will try to downcast to an appropriate
            equal type (e.g. float64 to int64 if possible).

        Returns
        -------
        Index

        See Also
        --------
        DataFrame.fillna : Fill NaN values of a DataFrame.
        Series.fillna : Fill NaN Values of a Series.
        N)ry)�_assert_can_do_oprsrFrorZryr�)rnr.Zdowncastrqrsrsrt�fillnaqs
zIndex.fillnar�cCs8|dkrtd|����|jr0|j|j|j�S|j�S)a
        Return Index without NA/NaN values.

        Parameters
        ----------
        how : {'any', 'all'}, default 'any'
            If the Index is a MultiIndex, drop the value when any or all levels
            are NaN.

        Returns
        -------
        Index
        r�rdzinvalid how option: )r�rd)rjrsr�rlro)rn�howrsrsrt�dropna�s
zIndex.dropnacs&|dk	r|j|�t�j�}|j|�S)a�
        Return unique values in the index.

        Unique values are returned in order of appearance, this does NOT sort.

        Parameters
        ----------
        level : int or str, optional, default None
            Only return values from specified level (for MultiIndex).

            .. versionadded:: 0.23.0

        Returns
        -------
        Index without duplicates

        See Also
        --------
        unique
        Series.unique
        N)r<�superr`r�)rnr1rq)�	__class__rsrtr`�s

zIndex.unique�firstcst�j|d�S)a
        Return Index with duplicate values removed.

        Parameters
        ----------
        keep : {'first', 'last', ``False``}, default 'first'
            - 'first' : Drop duplicates except for the first occurrence.
            - 'last' : Drop duplicates except for the last occurrence.
            - ``False`` : Drop all duplicates.

        Returns
        -------
        deduplicated : Index

        See Also
        --------
        Series.drop_duplicates : Equivalent method on Series.
        DataFrame.drop_duplicates : Equivalent method on DataFrame.
        Index.duplicated : Related method on Index, indicating duplicate
            Index values.

        Examples
        --------
        Generate an pandas.Index with duplicate values.

        >>> idx = pd.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'])

        The `keep` parameter controls  which duplicate values are removed.
        The value 'first' keeps the first occurrence for each
        set of duplicated entries. The default value of keep is 'first'.

        >>> idx.drop_duplicates(keep='first')
        Index(['lama', 'cow', 'beetle', 'hippo'], dtype='object')

        The value 'last' keeps the last occurrence for each set of duplicated
        entries.

        >>> idx.drop_duplicates(keep='last')
        Index(['cow', 'beetle', 'lama', 'hippo'], dtype='object')

        The value ``False`` discards all sets of duplicated entries.

        >>> idx.drop_duplicates(keep=False)
        Index(['cow', 'beetle', 'hippo'], dtype='object')
        )�keep)ry�drop_duplicates)rnr|)rzrsrtr}�s.zIndex.drop_duplicatescst�j|d�S)a�
        Indicate duplicate index values.

        Duplicated values are indicated as ``True`` values in the resulting
        array. Either all duplicates, all except the first, or all except the
        last occurrence of duplicates can be indicated.

        Parameters
        ----------
        keep : {'first', 'last', False}, default 'first'
            The value or values in a set of duplicates to mark as missing.

            - 'first' : Mark duplicates as ``True`` except for the first
              occurrence.
            - 'last' : Mark duplicates as ``True`` except for the last
              occurrence.
            - ``False`` : Mark all duplicates as ``True``.

        Returns
        -------
        numpy.ndarray

        See Also
        --------
        Series.duplicated : Equivalent method on pandas.Series.
        DataFrame.duplicated : Equivalent method on pandas.DataFrame.
        Index.drop_duplicates : Remove duplicate values from Index.

        Examples
        --------
        By default, for each set of duplicated values, the first occurrence is
        set to False and all others to True:

        >>> idx = pd.Index(['lama', 'cow', 'lama', 'beetle', 'lama'])
        >>> idx.duplicated()
        array([False, False,  True, False,  True])

        which is equivalent to

        >>> idx.duplicated(keep='first')
        array([False, False,  True, False,  True])

        By using 'last', the last occurrence of each set of duplicated values
        is set on False and all others on True:

        >>> idx.duplicated(keep='last')
        array([ True, False,  True, False, False])

        By setting keep on ``False``, all duplicates are True:

        >>> idx.duplicated(keep=False)
        array([ True, False,  True, False,  True])
        )r|)ryra)rnr|)rzrsrtra�s6zIndex.duplicated)rxcCsr|jr|r|S|js0|j�}t|t�s6|j}n|j}|rhy|jrP|t|�}Wntk
rfYnX|j	|�S)z�
        Returns an index containing unique values.

        Parameters
        ----------
        dropna : bool, default False
            If True, NaN values are dropped.

        Returns
        -------
        uniques : index
        )
rQr`rer>r�rlrsrE�NotImplementedErrorr�)rnrxr�rsrsrt�_get_unique_index,	s

zIndex._get_unique_indexcCs.t|ttf�rtSddlm}t||�|�S)Nr)rY)rerBr<r|r}rYrZ)rnrorYrsrsrt�__add__P	sz
Index.__add__cCsddlm}t|||��S)Nr)rY)r}rYrZ)rnrorYrsrsrt�__radd__W	szIndex.__radd__cCs||S)Nrs)rnrorsrsrt�__iadd__\	szIndex.__iadd__cCsttj|�|�S)N)rZrfr)rnrorsrsrt�__sub__`	sz
Index.__sub__cCsddlm}t|||��S)Nr)rY)r}rYrZ)rnrorYrsrsrt�__rsub__c	szIndex.__rsub__cCs
|j|�S)N)�intersection)rnrorsrsrt�__and__i	sz
Index.__and__cCs
|j|�S)N)�union)rnrorsrsrt�__or__l	szIndex.__or__cCs
|j|�S)N)�symmetric_difference)rnrorsrsrt�__xor__o	sz
Index.__xor__cCstdt|�j�d���dS)NzThe truth value of a zC is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().)rjrkrw)rnrsrsrt�__nonzero__r	szIndex.__nonzero__cCs$t||�}|j|kr |j|d�S|S)z�
        If the result of a set operation will be self,
        return self, unless the name changes, in which
        case make a shallow copy of self.
        )ry)rPryr�)rnroryrsrsrt�_get_reconciled_name_object}	s

z!Index._get_reconciled_name_objectcCs:|jtdd�}t|�jtdd�}tj|||d�jtdd�S)a
        Casts this and other index to object dtype to allow the formation
        of a union between incompatible types.

        Parameters
        ----------
        other : Index or array-like
        sort : False or None, default False
            Whether to sort the resulting index.

            * False : do not sort the result.
            * None : sort the result, except when `self` and `other` are equal
              or when the values cannot be compared.

        Returns
        -------
        Index
        F)r)�sort)r�r�rZr�)rnror��thisrsrsrt�_union_incompatible_dtypes�	sz Index._union_incompatible_dtypescCst|�t|�kot|j|j�S)a8
        Check whether this and the other dtype are compatible with each other.
        Meaning a union can be formed between them without needing to be cast
        to dtype object.

        Parameters
        ----------
        other : Index or array-like

        Returns
        -------
        bool
        )rkr)rb)rnrorsrsrt�_is_compatible_with_other�	szIndex._is_compatible_with_othercCs|dkrtd|�d���dS)NFz;The 'sort' keyword only takes the values of None or False; z was passed.)NF)rj)rnr�rsrsrt�_validate_sort_keyword�	szIndex._validate_sort_keywordcCs:|j|�|j|�|j|�s,|j||d�S|j||d�S)at
        Form the union of two Index objects.

        If the Index objects are incompatible, both Index objects will be
        cast to dtype('object') first.

            .. versionchanged:: 0.25.0

        Parameters
        ----------
        other : Index or array-like
        sort : bool or None, default None
            Whether to sort the resulting Index.

            * None : Sort the result, except when

              1. `self` and `other` are equal.
              2. `self` or `other` has length 0.
              3. Some values in `self` or `other` cannot be compared.
                 A RuntimeWarning is issued in this case.

            * False : do not sort the result.

            .. versionadded:: 0.24.0

            .. versionchanged:: 0.24.1

               Changed the default value from ``True`` to ``None``
               (without change in behaviour).

        Returns
        -------
        union : Index

        Examples
        --------
        Union matching dtypes

        >>> idx1 = pd.Index([1, 2, 3, 4])
        >>> idx2 = pd.Index([3, 4, 5, 6])
        >>> idx1.union(idx2)
        Int64Index([1, 2, 3, 4, 5, 6], dtype='int64')

        Union mismatched dtypes

        >>> idx1 = pd.Index(['a', 'b', 'c', 'd'])
        >>> idx2 = pd.Index([1, 2, 3, 4])
        >>> idx1.union(idx2)
        Index(['a', 'b', 'c', 'd', 1, 2, 3, 4], dtype='object')
        )r�)r��_assert_can_do_setopr�r��_union)rnror�rsrsrtr��	s
3


zIndex.unionc	stt|�s|j|�r|j|�St|�s0|j|�S|j}|j}|dkr�|jr�|jr�y|j||�d}WnFtk
r�t|�}t|��|j	�fdd�|D��t
|�j}YnXn�|jr�|j|�}|dkj
�d}ntj|j|�d�}t|�dk�rtj||dd�}t||f�}n|}|dk�rhytj|�}Wn:tk
�rf}ztj|�d�td	d
�WYdd}~XnX|j||�S)a
        Specific union logic should go here. In subclasses, union behavior
        should be overwritten here rather than in `self.union`.

        Parameters
        ----------
        other : Index or array-like
        sort : False or None, default False
            Whether to sort the resulting index.

            * False : do not sort the result.
            * None : sort the result, except when `self` and `other` are equal
              or when the values cannot be compared.

        Returns
        -------
        Index
        Nrcsg|]}|�kr|�qSrsrs)r�r)�	value_setrsrtr�
sz Index._union.<locals>.<listcomp>r{F)r�z2, sort order is undefined for incomparable objects�)rar�)ri�equalsr�rlrOr�r�r�r��extendrZrQ�get_indexerrpr
�unique1d�get_indexer_non_unique�take_ndr:�	safe_sortrbrc�RuntimeWarning�_wrap_setop_result)	rnror��lvals�rvalsrq�indexerZ
other_diffr�rs)r�rtr��	s>



zIndex._unioncCst||�}|j||d�S)N)ry)rPr�)rnrorqryrsrsrtr�6
s
zIndex._wrap_setop_resultc
Cs�|j|�|j|�t|�}|j|�r8|jr8|j|�St|j|j�sh|jd�}|jd�}|j	||d�S|j
}|j
}|jr�|jr�y|j||�d}Wnt
k
r�YnX|j|tj|��Sy(t|�j|�}|j|dkj�d�}Wn>ttfk
�r"tjt|�j|�d�}||dk}YnX|j|�j�}t||�}	|dk�r`tj|j�}|j||	d�Stj|j
�j|j
jk�s|t�|	|_|S)	a�
        Form the intersection of two Index objects.

        This returns a new Index with elements common to the index and `other`.

        Parameters
        ----------
        other : Index or array-like
        sort : False or None, default False
            Whether to sort the resulting index.

            * False : do not sort the result.
            * None : sort the result, except when `self` and `other` are equal
              or when the values cannot be compared.

            .. versionadded:: 0.24.0

            .. versionchanged:: 0.24.1

               Changed the default from ``True`` to ``False``, to match
               the behaviour of 0.23.4 and earlier.

        Returns
        -------
        intersection : Index

        Examples
        --------
        >>> idx1 = pd.Index([1, 2, 3, 4])
        >>> idx2 = pd.Index([3, 4, 5, 6])
        >>> idx1.intersection(idx2)
        Int64Index([3, 4], dtype='int64')
        �O)r�rr{N)ryr�r�) r�r��ensure_indexr�rTr�r)rbr�r�rlrOr�r�r�r
r�rZr�r�rprrr�r`rPr�r�r��shaper�ry)
rnror�r�r�r�rqr�r�Zres_namersrsrtr�;
s>"






zIndex.intersectioncCs�|j|�|j|�|j|�r2|j|jdd��S|j|�\}}|j�}|j|�}|j|dkj	�d�}t
jt
j|j
�|dd�}|jj|�}|dkr�ytj|�}Wntk
r�YnX|j||d�S)a}
        Return a new Index with elements of index not in `other`.

        This is the set difference of two Index objects.

        Parameters
        ----------
        other : Index or array-like
        sort : False or None, default None
            Whether to sort the resulting index. By default, the
            values are attempted to be sorted, but any TypeError from
            incomparable elements is caught by pandas.

            * None : Attempt to sort the result, but catch any TypeErrors
              from comparing incomparable elements.
            * False : Do not sort the result.

            .. versionadded:: 0.24.0

            .. versionchanged:: 0.24.1

               Changed the default value from ``True`` to ``None``
               (without change in behaviour).

        Returns
        -------
        difference : Index

        Examples
        --------
        >>> idx1 = pd.Index([2, 1, 3, 4])
        >>> idx2 = pd.Index([3, 4, 5, 6])
        >>> idx1.difference(idx2)
        Int64Index([1, 2], dtype='int64')
        >>> idx1.difference(idx2, sort=False)
        Int64Index([2, 1], dtype='int64')
        Nrr{T)�
assume_unique)ryr�)r�r�r�r�r��_convert_can_do_setoprr�r�rprf�	setdiff1d�arange�sizer�r
r�r�)rnror��result_namer�r�Z
label_diff�the_diffrsrsrt�
difference�
s &



zIndex.differencec

Cs�|j|�|j|�|j|�\}}|dkr.|}|j�}|j�}|j|�}|j|dkj�d�}tjtj	|j
�|dd�}|jj|�}	|dkj�d}
|jj|
�}t|	|g�}|dkr�yt
j|�}Wntk
r�YnXt||j|d�S)	a�
        Compute the symmetric difference of two Index objects.

        Parameters
        ----------
        other : Index or array-like
        result_name : str
        sort : False or None, default None
            Whether to sort the resulting index. By default, the
            values are attempted to be sorted, but any TypeError from
            incomparable elements is caught by pandas.

            * None : Attempt to sort the result, but catch any TypeErrors
              from comparing incomparable elements.
            * False : Do not sort the result.

            .. versionadded:: 0.24.0

            .. versionchanged:: 0.24.1

               Changed the default value from ``True`` to ``None``
               (without change in behaviour).

        Returns
        -------
        symmetric_difference : Index

        Notes
        -----
        ``symmetric_difference`` contains elements that appear in either
        ``idx1`` or ``idx2`` but not both. Equivalent to the Index created by
        ``idx1.difference(idx2) | idx2.difference(idx1)`` with duplicates
        dropped.

        Examples
        --------
        >>> idx1 = pd.Index([1, 2, 3, 4])
        >>> idx2 = pd.Index([2, 3, 4, 5])
        >>> idx1.symmetric_difference(idx2)
        Int64Index([1, 5], dtype='int64')

        You can also use the ``^`` operator:

        >>> idx1 ^ idx2
        Int64Index([1, 5], dtype='int64')
        Nr{rT)r�)rbryr�r�)r�r�r�rr�r�rprfr�r�r�rlr:r
r�r�rZrb)
rnror�r�Zresult_name_updater�r�Zcommon_indexer�left_indexerZ	left_diff�
right_indexerZ
right_diffr�rsrsrtr��
s*/


zIndex.symmetric_differencecCst|�std��dS)Nz!Input must be Index or array-likeT)r2r�)rnrorsrsrtr�szIndex._assert_can_do_setopcCs2t|t�s t||jd�}|j}n
t||�}||fS)N)ry)rerZryrP)rnror�rsrsrtr�s


zIndex._convert_can_do_setopcCs�|dkr\|dk	rtd��|j|�}y|jj|�Stk
rZ}zt|�|�WYdd}~XnX|dk	rv|j|tj|��}|j|g||d�}|j	dks�|j
dkr�td��|j�}|dkr�t|��|S)a
        Get integer location, slice or boolean mask for requested label.

        Parameters
        ----------
        key : label
        method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
            * default: exact matches only.
            * pad / ffill: find the PREVIOUS index value if no exact match.
            * backfill / bfill: use NEXT index value if no exact match
            * nearest: use the NEAREST index value if no exact match. Tied
              distances are broken by preferring the larger index value.
        tolerance : int or float, optional
            Maximum distance from index value for inexact matches. The value of
            the index at the matching location most satisfy the equation
            ``abs(index[loc] - key) <= tolerance``.

        Returns
        -------
        loc : int if unique index, slice if monotonic index, else mask

        Examples
        --------
        >>> unique_index = pd.Index(list('abc'))
        >>> unique_index.get_loc('b')
        1

        >>> monotonic_index = pd.Index(list('abbc'))
        >>> monotonic_index.get_loc('b')
        slice(1, 3, None)

        >>> non_monotonic_index = pd.Index(list('abcb'))
        >>> non_monotonic_index.get_loc('b')
        array([False,  True, False,  True])
        NzGtolerance argument only valid if using pad, backfill or nearest lookups)�method�	tolerancer{z$get_loc requires scalar valued inputr�)
rj�_maybe_cast_indexerr��get_locr;�_convert_tolerancerfrmr�rhr�r��item)rn�keyr�r�Z
casted_keyr�r��locrsrsrtr�&s$$
z
Index.get_loca�
        Compute indexer and mask for new index given the current index. The
        indexer should be then used as an input to ndarray.take to align the
        current data to the new index.

        Parameters
        ----------
        target : %(target_klass)s
        method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
            * default: exact matches only.
            * pad / ffill: find the PREVIOUS index value if no exact match.
            * backfill / bfill: use NEXT index value if no exact match
            * nearest: use the NEAREST index value if no exact match. Tied
              distances are broken by preferring the larger index value.
        limit : int, optional
            Maximum number of consecutive labels in ``target`` to match for
            inexact matches.
        tolerance : optional
            Maximum distance between original and new labels for inexact
            matches. The values of the index at the matching locations most
            satisfy the equation ``abs(index[indexer] - target) <= tolerance``.

            Tolerance may be a scalar value, which applies the same tolerance
            to all values, or list-like, which applies variable tolerance per
            element. List-like includes list, tuple, array, Series, and must be
            the same size as the index and its dtype must exactly match the
            index's type.

        Returns
        -------
        indexer : ndarray of int
            Integers from 0 to n - 1 indicating that the index at these
            positions matches the corresponding target values. Missing values
            in the target are marked by -1.
        %(raises_section)s
        Examples
        --------
        >>> index = pd.Index(['c', 'a', 'b'])
        >>> index.get_indexer(['a', 'b', 'x'])
        array([ 1,  2, -1])

        Notice that the return value is an array of locations in ``index``
        and ``x`` is marked by -1, as it is not in ``index``.
        r�c	Cs0tj|�}t|�}|dk	r&|j||�}|j�rH|j�rHttjd	|j	��S|j
|�\}}||k	sf||k	rx|j||||d�St|j
|j
�s�|jt�}|jt�}|j||||d�S|js�td��|dks�|dkr�|j||||�}nL|dkr�|j|||�}n4|dk	�rtd��|dk	�rtd��|jj|j��}t|�S)
Nr{)r��limitr�z8Reindexing only valid with uniquely valued Index objects�pad�backfillZnearestzJtolerance argument only valid if doing pad, backfill or nearest reindexingzFlimit argument only valid if doing pad, backfill or nearest reindexingr�)�missingZclean_reindex_fill_methodr�r�rVr\r$rfr�r��_maybe_promoter�r)rbr�r�rQr�_get_fill_indexer�_get_nearest_indexerrjr�r�)	rn�targetr�r�r��pself�ptargetr�r�rsrsrtr��s<




zIndex.get_indexercCs,tj|�}|j|jkr(|jdkr(td��|S)Nr{z5list-like tolerance size must match target index size)rfrmr�rj)rnr�r�rsrsrtr��s
zIndex._convert_tolerance)r�r�r�cCs`|j�}|jr8|jr8|dkr$|jjn|jj}|||�}n|j|||�}|dk	r\|j|||�}|S)Nr�)r�rNr�Zget_pad_indexerZget_backfill_indexer�_get_fill_indexer_searchsorted�_filter_indexer_tolerance)rnr�r�r�r�r�Z
engine_methodr�rsrsrtr��szIndex._get_fill_indexercCs�|dk	rtdt|��d���|dkr(dnd}|j|�}|dk}|j|||�||<|dkrl||d8<nd	||t|�k<|S)
z�
        Fallback pad/backfill get_indexer that works for monotonic decreasing
        indexes and non-monotonic targets.
        Nzlimit argument for z; method only well-defined if index and target are monotonicr�rpr�r{r�r�)rjr�r��_searchsorted_monotonicri)rnr�r�r��sider�Znonexactrsrsrtr��s
z$Index._get_fill_indexer_searchsorted)r�r�cCs�|j|d|d�}|j|d|d�}|j}tj|j||�}tj|j||�}|jrZtjntj}	tj|	||�|dkB||�}
|dk	r�|j	||
|�}
|
S)z�
        Get the indexer for the nearest index labels; requires an index with
        values that can be subtracted from each other (e.g., not strings or
        tuples).
        r�)r�r�r{Nr�)
r�rlrf�absrN�operator�lt�le�wherer�)rnr�r�r�r�r�r�Zleft_distancesZright_distancesrrr�rsrsrtr�szIndex._get_nearest_indexer)r�r�r�cCs(t|j||�}tj||k|d�}|S)Nr{r�)r�rlrfr�)rnr�r�r�Zdistancersrsrtr�szIndex._filter_indexer_tolerancecCs|S)z�
        Translate any partial string timestamp matches in key, returning the
        new key.

        Only relevant for MultiIndex.
        rs)rnr�rsrsrt�'_get_partial_string_timestamp_match_key$sz-Index._get_partial_string_timestamp_match_key)r�cCs4|jd|jd�|jd|jd�|jd|jd�dS)zz
        For positional indexing, a slice must have either int or None
        for each of start, stop, and step.
        Z
positional�ilocN)�_validate_indexerr��stop�step)rnr�rsrsrt�_validate_positional_slice.sz Index._validate_positional_slice)r��kindc
Cs6|dkst|��|j|j|j}}}dd�}||�oD||�oD||�}|oZ|j�pX|j�}|dkr�|j�sp|r�|jd|jd�|jd|jd�|jd|jd�|S|r�y,|dk	r�|j|�|dk	r�|j|�d}Wntk
r�YnXt	j
|�r�|}	n8|�r |dk�rtjdt
d	d
�|}	n|j||||d�}	|	S)
a(
        Convert a slice indexer.

        By definition, these are labels unless 'iloc' is passed in.
        Floats are not allowed as the start, step, or stop of the slice.

        Parameters
        ----------
        key : label of the slice bound
        kind : {'loc', 'getitem'}
        r��getitemcSs|dkpt|�S)N)r.)r�rsrsrt�is_intIsz,Index._convert_slice_indexer.<locals>.is_int�sliceNFz�Slicing a positional slice with .loc is not supported, and will raise TypeError in a future version.  Use .loc with labels or .iloc with positions instead.�)ra)r�)r�r�)r�r�r�r�r.r]r�r�r;r�Z
is_null_slicerbrcrd�
slice_indexer)
rnr�r�r�r�r�r�Zis_index_sliceZ
is_positionalr�rsrsrt�_convert_slice_indexer7s@



zIndex._convert_slice_indexercCs2t|t�r|j|�}n
|j|�}|j|�}||fS)a/
        Parameters
        ----------
        keyarr : list-like
            Indexer to convert.

        Returns
        -------
        indexer : numpy.ndarray or None
            Return an ndarray or None if cannot convert.
        keyarr : numpy.ndarray
            Return tuple-safe keys.
        )rerZ�_convert_index_indexer�_convert_arr_indexer�_convert_list_indexer)rn�keyarrr�rsrsrt�_convert_listlike_indexer}s



zIndex._convert_listlike_indexercCstj|�}|S)z�
        Convert an array-like indexer to the appropriate dtype.

        Parameters
        ----------
        keyarr : array-like
            Indexer to convert.

        Returns
        -------
        converted_keyarr : array-like
        )r�r�)rnr�rsrsrtr��s
zIndex._convert_arr_indexercCs|S)a
        Convert an Index indexer to the appropriate dtype.

        Parameters
        ----------
        keyarr : Index (or sub-class)
            Indexer to convert.

        Returns
        -------
        converted_keyarr : Index (or sub-class)
        rs)rnr�rsrsrtr��s
zIndex._convert_index_indexercCsdS)a
        Convert a list-like indexer to the appropriate dtype.

        Parameters
        ----------
        keyarr : Index (or sub-class)
            Indexer to convert.
        kind : iloc, loc, optional

        Returns
        -------
        positional indexer or None
        Nrs)rnr�rsrsrtr��szIndex._convert_list_indexer)�formc
Cs0td|�dt|�j�d|�dt|�j����dS)z5
        Consistent invalid indexer message.
        z
cannot do z
 indexing on z with these indexers [z
] of type N)r�rkrw)rnr�r�rsrsrt�_invalid_indexer�szIndex._invalid_indexercCs|jrt|�rtd��dS)z�
        Check if we are allowing reindexing with this particular indexer.

        Parameters
        ----------
        indexer : an integer indexer

        Raises
        ------
        ValueError if its a duplicate axis
        z$cannot reindex from a duplicate axisN)rQrirj)rnr�rsrsrt�_can_reindex�s
zIndex._can_reindexcCs0t|d�}t|�}t|t�r`t|�dkr`t|t�r@td�}n|jdd�}|j||j	d�}nt
|�}|dk	r�|dk	r�td��|j||ddd�\}}	}n^|j
|�r�d}	nN|jr�t|d	d
�r�|j||||d�}	n&|dk	s�|dk	r�td��|j|�\}	}
|�r(|jd
k�r(|j	|j	k�r(|j�}|j	|_	||	fS)a0
        Create index with target's values.

        Parameters
        ----------
        target : an iterable

        Returns
        -------
        new_index : pd.Index
            Resulting index.
        indexer : np.ndarray or None
            Indices of output values in original index.
        ryrN)ryz)Fill method not supported if level passedr�T)rw�return_indexersZis_overlappingF)r�r�r�z8cannot reindex a non-unique index with a method or limitr{)r��ensure_has_lenrerZrirAr�r�r�ryr�r��_join_levelr�rQr�r�rjr�r5r)rnr�r�r1r�r�Zpreserve_namesr��_r�r�rsrsrt�reindex�s4


 z
Index.reindexc
Cs>t|�}|j|�\}}|dk}|j||�}d}t|��rtjt|��}t|�}|j|�}t||�}	|j||�j}
t||�}tj	t
t|�g�td�}|
||<|||	<|jr�tjt|��}tjt|
��||<d||	<n(d||<tjt|j|���}d	||<t
|t��r&t|�j||jd�}nt||jd�}|||fS)
a�
        Create a new index with target's values (move/add/delete values as
        necessary) use with non-unique Index and a possibly non-unique target.

        Parameters
        ----------
        target : an iterable

        Returns
        -------
        new_index : pd.Index
            Resulting index.
        indexer : np.ndarray or None
            Indices of output values in original index.

        r{N)rb)r�)ryr�r�r�r�)r�r�r�rirfr�r$r"r�rmr~r�rQrer>rkr�r�rZry)
rnr�r�r��checkZ
new_labelsZnew_indexer�lengthZmissing_labelsZmissing_indexerZ
cur_labelsZcur_indexerr�rsrsrt�_reindex_non_unique
s4




zIndex._reindex_non_uniquerpcCs�t|�}t|t�}t|t�}|dkrJ|s,|rJ|j|jkr:n|j|||d�S|dk	rl|sZ|rl|j||||d�St|�dkr�|dkr�|j�}|r�tj	dt|��}	|d|	fS|St|�dkr�|dkr�|j�}|r�tj	dt|��}
||
dfS|S|j
|j
k�r8ddd�j||�}|j||||d	�}|�r4|\}}
}|||
f}|St
|j|j��sl|jd
�}|jd
�}|j|||d�St|�|j�r�|j�r�|j|||d�S|j�s�|j�r�|j�r�|j�r�|j|||d�S|j|||d�Sn8|j�r|j�ry|j|||d�Stk
�rYnX|dk�r&|}n>|dk�r6|}n.|dk�rP|j|dd
�}n|dk�rd|j|�}|�rr|j�}|�r�||k�r�d}
n
|j|�}
||k�r�d}	n
|j|�}	||
|	fS|SdS)aH
        Compute join_index and indexers to conform data
        structures to the new index.

        Parameters
        ----------
        other : Index
        how : {'left', 'right', 'inner', 'outer'}
        level : int or level name, default None
        return_indexers : bool, default False
        sort : bool, default False
            Sort the join keys lexicographically in the result Index. If False,
            the order of the join keys depends on the join type (how keyword).

        Returns
        -------
        join_index, (left_indexer, right_indexer)
        N)rwr�rrp�outerr{r�)r�rp)rwr1r�r��innerF)r�)rpr�r�)r�r�r�)r�rer>r��_join_multir�rir�rfr��_join_precedencer�rr)rbr��_validate_join_methodrQ�_join_non_uniquerO�_join_monotonicr�r�r�r@r�)rnrorwr1r�r��
self_is_mi�other_is_mi�
join_indexZrindexerZlindexerrqr�y�zr�rsrsrtrZ
s�

















z
Index.joincCs�ddlm}ddlm}ttj|j��}ttj|j��}||@}|sLtd��t	|t
�}	t	|t
�}
|	of|
�rt||�}t||�}t||�s�|}
|j
|j�}n|j|�}
|j|�}|
j||dd�\}}}||}|||||||�\}}}||||dd�}|j�}|�r|||fS|St|�d}d}|	�rL||}}d}d	d
d�j||�}|jj|�}|j||||d�}|�r�t	|t��r�|d|d
|dfS|S)Nr)r�)�!_restore_dropped_levels_multijoinz+cannot join with no overlapping index namesT)r�F)rCr�r�rDrpr�)r�rp)rwr�r`r{)r�r��pandas.core.reshape.merger�r�r�Znot_noner�rjrer>r�riZreorder_levelsrKrZremove_unused_levelsr�rr�r~)rnrorwr�r�r�Z
self_namesZother_names�overlapr�r�Zldrop_namesZrdrop_namesZ
self_jnlevelsZother_jnlevelsZjoin_idx�lidx�ridxZ
dropped_namesrCr�r�Zmulti_join_idxZjl�
flip_orderr1rqrsrsrtr��
sR






zIndex._join_multicCs�ddlm}|j|jkst�|j�}|j�}||g|g|dd�\}}t|�}t|�}tj|j|��}	|dk}
tj	|	|
|j|��|j
|	|�}	|r�|	||fS|	SdS)Nr)�_get_join_indexersT)rwr�r{r�)r�r�rbr�r�r$rfrmr�rF�_wrap_joined_index)rnrorwr�r�ZlvaluesZrvaluesZleft_idxZ	right_idxr�r rsrsrtr�"s
zIndex._join_non_uniquecs�ddlm}dd�}t||�r0t||�r0td��||}}	t||�}
|
rf|	|}}	ddd�j||�}|j|�}|j|}|	js�td	��|j	|	|d
d�\}}
}|
dkr�|s�t
|�dkr�d�|}n||jd|d
���|�}�nZt|
�}
t
j|
t
|��}tj||j|dd�}t|j�}|||<t|j�}|||<|�r|tjt
|�tjd��|dk��j��s*�fdd�|D�}���n�|dk�r�d
|j�}tj||�\�}�|dd���fdd�|D�}nd|dk��j�}|�s�fdd�|D�}||d|d
����fdd�|D�}|�s*�j�d��||||jdd�}|dk	�r^tj||j|dd�}n
|j|}|
�rx|��}|�r��dk�r�dnt���|dk�r�dnt|�}|�|fS|SdS)ai
        The join method *only* affects the level of the resulting
        MultiIndex. Otherwise it just exactly aligns the Index data to the
        labels of the level in the MultiIndex.

        If ```keep_order == True```, the order of the data indexed by the
        MultiIndex will not be changed; otherwise, it will tie out
        with `other`.
        r)r�cSs�|djdkrtjddd�St|�dkrPt|d�}tj|d|j��\}}|S|ddd�|ddd�k}x0|dd�D] }||dd	�|dd�kO}q~Wtjdg|dgf�j	�d}t|d
�}t
j|t|��S)zz
            Returns sorter for the inner most level while preserving the
            order of higher levels.
            rrq)rbr{NTr�r�r�r�)r�rfrmrir"�libalgos�groupsort_indexer�maxZhstackrprZget_level_sorter)r��labZsorterr�ZticZstartsrsrsrt�_get_leaf_sorterKs  z+Index._join_level.<locals>._get_leaf_sorterz9Join on level between two MultiIndex objects is ambiguousrpr�)r�rpz8Index._join_level on non-unique index is not implementedT)rwr�Nr{F)r�)rbcsg|]}|��qSrsrs)r�r�)r rsrtr��sz%Index._join_level.<locals>.<listcomp>csg|]}|��qSrsrs)r�r�)r�rsrtr��scsg|]}|��qSrsrs)r�r�)r rsrtr��scsg|]}|��qSrsrs)r�r�)r�rsrtr��s)rCr�r�rDr�r�)r�r�rer�r�r=rCrQr~rrir�r"rZget_reverse_indexerr
r�r�rfr��intprdr�r�r�rpr�r$)rnror1rwr�Z
keep_orderr�r�rpr�r�Z	old_levelZ	new_levelZleft_lev_indexerZright_lev_indexerr�Zrev_indexerZ
new_lev_codesrIrHZngroups�countsZmask_allr�rs)r�r rtr�=s�












zIndex._join_levelc
Cs�|j|jkst�|j|�r<|dkr&|n|}|r8|ddfS|S|j�}|j�}|jr�|jr�|dkrv|}d}|j||�}	nl|dkr�|}|j||�}d}	nN|dkr�|j||�\}}}	|j||�}n&|dkr�|j||�\}}}	|j||�}n�|dk�r|j	||�\}}}	nX|dk�r |j	||�\}}	}n:|dk�r>|j||�\}}}	n|dk�rZ|j||�\}}}	|j||�}|�r�|dk�rzdnt
|�}|	dk�r�dnt
|	�}	|||	fS|SdS)Nr�rpr�r�)rbr�r�r�rQr�r�r�r�r�r$)
rnrorwr�Z	ret_index�sv�ovr�r�r�rsrsrtr��sJ






zIndex._join_monotoniccCst||�}t||d�S)N)ry)rPrZ)rnZjoinedroryrsrsrtr��s
zIndex._wrap_joined_indexcCs|jjtj�S)a
        Return an array representing the data in the Index.

        .. warning::

           We recommend using :attr:`Index.array` or
           :meth:`Index.to_numpy`, depending on whether you need
           a reference to the underlying data or a NumPy array.

        Returns
        -------
        array: numpy.ndarray or ExtensionArray

        See Also
        --------
        Index.array : Reference to the underlying data.
        Index.to_numpy : A NumPy array representing the underlying data.
        )r�r�rfrg)rnrsrsrtr�szIndex.valuescCs*|j}t|tj�r&ddlm}||�}|S)Nr)�PandasArray)r�rerfrgZpandas.core.arrays.numpy_r)rnrrrsrsrtrs
zIndex.arraycCs|jS)a
        The best array representation.

        This is an ndarray or ExtensionArray.

        ``_values`` are consistent between``Series`` and ``Index``.

        It may differ from the public '.values' method.

        index             | values          | _values       |
        ----------------- | --------------- | ------------- |
        Index             | ndarray         | ndarray       |
        CategoricalIndex  | Categorical     | Categorical   |
        DatetimeIndex     | ndarray[M8ns]   | DatetimeArray |
        DatetimeIndex[tz] | ndarray[M8ns]   | DatetimeArray |
        PeriodIndex       | ndarray[object] | PeriodArray   |
        IntervalIndex     | IntervalArray   | IntervalArray |

        See Also
        --------
        values
        )r�)rnrsrsrtrl!sz
Index._valuescCs|jS)zR
        Get the ndarray that we can pass to the IndexEngine constructor.
        )rl)rnrsrsrtr�;szIndex._get_engine_target)r�r�cs$t�j|d�}||jj|d�7}|S)N)r�)ry�memory_usager��sizeof)rnr�rq)rzrsrtrAszIndex.memory_usagecCsn|dkr|j}|j}|j}t|�s*t|�r8|jt�}d}tj|||�}|j	r^tj
t|��r^d}t|||j
d�S)a�
        Replace values where the condition is False.

        The replacement is taken from other.

        Parameters
        ----------
        cond : bool array-like with the same length as self
            Condition to select the values on.
        other : scalar, or array-like, default None
            Replacement if the condition is False.

        Returns
        -------
        pandas.Index
            A copy of self with values replaced from other
            where the condition is False.

        See Also
        --------
        Series.where : Same method for Series.
        DataFrame.where : Same method for DataFrame.

        Examples
        --------
        >>> idx = pd.Index(['car', 'bike', 'train', 'tractor'])
        >>> idx
        Index(['car', 'bike', 'train', 'tractor'], dtype='object')
        >>> idx.where(idx.isin(['car', 'train']), 'other')
        Index(['car', 'other', 'train', 'other'], dtype='object')
        N)rbry)r�rbr�r%r&r�r�rfr��_is_numeric_dtyper�rErZry)rnZcondrorbr�rsrsrtr�Is 
zIndex.wherecCst|j�dt|��d��S)Nz5(...) must be called with a collection of some kind, z was passed)r�rwr�)rxr�rsrsrtr�szIndex._scalar_data_errorcCstd��dS)NzMString dtype not supported, you may need to explicitly cast to a numeric type)r�)rxr�rsrsrt�_string_data_error�szIndex._string_data_errorcCs2|j}|jrt|�rd}t|gfd|i|j���S)z�
        We need to coerce a scalar to a compat for our index type.

        Parameters
        ----------
        item : scalar item to coerce
        Nrb)rbrrErZr�)rnr�rbrsrsrt�_coerce_scalar_to_index�szIndex._coerce_scalar_to_indexcCs|S)z<
        Convert to object if we are a categorical.
        rs)rnrsrsrt�_to_safe_for_reshape�szIndex._to_safe_for_reshapecCs|S)z<
        Convert value to be insertable to ndarray.
        rs)rnr.rsrsrt�_convert_for_op�szIndex._convert_for_opcCs t|�stdt|�j����dS)z5
        Check value is valid for scalar op.
        z"'value' must be a scalar, passed: N)r5r�rkrw)rnr.rsrsrtru�szIndex._assert_can_do_opcCsdS)zO
        Indicates if an index is not directly backed by a numpy array
        Frs)rnrsrsrt�_has_complex_internals�szIndex._has_complex_internalscCs|j�S)zH
        Return a boolean if we need a qualified .info display.
        )r#)rnrsrsrt�_is_memory_usage_qualified�sz Index._is_memory_usage_qualifiedcCs
||jkS)zN
        Whether the index type is compatible with the provided type.
        )r)rnr�rsrsrt�is_type_compatible�szIndex.is_type_compatible)r�r�c
Cs2t|�y
||jkStttfk
r,dSXdS)a�
        Return a boolean indicating whether the provided key is in the index.

        Parameters
        ----------
        key : label
            The key to check if it is present in the index.

        Returns
        -------
        bool
            Whether the key search is in the index.

        Raises
        ------
        TypeError
            If the key is not hashable.

        See Also
        --------
        Index.isin : Returns an ndarray of boolean dtype indicating whether the
            list-like key is in the index.

        Examples
        --------
        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx
        Int64Index([1, 2, 3, 4], dtype='int64')

        >>> 2 in idx
        True
        >>> 6 in idx
        False
        FN)�hashr��
OverflowErrorr�rj)rnr�rsrsrt�__contains__�s
#
zIndex.__contains__cCstdtt|�j�����dS)Nzunhashable type: )r�r�rkrw)rnrsrsrt�__hash__�szIndex.__hash__cCstd��dS)Nz)Index does not support mutable operations)r�)rnr�r.rsrsrt�__setitem__�szIndex.__setitem__cCs�|jj}|j}t|�r,tj|dd�}||�St|t�rB|||��Stj|�rZt	j
|td�}||�}t|�s�t	j|�dkr�t
|�|S||�S|SdS)aA
        Override numpy.ndarray's __getitem__ method to work as desired.

        This function adds lists and Series as valid boolean indexers
        (ndarrays only supports ndarray with dtype=bool).

        If resulting ndim != 1, plain ndarray is returned instead of
        corresponding `Index` subclass.

        T)Z
warn_float)rbr{N)r��__getitem__r�r5r��cast_scalar_indexerrer�Zis_bool_indexerrfrmr�rhrN)rnr�r�Zpromoterqrsrsrtr�s 


zIndex.__getitem__cCs|j�s|j�r||kSdS)a]
        Faster check for ``name in self`` when we know `name` is a Python
        identifier (e.g. in NDFrame.__getattr__, which hits this to support
        . key lookup). For indexes that can't hold identifiers (everything
        but object & categorical) we just return False.

        https://github.com/pandas-dev/pandas/issues/19764
        F)r#r])rnryrsrsrt�$_can_hold_identifiers_and_holds_names	z*Index._can_hold_identifiers_and_holds_namecCs||g}t|ttf�r"|t|�}n
|j|�x|D]}t|t�s2td��q2Wdd�|D�}t|�dkrjdn|j}|j||�S)z�
        Append a collection of Index options together.

        Parameters
        ----------
        other : Index or list/tuple of indices

        Returns
        -------
        appended : Index
        zall inputs must be IndexcSsh|]
}|j�qSrs)ry)r��objrsrsrt�	<setcomp>?szIndex.append.<locals>.<setcomp>r{N)	rer�r~rrZr�riry�_concat)rnro�	to_concatrr�ryrsrsrtr(s


zIndex.appendcCs$dd�|D�}tj|�}t||d�S)z5
        Concatenate multiple Index objects.
        cSs g|]}t|t�r|jn|�qSrs)rerZrl)r�rrsrsrtr�Hsz!Index._concat.<locals>.<listcomp>)ry)rr:rZ)rnrryrqrsrsrtrDs
z
Index._concatcCs�|jj�}y6tj|||j|��t|j�r8t|�|�j}|j	|�St
tfk
r~}zt|�rb|�|j
t�j||�Sd}~XnXdS)z�
        Return a new Index of the values set with the mask.

        Returns
        -------
        Index

        See Also
        --------
        numpy.ndarray.putmask
        N)r�rrfrFrr4rbrkr�r�rjr�r3r�r�)rnr r.r�r�rsrsrtrFMs


z
Index.putmask)ror�cCsr|j|�rdSt|t�sdSt|j�r<t|j�r<|j|�St|t�rP|j|�St|j�rd|j|�St|j	|j	�S)a
        Determine if two Index object are equal.

        The things that are being compared are:

        * The elements inside the Index object.
        * The order of the elements inside the Index object.

        Parameters
        ----------
        other : Any
            The other object to compare against.

        Returns
        -------
        bool
            True if "other" is an Index and it has the same elements and order
            as the calling index; False otherwise.

        Examples
        --------
        >>> idx1 = pd.Index([1, 2, 3])
        >>> idx1
        Int64Index([1, 2, 3], dtype='int64')
        >>> idx1.equals(pd.Index([1, 2, 3]))
        True

        The elements inside are compared

        >>> idx2 = pd.Index(["1", "2", "3"])
        >>> idx2
        Index(['1', '2', '3'], dtype='object')

        >>> idx1.equals(idx2)
        False

        The order is compared

        >>> ascending_idx = pd.Index([1, 2, 3])
        >>> ascending_idx
        Int64Index([1, 2, 3], dtype='int64')
        >>> descending_idx = pd.Index([3, 2, 1])
        >>> descending_idx
        Int64Index([3, 2, 1], dtype='int64')
        >>> ascending_idx.equals(descending_idx)
        False

        The dtype is *not* compared

        >>> int64_idx = pd.Int64Index([1, 2, 3])
        >>> int64_idx
        Int64Index([1, 2, 3], dtype='int64')
        >>> uint64_idx = pd.UInt64Index([1, 2, 3])
        >>> uint64_idx
        UInt64Index([1, 2, 3], dtype='uint64')
        >>> int64_idx.equals(uint64_idx)
        True
        TF)
r�rerZr3rbr�r>r*rDrl)rnrorsrsrtr�gs;






zIndex.equalscs4�j��o2t��fdd��jD��o2t��t��kS)z�
        Similar to equals, but checks that object attributes and types are also equal.

        Returns
        -------
        bool
            If two Index objects have equal elements and same type True,
            otherwise False.
        c3s&|]}t�|d�t�|d�kVqdS)N)r�)r��c)rornrsrtr��sz"Index.identical.<locals>.<genexpr>)r�rd�_comparablesrk)rnrors)rornrt�	identical�s

zIndex.identicalcCsRy|j|dd�}Wntk
r(|jSXt|t�rF|jt|��d}||SdS)aB
        Return the label from the index, or, if not present, the previous one.

        Assuming that the index is sorted, return the passed index label if it
        is in the index, or return the previous index label if the passed one
        is not in the index.

        Parameters
        ----------
        label : object
            The label up to which the method returns the latest index label.

        Returns
        -------
        object
            The passed label if it is in the index. The previous label if the
            passed label is not in the sorted index or `NaN` if there is no
            such label.

        See Also
        --------
        Series.asof : Return the latest value in a Series up to the
            passed index.
        merge_asof : Perform an asof merge (similar to left join but it
            matches on nearest key rather than equal key).
        Index.get_loc : An `asof` is a thin wrapper around `get_loc`
            with method='pad'.

        Examples
        --------
        `Index.asof` returns the latest index label up to the passed label.

        >>> idx = pd.Index(['2013-12-31', '2014-01-02', '2014-01-03'])
        >>> idx.asof('2014-01-01')
        '2013-12-31'

        If the label is in the index, the method returns the passed label.

        >>> idx.asof('2014-01-02')
        '2014-01-02'

        If all of the labels in the index are later than the passed label,
        NaN is returned.

        >>> idx.asof('1999-01-02')
        nan

        If the index is not sorted, an error is raised.

        >>> idx_not_sorted = pd.Index(['2013-12-31', '2015-01-02',
        ...                            '2014-01-03'])
        >>> idx_not_sorted.asof('2013-12-31')
        Traceback (most recent call last):
        ValueError: index must be monotonic increasing or decreasing
        r�)r�r{Nr�)r�r;r�rer�r�ri)rn�labelr�rsrsrt�asof�s8
z
Index.asofcCsl|j|j|jdd�}tj|dk|dd�}tjt|��|j|�}|j�}d||dk|j|j|k@<|S)a�
        Return the locations (indices) of labels in the index.

        As in the `asof` function, if the label (a particular entry in
        `where`) is not in the index, the latest index label up to the
        passed label is chosen and its index returned.

        If all of the labels in the index are later than a label in `where`,
        -1 is returned.

        `mask` is used to ignore NA values in the index during calculation.

        Parameters
        ----------
        where : Index
            An Index consisting of an array of timestamps.
        mask : array-like
            Array of booleans denoting where values in the original
            data are not NA.

        Returns
        -------
        numpy.ndarray
            An array of locations (indices) of the labels from the Index
            which correspond to the return values of the `asof` function
            for every element in `where`.
        r�)r�rr{r�)r��searchsortedrfr�r�rir�Zargmax)rnr�r Zlocsrqr{rsrsrt�	asof_locsszIndex.asof_locscCsBt||�}|j�}|s$|ddd�}|j|�}|r:||fS|SdS)a�
        Return a sorted copy of the index.

        Return a sorted copy of the index, and optionally return the indices
        that sorted the index itself.

        Parameters
        ----------
        return_indexer : bool, default False
            Should the indices that would sort the index be returned.
        ascending : bool, default True
            Should the index values be sorted in an ascending order.
        key : callable, optional
            If not None, apply the key function to the index values
            before sorting. This is similar to the `key` argument in the
            builtin :meth:`sorted` function, with the notable difference that
            this `key` function should be *vectorized*. It should expect an
            ``Index`` and return an ``Index`` of the same shape.

            .. versionadded:: 1.1.0

        Returns
        -------
        sorted_index : pandas.Index
            Sorted copy of the index.
        indexer : numpy.ndarray, optional
            The indices that the index itself was sorted by.

        See Also
        --------
        Series.sort_values : Sort values of a Series.
        DataFrame.sort_values : Sort values in a DataFrame.

        Examples
        --------
        >>> idx = pd.Index([10, 100, 1, 1000])
        >>> idx
        Int64Index([10, 100, 1, 1000], dtype='int64')

        Sort values in ascending order (default behavior).

        >>> idx.sort_values()
        Int64Index([1, 10, 100, 1000], dtype='int64')

        Sort values in descending order, and also get the indices `idx` was
        sorted by.

        >>> idx.sort_values(ascending=False, return_indexer=True)
        (Int64Index([1000, 100, 10, 1], dtype='int64'), array([3, 1, 0, 2]))
        Nr{r�)rR�argsortr�)rnr>r?r�r6Z_asZsorted_indexrsrsrtr@2s5

zIndex.sort_valuescOstd��dS)z*
        Use sort_values instead.
        z=cannot sort an Index object in-place, use sort_values insteadN)r�)rn�argsr�rsrsrtr�tsz
Index.sortcCstdt|�j����dS)a�
        Shift index by desired number of time frequency increments.

        This method is for shifting the values of datetime-like indexes
        by a specified time increment a given number of times.

        Parameters
        ----------
        periods : int, default 1
            Number of periods (or increments) to shift by,
            can be positive or negative.
        freq : pandas.DateOffset, pandas.Timedelta or str, optional
            Frequency increment to shift by.
            If None, the index is shifted by its own `freq` attribute.
            Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

        Returns
        -------
        pandas.Index
            Shifted index.

        See Also
        --------
        Series.shift : Shift values of Series.

        Notes
        -----
        This method is only implemented for datetime-like index classes,
        i.e., DatetimeIndex, PeriodIndex and TimedeltaIndex.

        Examples
        --------
        Put the first 5 month starts of 2011 into an index.

        >>> month_starts = pd.date_range('1/1/2011', periods=5, freq='MS')
        >>> month_starts
        DatetimeIndex(['2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01',
                       '2011-05-01'],
                      dtype='datetime64[ns]', freq='MS')

        Shift the index by 10 days.

        >>> month_starts.shift(10, freq='D')
        DatetimeIndex(['2011-01-11', '2011-02-11', '2011-03-11', '2011-04-11',
                       '2011-05-11'],
                      dtype='datetime64[ns]', freq=None)

        The default value of `freq` is the `freq` attribute of the index,
        which is 'MS' (month start) in this example.

        >>> month_starts.shift(10)
        DatetimeIndex(['2011-11-01', '2011-12-01', '2012-01-01', '2012-02-01',
                       '2012-03-01'],
                      dtype='datetime64[ns]', freq='MS')
        zNot supported for type N)r~rkrw)rnZperiods�freqrsrsrt�shiftzs8zIndex.shiftcOs$|j}|dkrtj|�}|j||�S)aE
        Return the integer indices that would sort the index.

        Parameters
        ----------
        *args
            Passed to `numpy.ndarray.argsort`.
        **kwargs
            Passed to `numpy.ndarray.argsort`.

        Returns
        -------
        numpy.ndarray
            Integer indices that would sort the index if used as
            an indexer.

        See Also
        --------
        numpy.argsort : Similar method for NumPy arrays.
        Index.sort_values : Return sorted copy of Index.

        Examples
        --------
        >>> idx = pd.Index(['b', 'a', 'd', 'c'])
        >>> idx
        Index(['b', 'a', 'd', 'c'], dtype='object')

        >>> order = idx.argsort()
        >>> order
        array([1, 0, 3, 2])

        >>> idx[order]
        Index(['a', 'b', 'c', 'd'], dtype='object')
        N)r�rfrr")rnr#r�rqrsrsrtr"�s#
z
Index.argsortrY)�seriescCshtjdtdd�|j|�y|j|�}Wn0tk
rX|j�sD�nt|�rR|}n�YnX|j|||�S)z�
        Fast lookup of value from 1-dimensional ndarray.

        Only use this if you know what you're doing.

        Returns
        -------
        scalar or Series
        zXget_value is deprecated and will be removed in a future version. Use Series[key] insteadr`)ra)	rbrcrd�_check_indexing_errorr�r;�_should_fallback_to_positionalr.�_get_values_for_loc)rnr&r�r�rsrsrt�	get_value�s

zIndex.get_valuecCst|�st|��dS)N)r5r)rnr�rsrsrtr'szIndex._check_indexing_errorcCs|j�s|j�rdSdS)zA
        Should an integer key be treated as positional?
        FT)rgrV)rnrsrsrtr(
sz$Index._should_fallback_to_positionalcCst|�r|j|S|j|S)z�
        Do a positional lookup on the given Series, returning either a scalar
        or a Series.

        Assumes that `series.index is self`

        key is included for MultiIndex compat.
        )r.rlr�)rnr&r�r�rsrsrtr)s	
zIndex._get_values_for_loccCs4tjdtdd�|jj|�}t|j|�|||<dS)z�
        Fast lookup of value from 1-dimensional ndarray.

        .. deprecated:: 1.0

        Notes
        -----
        Only use this if you know what you're doing.
        zNThe 'set_value' method is deprecated, and will be removed in a future version.r`)raN)rbrcrdr�r�r!rb)rn�arrr�r.r�rsrsrtr� s
zIndex.set_valuea�
        Compute indexer and mask for new index given the current index. The
        indexer should be then used as an input to ndarray.take to align the
        current data to the new index.

        Parameters
        ----------
        target : %(target_klass)s

        Returns
        -------
        indexer : ndarray of int
            Integers from 0 to n - 1 indicating that the index at these
            positions matches the corresponding target values. Missing values
            in the target are marked by -1.
        missing : ndarray of int
            An indexer into the target of the values not found.
            These correspond to the -1 in the indexer array.
        r�cCs�t|�}|j|�\}}||k	s&||k	r0|j|�S|j|j�sZdtj|jtjd�}||fSt	|j�rptj
|�}n|j�}|jj|�\}}t
|�|fS)Nr{)rbr�)r�r�r��_is_comparable_dtyperbrfZonesr�rr'rmr�r�r$)rnr�r�r�Z
no_matchesZ
tgt_valuesr�r�rsrsrtr�Ls

zIndex.get_indexer_non_uniquecKs*|jr|j|f|�S|j|f|�\}}|S)z�
        Guaranteed return of an indexer even when non-unique.

        This dispatches to get_indexer or get_indexer_non_unique
        as appropriate.

        Returns
        -------
        numpy.ndarray
            List of indices.
        )rQr�r�)rnr�r�r�r�rsrsrt�get_indexer_for_szIndex.get_indexer_for)rocCs�|jdkr@t|t�r@yt|�|�|fStk
r<||fSXnL|jdkrdt|t�rdt|�|�|fS|jdkr�t|j�s�|jd�|jd�fSt|j�r�t|j�r�|j	|�\}}||fS)z�
        When dealing with an object-dtype Index and a non-object Index, see
        if we can upcast the object-dtype one to improve performance.
        �date�	timedeltarUr�)
rrer=rkrrCr3rbr�r�)rnrorsrsrtr�ps

zIndex._maybe_promote)rbr�cCsdS)zF
        Can we compare values of the given dtype to our own?
        Trs)rnrbrsrsrtr,�szIndex._is_comparable_dtypecs>t|t�r|j}t|�}|j�}�fdd�|j�D�}t|�S)a

        Group the index labels by a given array of values.

        Parameters
        ----------
        values : array
            Values used to determine the groups.

        Returns
        -------
        dict
            {group name -> group labels}
        csi|]\}}�j|�|�qSrs)r�)r�r�r�)rnrsrtr��sz!Index.groupby.<locals>.<dictcomp>)rer>rlrHZ_reverse_indexer�itemsrT)rnr�rqrs)rnrt�groupby�s
z
Index.groupbycs�ddlm}t�j||d�}|j�}|jr�t|dt�r�t||�rJ|j}n(|j	d�rn|j	d�gt
|d�}nd}|j||d�Sd|d<|js�|j|d	<t
|f|�S)
al
        Map values using input correspondence (a dict, Series, or function).

        Parameters
        ----------
        mapper : function, dict, or Series
            Mapping correspondence.
        na_action : {None, 'ignore'}
            If 'ignore', propagate NA values, without passing them to the
            mapping correspondence.

        Returns
        -------
        applied : Union[Index, MultiIndex], inferred
            The output of the mapping function applied to the index.
            If the function returns a tuple with more than one element
            a MultiIndex will be returned.
        r)r�)�	na_actionryN)r�Frrb)r�r�ryZ_map_valuesr�r�rer~r�r�rir�rbrZ)rnrLr2r�Z
new_values�
attributesr�)rzrsrtr�s


z	Index.mapcstt|t�rN�dk	r(��fdd�|D�}n�fdd�|D�}t|�j||jd�S�fdd�|D�}t||jdd�SdS)	z�
        Apply function to all values found in index.

        This includes transforming multiindex entries separately.
        Only apply function to one level of the MultiIndex if level is specified.
        Ncs(g|] }t��fdd�t|�D���qS)c3s&|]\}}|�kr�|�n|VqdS)Nrs)r�rJr�)�funcr1rsrtr��sz4Index._transform_index.<locals>.<listcomp>.<genexpr>)r~�	enumerate)r�r)r4r1rsrtr��sz*Index._transform_index.<locals>.<listcomp>cs"g|]}t�fdd�|D���qS)c3s|]}�|�VqdS)Nrs)r�r�)r4rsrtr��sz4Index._transform_index.<locals>.<listcomp>.<genexpr>)r~)r�r)r4rsrtr��s)r�csg|]}�|��qSrsrs)r�r)r4rsrtr��sF)ryr�)rer>rkr�r�rZry)rnr4r1r0rs)r4r1rt�_transform_index�s

zIndex._transform_indexcCs|dk	r|j|�tj||�S)a 

        Return a boolean array where the index values are in `values`.

        Compute boolean array of whether each index value is found in the
        passed set of values. The length of the returned boolean array matches
        the length of the index.

        Parameters
        ----------
        values : set or list-like
            Sought values.
        level : str or int, optional
            Name or position of the index level to use (if the index is a
            `MultiIndex`).

        Returns
        -------
        is_contained : ndarray
            NumPy array of boolean values.

        See Also
        --------
        Series.isin : Same for Series.
        DataFrame.isin : Same method for DataFrames.

        Notes
        -----
        In the case of `MultiIndex` you must either specify `values` as a
        list-like object containing tuples that are the same length as the
        number of levels, or specify `level`. Otherwise it will raise a
        ``ValueError``.

        If `level` is specified:

        - if it is the name of one *and only one* index level, use that level;
        - otherwise it should be a number indicating level position.

        Examples
        --------
        >>> idx = pd.Index([1,2,3])
        >>> idx
        Int64Index([1, 2, 3], dtype='int64')

        Check whether each index value in a list of values.

        >>> idx.isin([1, 4])
        array([ True, False, False])

        >>> midx = pd.MultiIndex.from_arrays([[1,2,3],
        ...                                  ['red', 'blue', 'green']],
        ...                                  names=('number', 'color'))
        >>> midx
        MultiIndex([(1,   'red'),
                    (2,  'blue'),
                    (3, 'green')],
                   names=['number', 'color'])

        Check whether the strings in the 'color' level of the MultiIndex
        are in a list of colors.

        >>> midx.isin(['red', 'orange', 'yellow'], level='color')
        array([ True, False, False])

        To check across the levels of a MultiIndex, pass a list of tuples:

        >>> midx.isin([(1, 'red'), (3, 'red')])
        array([ True, False, False])

        For a DatetimeIndex, string values in `values` are converted to
        Timestamps.

        >>> dates = ['2000-03-11', '2000-03-12', '2000-03-13']
        >>> dti = pd.to_datetime(dates)
        >>> dti
        DatetimeIndex(['2000-03-11', '2000-03-12', '2000-03-13'],
        dtype='datetime64[ns]', freq=None)

        >>> dti.isin(['2000-03-11'])
        array([ True, False, False])
        N)r<r
�isin)rnr�r1rsrsrtr7�sQ
z
Index.isin)r��use_lhs�use_rhscCst�dS)N)r~)rnr�r8r9rsrsrt�_get_string_slice<szIndex._get_string_slicecCsB|j||||d�\}}t|�s&td��t|�s6td��t|||�S)a$
        Compute the slice indexer for input labels and step.

        Index needs to be ordered and unique.

        Parameters
        ----------
        start : label, default None
            If None, defaults to the beginning.
        end : label, default None
            If None, defaults to the end.
        step : int, default None
        kind : str, default None

        Returns
        -------
        indexer : slice

        Raises
        ------
        KeyError : If key does not exist, or key is not unique and index is
            not ordered.

        Notes
        -----
        This function assumes that the data is sorted, so use at your own peril

        Examples
        --------
        This is a method on all index types. For example you can do:

        >>> idx = pd.Index(list('abcd'))
        >>> idx.slice_indexer(start='b', end='c')
        slice(1, 3, None)

        >>> idx = pd.MultiIndex.from_arrays([list('abcd'), list('efgh')])
        >>> idx.slice_indexer(start='b', end=('c', 'g'))
        slice(1, 3, None)
        )r�r�zStart slice bound is non-scalarzEnd slice bound is non-scalar)�
slice_locsr5r�r�)rnr��endr�r��start_slice�	end_slicersrsrtr�As(zIndex.slice_indexercCs|j�stj|�S|S)zx
        If we have a float key and are not a floating index, then try to cast
        to an int if equivalent.
        )r[r�r)rnr�rsrsrtr�ss
zIndex._maybe_cast_indexer)r�r�cCs0|dkst�|dkrnt|�r n|j||�dS)zz
        If we are positional indexer, validate that we have appropriate
        typed bounds must be an integer.
        r�r�N)r�r�)r�r.r�)rnr�r�r�rsrsrtr�|szIndex._validate_indexer)r�cCs:|dkst�t|�r"|jd|�nt|�r6|jd|�|S)a�
        This function should be overloaded in subclasses that allow non-trivial
        casting on label-slice bounds, e.g. datetime-like indices allowing
        strings containing formatted datetimes.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'loc', 'getitem'} or None

        Returns
        -------
        label : object

        Notes
        -----
        Value of `side` parameter should be validated in caller.
        r�r�Nr�)r�r�N)r�r+r�r.)rnrr�r�rsrsrt�_maybe_cast_slice_bound�szIndex._maybe_cast_slice_boundcCsV|jr|j||d�S|jrJ|ddd�j||dkr6dndd�}t|�|Std��dS)N)r�r{rpr�z0index must be monotonic increasing or decreasingr�)rNr rPrirj)rnrr��posrsrsrtr��szIndex._searchsorted_monotonic)r�r�cCs4|d
kst�|dkr"td|����|}|j|||�}y|j|�}WnHtk
r�}z,y|j||�Stk
rx|�YnXWYdd}~XnXt|tj��r�t	|�r�t
j|jd��}nt
j
|jtjdd	�t|��}t|tj��r�td
|�dt|�����t|t��r|dk�r|jS|jSn|dk�r,|dS|SdS)a�
        Calculate slice bound that corresponds to given label.

        Returns leftmost (one-past-the-rightmost if ``side=='right'``) position
        of given label.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'loc', 'getitem'} or None

        Returns
        -------
        int
            Index of label.
        r�r�Nrpr�z@Invalid value for side kwarg, must be either 'left' or 'right': �u1F)rzCannot get z# slice bound for non-unique label: r{)r�r�N)rpr�)r�rjr?r�r;r�rerfrgr&rZmaybe_booleans_to_slicer�Zmaybe_indices_to_slicer�rrir�r�r�r�)rnrr�r�Zoriginal_labelZslcr�rsrsrt�get_slice_bound�s8

zIndex.get_slice_boundc
Cs|dkp|dk}|s||}}t|ttf�r~t|ttf�r~yt|�}t|�}Wnttfk
rfYnXt|j|j�s~td��d}|dk	r�|j|d|�}|dkr�d}d}	|dk	r�|j|d|�}	|	dkr�t	|�}	|�s|d|	d}	}|	dk�r�|	t	|�8}	|dk�r|t	|�8}||	fS)	a�
        Compute slice locations for input labels.

        Parameters
        ----------
        start : label, default None
            If None, defaults to the beginning.
        end : label, default None
            If None, defaults to the end.
        step : int, defaults None
            If None, defaults to 1.
        kind : {'loc', 'getitem'} or None

        Returns
        -------
        start, end : int

        See Also
        --------
        Index.get_loc : Get location for a single label.

        Notes
        -----
        This method only works if the index is monotonic or unique.

        Examples
        --------
        >>> idx = pd.Index(list('abcd'))
        >>> idx.slice_locs(start='b', end='c')
        (1, 3)
        Nrz(Both dates must have the same UTC offsetrpr�r{r�r�)
rer�rrrjr�r�tzinforBri)
rnr�r<r�r��incZts_startZts_endr=r>rsrsrtr;s8 


zIndex.slice_locscCs|jtj|j|��S)a�
        Make new Index with passed location(-s) deleted.

        Parameters
        ----------
        loc : int or list of int
            Location of item(-s) which will be deleted.
            Use a list of locations to delete more than one value at the same time.

        Returns
        -------
        Index
            New Index with passed location(-s) deleted.

        See Also
        --------
        numpy.delete : Delete any rows and column from NumPy array (ndarray).

        Examples
        --------
        >>> idx = pd.Index(['a', 'b', 'c'])
        >>> idx.delete(1)
        Index(['a', 'c'], dtype='object')

        >>> idx = pd.Index(['a', 'b', 'c'])
        >>> idx.delete([0, 2])
        Index(['b'], dtype='object')
        )r�rf�deleter�)rnr�rsrsrtrEYszIndex.delete)r�cCsDtj|�}|j|�j}tj|d|�|||d�f�}t||jd�S)a

        Make new Index inserting new item at location.

        Follows Python list.append semantics for negative values.

        Parameters
        ----------
        loc : int
        item : object

        Returns
        -------
        new_index : Index
        N)ry)rfrmr	rlZconcatenaterZry)rnr�r�r+r6rsrsrt�insertxs
 zIndex.insert�raise)�errorscCsh|jdkrdnd}tj||d�}|j|�}|dk}|j�r^|dkrTt||�d���||}|j|�S)a�
        Make new Index with passed list of labels deleted.

        Parameters
        ----------
        labels : array-like
        errors : {'ignore', 'raise'}, default 'raise'
            If 'ignore', suppress error and existing labels are dropped.

        Returns
        -------
        dropped : Index

        Raises
        ------
        KeyError
            If not all of the labels are found in the selected axis
        r�N)rbr{rcz not found in axisr�)rbr�Zindex_labels_to_arrayr�r�r;rE)rnr�rHZ	arr_dtyper�r rsrsrt�drop�s

z
Index.dropcCsXttj|�|_ttj|�|_ttj|�|_ttj|�|_	ttj
|�|_ttj|�|_
dS)z,
        Add in comparison methods.
        N)rzr��eq�__eq__�ne�__ne__r��__lt__�gt�__gt__r��__le__�ge�__ge__)rxrsrsrt�_add_comparison_methods�szIndex._add_comparison_methodscCs@td�|_td�|_td�|_td�|_td�|_td�|_dS)z@
        Add in the numeric add/sub methods to disable.
        r�r�r�r�r��__isub__N)rQr�r�r�r�r�rU)rxrsrsrt�%_add_numeric_methods_add_sub_disabled�s




z+Index._add_numeric_methods_add_sub_disabledcCs�td�|_td�|_td�|_td�|_td�|_td�|_td�|_td�|_td	�|_	td
�|_
td�|_td�|_td
�|_
td�|_dS)zG
        Add in numeric methods to disable other than add/sub.
        �__pow__�__rpow__�__mul__�__rmul__�__floordiv__�
__rfloordiv__�__truediv__�__rtruediv__�__mod__�
__divmod__�__neg__�__pos__�__abs__�__inv__N)rQrWrXrYrZr[r\r]r^r_r`rarbrcrd)rxrsrsrt�_add_numeric_methods_disabled�s












z#Index._add_numeric_methods_disabledcCs�ttj|�|_ttj|�|_ttj|�|_ttj	|�|_
ttj|�|_ttj
|�|_ttj|�|_ttj|�|_ttj|�|_ttj|�|_ttj|�|_tt|�|_ttj|�|_ttj|�|_dS)z)
        Add in numeric methods.
        N)r�r��addr�rFZraddr��subr�Zrsubr�ZrpowrX�powrW�truedivr]Zrtruedivr^�modr_�floordivr[Z	rfloordivr\�divmodr`�mulrYZrmulrZ)rxrsrsrt�_add_numeric_methods_binary�sz!Index._add_numeric_methods_binarycCsLtd�dd�}|tjd�|_|tjd�|_|tjd�|_|dd�d	�|_	d
S)z/
        Add in numeric unary methods.
        )�opstrcs�fdd�}||_|S)Ncs|j�}t�|j�f|�S)N)r�rZr�)rnr�)rrrsrt�_evaluate_numeric_unary�sz_Index._add_numeric_methods_unary.<locals>._make_evaluate_unary.<locals>._evaluate_numeric_unary)rw)rrrorprs)rrrt�_make_evaluate_unary�sz>Index._add_numeric_methods_unary.<locals>._make_evaluate_unaryrarbrccSs|S)Nrs)rrsrsrtr�sz2Index._add_numeric_methods_unary.<locals>.<lambda>rdN)
�str_tr��negrar@rbrfr�rcrd)rxrqrsrsrt�_add_numeric_methods_unary�s
	z Index._add_numeric_methods_unarycCs|j�|j�dS)N)rtrn)rxrsrsrt�_add_numeric_methodsszIndex._add_numeric_methodscsTd�td�td<td�td<ttd��fdd�}|d	d
tj�|_|ddtj�|_d
S)z)
        Add in logical methods.
        a~
        %(desc)s

        Parameters
        ----------
        *args
            These parameters will be passed to numpy.%(outname)s.
        **kwargs
            These parameters will be passed to numpy.%(outname)s.

        Returns
        -------
        %(outname)s : bool or array_like (if axis is specified)
            A single element array_like may be converted to bool.a�

        See Also
        --------
        Index.any : Return whether any element in an Index is True.
        Series.any : Return whether any element in a Series is True.
        Series.all : Return whether all elements in a Series are True.

        Notes
        -----
        Not a Number (NaN), positive infinity and negative infinity
        evaluate to True because these are not equal to zero.

        Examples
        --------
        **all**

        True, because nonzero integers are considered True.

        >>> pd.Index([1, 2, 3]).all()
        True

        False, because ``0`` is considered False.

        >>> pd.Index([0, 1, 2]).all()
        False

        **any**

        True, because ``1`` is considered True.

        >>> pd.Index([0, 0, 1]).any()
        True

        False, because ``0`` is considered False.

        >>> pd.Index([0, 0, 0]).any()
        False
        Z	index_alla�

        See Also
        --------
        Index.all : Return whether all elements are True.
        Series.all : Return whether all elements are True.

        Notes
        -----
        Not a Number (NaN), positive infinity and negative infinity
        evaluate to True because these are not equal to zero.

        Examples
        --------
        >>> index = pd.Index([0, 1, 2])
        >>> index.any()
        True

        >>> index = pd.Index([0, 0, 0])
        >>> index.any()
        False
        Z	index_any)ry�desccs:t||d�ttd|�t���fdd����}||_|S)N)�outnamervZindex_cs>�|j�}t|tjttf�r6|jdkr6|jj|j	��S|SdS)Nr)
r�rerfrgrBrZrhrbrkr�)rnr#r�rq)�frsrt�logical_funcbs


zPIndex._add_logical_methods.<locals>._make_logical_function.<locals>.logical_func)rr�_index_shared_docsrw)ryrvrxry)�_doc)rxrt�_make_logical_functionas

z:Index._add_logical_methods.<locals>._make_logical_functionrdz%Return whether all elements are True.r�z#Return whether any element is True.N)rrzrrrfrdr�)rxr|rs)r{rt�_add_logical_methods
s'

zIndex._add_logical_methodscCstd�|_td�|_dS)z4
        Add in logical methods to disable.
        rdr�N)rQrdr�)rxrsrsrt�_add_logical_methods_disabledzs
z#Index._add_logical_methods_disabledcCs|jjS)zE
        Return a tuple of the shape of the underlying data.
        )rlr�)rnrsrsrtr��szIndex.shape)NNFNT)N)N)N)r�)N)T)rTN)N)NFNN)N)N)FNr)r)N)r]N)N)NN)TN)NNF)N)NF)F)NTN)r)N)NN)r�)N)r{)r{)F)N)F)N)NN)NN)NNN)NN)N)NNNN)rpNFF)T)rpF)rpFT)rpF)F)N)FTN)r{N)N)N)N)TT)NNNN)rp)NNNN)rG)�rw�
__module__�__qualname__�__doc__rMZ
_deprecationsrL�	frozensetrr�r�r�r�r�r�r�rrIrfrgr�r�r�rr,r�rr�rr�Z_defer_to_indexing�libindexZObjectEnginer�Z!_supports_partial_string_indexingZ
_accessorsrGrSr��propertyr��classmethodr�rr�r�rr�r�r�r�r�r9r�r�r�rbr�r�r�rzr�_index_doc_kwargsr�rGr�r�rr�r�rrrrrr�r�r
rrr
rrr"r!r'r(r)r+ry�setterr�r0r2r�r�r7r5r8r<r=rArBZget_level_valuesrKrMrOrNrPrRrSrQrTrVr.r[r\r#r]r_rergrrjrlr�rorrrsrEZisnullrtZnotnullrvrxr`r}rarr�r�r�r�r�r�r�r�r��__bool__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�rrrlr�rr�r�rr	r
rrurr
rrrrrrrrrrFr�rrr!r@r�r%r"r*r'r(r)r�r�r-r�rr,rTr	r1rr6r7r:r�r�r�r?r�rBr;rErFrIrTrVrernrtrur}r~r��
__classcell__rsrs)rzrtrZ�s�
+ 

J:&

?@N6'>##++(+!%	
	7, 08$;DP>Mh2
	F<@zN
0 6	)%
	OA'A:*&*+U2	$DY pcCsJddlm}t|�dkr8|dk	r(|d}t|d|d�S|j||d�SdS)a�
    Construct an index from sequences of data.

    A single sequence returns an Index. Many sequences returns a
    MultiIndex.

    Parameters
    ----------
    sequences : sequence of sequences
    names : sequence of str

    Returns
    -------
    index : Index or MultiIndex

    Examples
    --------
    >>> ensure_index_from_sequences([[1, 2, 3]], names=["name"])
    Int64Index([1, 2, 3], dtype='int64', name='name')

    >>> ensure_index_from_sequences([["a", "a"], ["a", "b"]], names=["L1", "L2"])
    MultiIndex([('a', 'a'),
                ('a', 'b')],
               names=['L1', 'L2'])

    See Also
    --------
    ensure_index
    r)r�r{N)ry)r�)r�r�rirZ�from_arrays)�	sequencesr�r�rsrsrt�ensure_index_from_sequences�sr�FcCs�t|t�r|r|j�}|St|d�r4t||j|d�St|�rDt|�}t|t�r�t|�tkrbt|�}tj	|�\}}t
|�dkr�|r�ddlm}|j
|�S|}n|r�t|�}t|�S)ak
    Ensure that we have an index from some index-like object.

    Parameters
    ----------
    index_like : sequence
        An Index or other sequence
    copy : bool, default False

    Returns
    -------
    index : Index or MultiIndex

    See Also
    --------
    ensure_index_from_sequences

    Examples
    --------
    >>> ensure_index(['a', 'b'])
    Index(['a', 'b'], dtype='object')

    >>> ensure_index([('a', 'a'),  ('b', 'c')])
    Index([('a', 'a'), ('b', 'c')], dtype='object')

    >>> ensure_index([['a', 'a'], ['b', 'c']])
    MultiIndex([('a', 'b'),
            ('a', 'c')],
           )
    ry)ryrr)r�)rerZrr�ryr1r�rkrZclean_index_listrir�r�r��	copy_func)Z
index_likerZ	convertedZ
all_arraysr�rsrsrtr��s&



r�cCs.yt|�Wntk
r$t|�SX|SdS)z<
    If seq is an iterator, put its values into a list.
    N)rir�r�)�seqrsrsrtr��s

r�)�stringsr�cCs:|}x0t|�dkr4tdd�|D��r4dd�|D�}qW|S)z)
    Trims zeros and decimal points.
    rcss|]}|ddkVqdS)rrNrs)r�rrsrsrtr�sztrim_front.<locals>.<genexpr>cSsg|]}|dd��qS)r{Nrs)r�rrsrsrtr�sztrim_front.<locals>.<listcomp>)rird)r�Ztrimmedrsrsrtrs r)r�cCs|dkrtd|����dS)Nrpr�r�r�zdo not recognize join method )rpr�r�r�)rj)r�rsrsrtr�sr�cCsddlm}|d|dd�S)Nr)r�)ry)r�r�)�nr�rsrsrt�
default_indexsr�)r�cCs8|dkrt|ttf�r|j}t|�s4t|j�d���|S)zR
    If no name is passed, then extract it from data, validating hashability.
    Nz.name must be a hashable type)rerZrBryr-r�rw)ryrrxrsrsrtr�s
r�)r�rbrr�cCs�t|�r�tj|dd�}|dkr.t|||d�}q�|d
kr�t|�j�rJtd��|dkr\t||�}yt|||�}Wq�tk
r�tj	|tj
|d�}Yq�Xq�|d	kr�q�|j|�}n<t|�r�tj|dd�}|d	kr�q�|j|�}ntj	|||d�}|S)z�
    If a dtype is passed, cast to the closest matching dtype that is supported
    by Index.

    Parameters
    ----------
    data : np.ndarray
    dtype : np.dtype
    copy : bool

    Returns
    -------
    np.ndarray
    F)rhrW)rrX�mixed-integer-floatz#cannot convert float NaN to integer)rbrr)rXr�)
r/rrir rEr�rj�_try_convert_to_int_arrayrfr�float64r�r,)r�rbr�inferredrsrsrtr�+s.
r�cCsfddlm}m}m}m}tj|dd�}|dkrbyt|dd�}||jfSt	k
rXYnX|t
fS|dkrt|tjfS|d
kr�y|j
|dd�}||jfSt	k
r�YnXn�|dkr�n�|d
k�r\|jd��ry|j
|dd�}||jfSt	tfk
�r�YnXnZ|jd��r&|j
|dd�}||jfS|dk�r\y|j
|�}||jfStk
�rZYnX||jfS)a
    If we have an arraylike input but no passed dtype, try to infer
    a supported dtype.

    Parameters
    ----------
    subarr : np.ndarray, Index, or Series

    Returns
    -------
    converted : np.ndarray or ExtensionArray
    dtype : np.dtype or ExtensionDtype
    r)�
DatetimeArray�
IntervalArray�PeriodArray�TimedeltaArrayF)rhrWNrX�mixed-integer-float�
integer-nar^)rrUrrr/Zperiod)rXr�r�)�pandas.core.arraysr�r�r�r�rrir�rbrjr�rfr�r��
startswithrr)r�r�r�r�r�r�r�rsrsrtr�asH








r�)r�rrbr�cCs�t|�sFy"|jddd�}||kj�r(|SWntttfk
rDYnXy"|jddd�}||kj�rf|SWntttfk
r�YnXt�dS)a�
    Attempt to convert an array of data into an integer array.

    Parameters
    ----------
    data : The data to convert.
    copy : bool
        Whether to copy the data or not.
    dtype : np.dtype

    Returns
    -------
    int_array : data converted to either an ndarray[int64] or ndarray[uint64]

    Raises
    ------
    ValueError if the conversion was not successful.
    �i8F)r�u8N)r8r�rdrr�rj)r�rrbrrsrsrtr��sr�)rrycKsBtt|�r*||fd|d�|��}|jt�S||f|||d�|��S)a�
    If an object dtype was specified, create the non-object Index
    and then convert it to object.

    Parameters
    ----------
    dtype : np.dtype, ExtensionDtype, str
    klass : Index subclass
    data : list-like
    copy : bool
    name : hashable
    **kwargs

    Returns
    -------
    Index

    Notes
    -----
    We assume that calling .astype(object) on this klass will make a copy.
    F)rry)rbrry)r)�_o_dtyper�r�)rbr^r�rryr�rrsrsrtr��s

r�)r[r\)N)F)�rr�rr��textwraprZtypingrrrrr	r
rrrbZnumpyrfZpandas._libsr
r�rr�rZpandas._libs.joinZ_libsrr�Zpandas._libs.librrZpandas._libs.tslibsrrZpandas._libs.tslibs.periodrZpandas._libs.tslibs.timezonesrZpandas._typingrrZ
pandas.compatrZpandas.compat.numpyrr�Z
pandas.errorsrZpandas.util._decoratorsrrrrZpandas.core.dtypesrrZpandas.core.dtypes.castr r!Zpandas.core.dtypes.commonr"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9Zpandas.core.dtypes.concatr:Zpandas.core.dtypes.genericr;r<r=r>r?r@rArBrCZpandas.core.dtypes.missingrDrEZpandas.corerFZpandas.core.accessorrGZpandas.core.algorithms�coreZ
algorithmsr�rHrIZpandas.core.arrays.datetimesrJrKZpandas.core.baserLrMZpandas.core.common�commonr�Zpandas.core.indexersrNZpandas.core.indexes.frozenrOZpandas.core.missingr�Zpandas.core.opsrPZpandas.core.ops.invalidrQZpandas.core.sortingrRZpandas.core.stringsrSZpandas.io.formats.printingrTrUrVrWrXr}rY�__all__r�Z_unsortable_typesr�r�rzr�rrrzr�rbr�r�r�r�rZrer}rTr�r�r�r�rr�r�r�rgr�r�r�r�rsrsrsrt�<module>s�(
h,#
t
(@
6H
)