U
    f/e/                     @  s  d dl mZ d dlmZmZ d dlZd dlZd dlm	Z
mZ d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZ d d	l m!Z! d d
l"m#Z#m$Z$ i Z%de%d< G dd de#Z&G dd de&Z'G dd de'Z(G dd de'Z)G dd de&Z*dS )    )annotations)CallableHashableN)indexlib)DtypeDtypeObj)cache_readonlydoc)astype_nansafe)is_dtype_equalis_extension_array_dtypeis_floatis_float_dtypeis_integer_dtypeis_numeric_dtype	is_scalaris_signed_integer_dtypeis_unsigned_integer_dtypeneeds_i8_conversionpandas_dtype)	ABCSeries)Indexmaybe_extract_namea  
    Immutable sequence used for indexing and alignment. The basic object
    storing axis labels for all pandas objects. %(klass)s is a special case
    of `Index` with purely %(ltype)s labels. %(extra)s.

    Parameters
    ----------
    data : array-like (1-dimensional)
    dtype : NumPy dtype (default: %(dtype)s)
    copy : bool
        Make a copy of input ndarray.
    name : object
        Name to be stored in the index.

    Attributes
    ----------
    None

    Methods
    -------
    None

    See Also
    --------
    Index : The base pandas Index type.

    Notes
    -----
    An Index instance can **only** contain hashable objects.
class_descrc                      sH  e Zd ZU dZd ddddZded< ded	< d
ed< dZdZeddddZ	e
e
jeje
e
jeje
e
jeje
e
jeje
e
jeje
e
jeje
e
jeje
e
jeje
e
jeje
e
jej i
Z!ded< e"dd Z#eddddZ$dFddddZ%e&dddd Z'e&dd!d"d#d$Z(e&dd%d"d&d'Z)dd fd(d)Z*e+e,j-dG fd*d+	Z-e+e,j.ddd,d-Z.e+e,j/d.dd/ fd0d1Z/e+e,j0e1j2fdd2d3d4Z0e+e,j3e1j2fd5d6 fd7d8Z3 fd9d:Z4d;dd"d<d=Z5e&ddd!d>d?d@Z6e"dddAdBZ7dH fdDdE	Z8  Z9S )INumericIndexzJ
    Provide numeric type operations.

    This is an abstract class.
    zinteger or floatinferred klassltypedtypeextra
np.ndarray_valuesznp.dtype_default_dtypeztuple[Callable[..., bool], str]_dtype_validation_metadataTFboolreturnc                 C  s   t | jrdS dS d S )NTF)r   r!   self r,   ?/tmp/pip-unpacked-wheel-tiezk1ph/pandas/core/indexes/numeric.py_can_hold_naf   s    
zNumericIndex._can_hold_naz*dict[np.dtype, type[libindex.IndexEngine]]_engine_typesc                 C  s   | j | j S N)r/   r!   r*   r,   r,   r-   _engine_typez   s    zNumericIndex._engine_typestrc                 C  s   dddd| j j S )NintegerZfloating)iuf)r!   kindr*   r,   r,   r-   inferred_type~   s    zNumericIndex.inferred_typeNzDtype | Noner!   c                 C  s(   t ||| }| |||}| j||dS )Nname)r   _ensure_array_simple_new)clsdatar!   copyr;   subarrr,   r,   r-   __new__   s    zNumericIndex.__new__r@   c                 C  s   |  | t|tjtfsRt|r,| |t|ttt	fsDt|}tj
||d}t|jjtrj| | | |}|st|j|stj|||d}| || n|}|jdkrtdt
|}|S )zF
        Ensure we have a valid array to pass to _simple_new.
        r9   )r!   r@      z Index data must be 1-dimensional)_validate_dtype
isinstancenpZndarrayr   r   Z_scalar_data_errorr   listtupleZasarray
issubclassr!   typer2   Z_string_data_error_ensure_dtyper   array_assert_safe_castingndim
ValueError)r>   r?   r!   r@   rA   r,   r,   r-   r<      s$    





zNumericIndex._ensure_arrayNone)r!   r)   c                 C  s6   |d krd S | j \}}||s2td| d| d S )Nz#Incorrect `dtype` passed: expected z, received )r&   rP   )r>   r!   Zvalidation_funcexpectedr,   r,   r-   rE      s    
zNumericIndex._validate_dtypeznp.dtype | Nonec                 C  s   | j S )zCEnsure int64 dtype for Int64Index, etc. Assumed dtype is validated.)r%   )r>   r!   r,   r,   r-   rL      s    zNumericIndex._ensure_dtypec              
     sf   t | jst |S t| z&t|r:t||kr:W dS || jkW S  tt	t
fk
r`   Y dS X dS )zU
        Check if key is a float and has a decimal. If it has, return False.
        FN)r   r!   super__contains__hashr   intZ_engineOverflowError	TypeErrorrP   )r+   key	__class__r,   r-   rT      s    
zNumericIndex.__contains__c                   sh   t | jrXt|}t|r,td| dn,t|rXt|sXt| j|d}t	|| j
dS t j||dS )Nz%Cannot convert Float64Index to dtype z,; integer values are required for conversionr9   r:   rC   )r   r!   r   r   rX   r   r   r   r$   
Int64Indexr;   rS   astype)r+   r!   r@   ZarrrZ   r,   r-   r]      s    

zNumericIndex.astypec                 C  s   dS )NFr,   r*   r,   r,   r-   _should_fallback_to_positional   s    z+NumericIndex._should_fallback_to_positionalslice)rY   r7   c                   s>   t | jr.|dkst| j|j|j|j|dS t j||dS )N)locgetitem)r7   )	r   r!   AssertionErrorZslice_indexerstartstopsteprS   _convert_slice_indexer)r+   rY   r7   rZ   r,   r-   rf      s    
z#NumericIndex._convert_slice_indexer)sidec                 C  s.   |ddd t jfkst| |dd | |S )Nr`   ra   r7   _maybe_cast_slice_bound)r   
no_defaultrb   Z_deprecated_argZ_maybe_cast_indexer)r+   labelrg   r7   r,   r,   r-   rh      s    z$NumericIndex._maybe_cast_slice_boundr   r:   c                   sD   | j s4|jjdkr4|tjkr"| jn|}tj||dS t j	||dS )Nr6   r:   )valuesr;   )
r.   r!   r7   r   ri   _nameFloat64Indexr=   rS   _shallow_copy)r+   rk   r;   rZ   r,   r-   rn      s    zNumericIndex._shallow_copyc                   sb   t  ||}t|jtjs^|jdkr@tdt| j	 dntdt| j	 dt
| |S )Nr   ztolerance argument for z1 must contain numeric elements if it is list typez$ must be numeric if it is a scalar: )rS   _convert_tolerancerG   Z
issubdtyper!   numberrO   rP   rK   __name__repr)r+   Z	tolerancetargetrZ   r,   r-   ro     s    
zNumericIndex._convert_tolerancer   c                 C  s   t |S r0   )r   )r+   r!   r,   r,   r-   _is_comparable_dtype  s    z!NumericIndex._is_comparable_dtype)r?   rA   r)   c                 C  s"   t |jrt||stddS )z
        Ensure incoming data can be represented with matching signed-ness.

        Needed if the process of casting data from some accepted dtype to the internal
        dtype(s) bears the risk of truncation (e.g. float to int).
        z.Unsafe NumPy casting, you must explicitly castN)r   r!   rG   Zarray_equalrX   )r>   r?   rA   r,   r,   r-   rN     s    
z!NumericIndex._assert_safe_castingc                 C  s   dS )zB
        Checks that all the labels are datetime objects.
        Fr,   r*   r,   r,   r-   _is_all_dates(  s    zNumericIndex._is_all_dates.c                   sP   ddl m} t| jr4|| j||||dd}| S t jf ||||d|S )Nr   )FloatArrayFormatterF)na_repfloat_formatdecimalquotingZfixed_width)rx   ry   rz   r{   )Zpandas.io.formats.formatrw   r   r!   r$   Zget_result_as_arrayrS   _format_native_types)r+   rx   ry   rz   r{   kwargsrw   	formatterrZ   r,   r-   r|   /  s&    
z!NumericIndex._format_native_types)NNFN)T)r   Nrv   N):rq   
__module____qualname____doc___index_descr_args__annotations__Z_is_numeric_dtypeZ_can_hold_stringsr	   r.   rG   r!   Zint8libindexZ
Int8EngineZint16ZInt16EngineZint32ZInt32Engineint64Int64EngineZuint8ZUInt8EngineZuint16ZUInt16EngineZuint32ZUInt32Engineuint64UInt64EngineZfloat32ZFloat32Enginefloat64Float64Enginer/   propertyr1   r8   rB   classmethodr<   rE   rL   rT   r
   r   r]   r^   rf   rh   r   ri   rn   ro   rt   rN   ru   r|   __classcell__r,   r,   rZ   r-   r   R   s   

 
 
 
 
 
 
 
 
 
 
#

	       r   c                   @  s"   e Zd ZdZeddddZdS )IntegerIndexz@
    This is an abstract class for Int64Index, UInt64Index.
    r#   r(   c                 C  s   t jdtdd | j| jS )Nz@Index.asi8 is deprecated and will be removed in a future version   )
stacklevel)warningswarnFutureWarningr$   viewr%   r*   r,   r,   r-   asi8M  s    zIntegerIndex.asi8N)rq   r   r   r   r   r   r,   r,   r,   r-   r   H  s   r   c                   @  sD   e Zd Zd ddddZed e ZdZejZ	e
e
jZedfZdS )	r\   r3   r   r   r   r   Z
int64indexzsigned integerN)rq   r   r   r   _num_index_shared_docsr   _typr   r   r1   rG   r!   r   r%   r   r&   r,   r,   r,   r-   r\   X  s   r\   c                      sT   e Zd Zd ddddZed e ZdZejZ	e
e
jZedfZ fddZ  ZS )	UInt64Indexzunsigned integerr   r   r   r   Zuint64indexc                   s@   t  | t|dr<t|jr<|dk r8|| jS t|S )Nr!   r   )rS   _validate_fill_valuehasattrr   r!   allr]   rX   )r+   valuerZ   r,   r-   r   u  s    z UInt64Index._validate_fill_value)rq   r   r   r   r   r   r   r   r   r1   rG   r!   r   r%   r   r&   r   r   r,   r,   rZ   r-   r   g  s   r   c                   @  sD   e Zd Zd ddddZed e ZdZejZ	e
e
jZedfZdS )rm   r   floatr   )r   r!   r    r"   r   Zfloat64indexN)rq   r   r   r   r   r   r   r   r   r1   rG   r!   r   r%   r   r&   r,   r,   r,   r-   rm     s   rm   )+
__future__r   typingr   r   r   ZnumpyrG   Zpandas._libsr   r   r   Zpandas._typingr   r   Zpandas.util._decoratorsr	   r
   Zpandas.core.dtypes.castr   Zpandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r   Zpandas.core.dtypes.genericr   Zpandas.core.indexes.baser   r   r   r   r   r\   r   rm   r,   r,   r,   r-   <module>   s*   4" w